from django.test import TestCase
# from django.db.utils import IntegrityError

from core.models import User


class CaseInsensitiveUserNameManagerTest(TestCase):

    @classmethod
    def setUpTestData(cls):
        cls.user1 = User.objects.create_user(username="user1",
                                             password="<PASSWORD>",
                                             email="<EMAIL>")

    def test_get_by_natural_key(self):
        user = User.objects.get_by_natural_key('user1')
        self.assertEqual(user.username, 'user1')
        user = User.objects.get_by_natural_key('uSEr1')
        self.assertEqual(user.username, 'user1')

    def test_create_user_username(self):
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user1",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")
        with self.assertRaises(ValueError):
            User.objects.create_user(username="usER1",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")

    def test_create_user_email(self):
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user2",
                                     password="<PASSWORD>",
                                     email="")
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user2",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")

from django.test import TestCase
# from django.db.utils import IntegrityError

from core.models import User


class CaseInsensitiveUserNameManagerTest(TestCase):

    @classmethod
    def setUpTestData(cls):
        cls.user1 = User.objects.create_user(username="user1",
                                             password="<PASSWORD>",
                                             email="<EMAIL>")

    def test_get_by_natural_key(self):
        user = User.objects.get_by_natural_key('user1')
        self.assertEqual(user.username, 'user1')
        user = User.objects.get_by_natural_key('uSEr1')
        self.assertEqual(user.username, 'user1')

    def test_create_user_username(self):
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user1",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")
        with self.assertRaises(ValueError):
            User.objects.create_user(username="usER1",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")

    def test_create_user_email(self):
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user2",
                                     password="<PASSWORD>",
                                     email="")
        with self.assertRaises(ValueError):
            User.objects.create_user(username="user2",
                                     password="<PASSWORD>",
                                     email="<EMAIL>")

# from django.db.utils import IntegrityError