from django.test import TestCase
from django.contrib.auth import get_user_model


class ModelTests(TestCase):

    def test_create_user_with_email_successful(self):
        """Test creating a new user with an email successful"""

        email="<EMAIL>"
        password="<PASSWORD>"
        user=get_user_model().objects.create_user(
            email=email,
            password=password
        )
        self.assertEquals(user.email,email)
        self.assertTrue(user.check_password(password))

    def test_new_user_email_normalized(self):
        email="<EMAIL>"
        user = get_user_model().objects.create_user(
            email,'test123'
        )
        self.assertEquals(user.email,email.lower())

    def test_new_user_invalid_email(self):
        """ Test Creating user with no email raises error"""
        with self.assertRaises(ValueError):
            user = get_user_model().objects.create_user(
                None, 'test123'
            )

    def test_create_new_superuser(self):
        user=get_user_model().objects.create_superuser('<EMAIL>','test123')
        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)



from django.test import TestCase
from django.contrib.auth import get_user_model


class ModelTests(TestCase):

    def test_create_user_with_email_successful(self):
        """Test creating a new user with an email successful"""

        email="<EMAIL>"
        password="<PASSWORD>"
        user=get_user_model().objects.create_user(
            email=email,
            password=password
        )
        self.assertEquals(user.email,email)
        self.assertTrue(user.check_password(password))

    def test_new_user_email_normalized(self):
        email="<EMAIL>"
        user = get_user_model().objects.create_user(
            email,'test123'
        )
        self.assertEquals(user.email,email.lower())

    def test_new_user_invalid_email(self):
        """ Test Creating user with no email raises error"""
        with self.assertRaises(ValueError):
            user = get_user_model().objects.create_user(
                None, 'test123'
            )

    def test_create_new_superuser(self):
        user=get_user_model().objects.create_superuser('<EMAIL>','test123')
        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)



Test creating a new user with an email successful Test Creating user with no email raises error