<reponame>DocMoeller/recipe-app-api<gh_stars>0
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 user is created with an email succeeded"""
        email = '<EMAIL>'
        pwd = '<PASSWORD>'
        user = get_user_model().objects.create_user(
            email=email,
            password=<PASSWORD>
        )
        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(pwd))

    def test_new_user_email_mormalized(self):
        """Test that emails are all lovwrcase"""
        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 that an emailadr is provided when creating a new user"""
        with self.assertRaises(ValueError):
            get_user_model().objects.create_user(None, 'test123')

    def test_create_new_superuser(self):
        """Test creat new superuser"""
        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 user is created with an email succeeded"""
        email = '<EMAIL>'
        pwd = '<PASSWORD>'
        user = get_user_model().objects.create_user(
            email=email,
            password=<PASSWORD>
        )
        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(pwd))

    def test_new_user_email_mormalized(self):
        """Test that emails are all lovwrcase"""
        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 that an emailadr is provided when creating a new user"""
        with self.assertRaises(ValueError):
            get_user_model().objects.create_user(None, 'test123')

    def test_create_new_superuser(self):
        """Test creat new superuser"""
        user = get_user_model().objects.create_superuser(
            '<EMAIL>',
            'test123'
        )

        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)
Test user is created with an email succeeded Test that emails are all lovwrcase Test that an emailadr is provided when creating a new user Test creat new superuser