<reponame>AdamPetroff/recipe-app-api<filename>app/core/tests/test_models.py
from django.contrib.auth import get_user_model
from django.test import TestCase


class ModelTests(TestCase):
    def test_create_user_with_email_successful(self):
        """Test creating a new user with an email is successful"""
        email = '<EMAIL>'
        password = '<PASSWORD>'
        user = get_user_model()\
            .objects.create_user(email=email, password=password)
        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

    def test_create_user_email_normalized(self):
        """Test email for a new user is normalised"""
        email = "<EMAIL>"
        user = get_user_model()\
            .objects.create_user(email=email, password='<PASSWORD>')
        self.assertEqual(user.email, email.lower())

    def test_user_invalid_email(self):
        """Test new user with invalid email fails"""
        with self.assertRaises(ValueError):
            get_user_model().objects.create_user(None, 'test')

    def test_create_new_superuser(self):
        """Test createing a new superuser"""
        user = get_user_model().objects.\
            create_superuser('<EMAIL>', 'test123')
        self.assertTrue(user.is_superuser)
        self.assertTrue(user.is_staff)

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


class ModelTests(TestCase):
    def test_create_user_with_email_successful(self):
        """Test creating a new user with an email is successful"""
        email = '<EMAIL>'
        password = '<PASSWORD>'
        user = get_user_model()\
            .objects.create_user(email=email, password=password)
        self.assertEqual(user.email, email)
        self.assertTrue(user.check_password(password))

    def test_create_user_email_normalized(self):
        """Test email for a new user is normalised"""
        email = "<EMAIL>"
        user = get_user_model()\
            .objects.create_user(email=email, password='<PASSWORD>')
        self.assertEqual(user.email, email.lower())

    def test_user_invalid_email(self):
        """Test new user with invalid email fails"""
        with self.assertRaises(ValueError):
            get_user_model().objects.create_user(None, 'test')

    def test_create_new_superuser(self):
        """Test createing a new superuser"""
        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 is successful Test email for a new user is normalised Test new user with invalid email fails Test createing a new superuser