text: from unittest.mock import patch
  
  from django.test import TestCase
  from django.contrib.auth import get_user_model
  
  from core import models
  
  
  def sample_user(email="test@gmail.com", password="testpass"):
      """Create a sample test"""
      return get_user_model().objects.create_user(email, password)
  
  
  class ModelTests(TestCase):
      def test_create_user_email_successful(self):
          """Test creating a new user with an email is successful"""
          email = "testuser@gmail.com"
          password = "testuserpassword"
          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 email for a new user is normaized"""
          email = "testuser@Gmail.com"
          user = get_user_model().objects.create_user(email, "test321")
  
          self.assertEqual(user.email, email.lower())
  
      def test_new_user_invalid_email(self):
          """Test creating user with no email raises error"""
          with self.assertRaises(ValueError):
              get_user_model().objects.create_user(None, "123")
  
      def test_create_new_super_user(self):
          """Test creating Super User"""
          user = get_user_model().objects.create_superuser(
              "supertestuser@gmail.com", "superuser"
          )
          self.assertTrue(user.is_superuser)
          self.assertTrue(user.is_staff)
  
      def test_tag_str(self):
          """Test the tag string representation"""
          tag = models.Tag.objects.create(
              user=sample_user(),
              name="Vegan",
          )
          self.assertEqual(str(tag), tag.name)
  
      def test_ingredient_str(self):
          """Test ingredient representation"""
          ingredient = models.Ingredient.objects.create(user=sample_user(), name="Cheese")
          self.assertEqual(str(ingredient), ingredient.name)
  
      def test_recipe_str(self):
          """Test recipe str representation"""
          recipe = models.Recipe.objects.create(
              user=sample_user(), title="Combinaton Pasta", time_minutes=5, price=5.00
          )
          self.assertEqual(str(recipe), recipe.title)
  
      @patch("uuid.uuid4")
      def test_recipe_filename_uuid(self, mock_uuid):
          """Test image is been saved in correct dir"""
          uuid = "test-uuid"
          mock_uuid.return_value = uuid
          file_path = models.recipe_image_file_path(None, "myimage.jpeg")
          exp_path = f"uploads/recipe/{uuid}.jpeg"
  
          self.assertEqual(file_path, exp_path)
  