from django.test import TestCase

from django.contrib.auth import get_user_model

class ModelTests(TestCase):

    def test_create_user_with_email_successfull(self):
        """ test creating a new user with an email is successfull"""
        email ='ferid.maghraoui@gmail.com'
        password="testpass100"
        user=get_user_model().objects.create_user(
            email = email,
            password = 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 is normalized"""
        email = 'feridmaghraou@GMAIL.COM'
        user=get_user_model().objects.create_user(email,'test123')

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

    def test_new_user_valid_email(self):
        """test creating user with no  email raises error"""
        with self.assertRaises(ValueError):
            get_user_model().objects.create_user(None,"test123")

    def test_create_new_super_user(self):
        """resting creating super user"""
        user=get_user_model().objects.create_superuser(
            email = 'test@gmail.com',
            password = "testtest"
            )
        self.assertTrue(user.is_superuser)  
        self.assertTrue(user.is_staff)  
