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


def sample_user(email='<EMAIL>', password='<PASSWORD>'):
    """Create a sample user"""
    return get_user_model().objects.create_user(email=email, password=password)


class UserModelTests(TestCase):

    def test_create_user_with_email_successful(self):
        """Test for creating a new user with an email is successful"""
        email = '<EMAIL>'
        password = '<PASSWORD>'
        user = sample_user(email, password)

        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

    def test_new_user_email_normalized(self):
        """Test the email for a new user is normalized"""
        email = "<EMAIL>"
        user = sample_user(email, "test12345")

        self.assertEqual(user.email, email.lower())

    def test_new_user_invalid_email(self):
        """Test creating user with no email raise error"""
        with self.assertRaises(ValueError):
            sample_user(None, 'test123')

    def test_create_new_super_user(self):
        """Test creating a new superuser"""
        user = get_user_model().objects.create_superuser(
            email='<EMAIL>',
            password='<PASSWORD>',
        )

        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)

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


def sample_user(email='<EMAIL>', password='<PASSWORD>'):
    """Create a sample user"""
    return get_user_model().objects.create_user(email=email, password=password)


class UserModelTests(TestCase):

    def test_create_user_with_email_successful(self):
        """Test for creating a new user with an email is successful"""
        email = '<EMAIL>'
        password = '<PASSWORD>'
        user = sample_user(email, password)

        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

    def test_new_user_email_normalized(self):
        """Test the email for a new user is normalized"""
        email = "<EMAIL>"
        user = sample_user(email, "test12345")

        self.assertEqual(user.email, email.lower())

    def test_new_user_invalid_email(self):
        """Test creating user with no email raise error"""
        with self.assertRaises(ValueError):
            sample_user(None, 'test123')

    def test_create_new_super_user(self):
        """Test creating a new superuser"""
        user = get_user_model().objects.create_superuser(
            email='<EMAIL>',
            password='<PASSWORD>',
        )

        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)

Create a sample user Test for creating a new user with an email is successful Test the email for a new user is normalized Test creating user with no email raise error Test creating a new superuser