def test_createUser_shouldCreateUserProfile(self): user = RecipesUser( email='*****@*****.**', password='******', ) user.save() profile = RecipesUserProfile.objects.last() self.assertEqual(profile.user_id, user.id)
def test_userGetFullName_whenCreatedWithNames_shouldReturnFullName(self): user = RecipesUser( email='*****@*****.**', password='******', first_name='FirstName', last_name='LastName', ) full_name = user.get_full_name() expected_full_name = 'FirstName LastName' self.assertEqual(expected_full_name, full_name)
def test_strRecipe_shouldReturnRecipeName(self): user = RecipesUser( email='*****@*****.**', password='******', ) user.save() recipe = Recipe.objects.create( recipe_type=Recipe.MAIN_DISH, name='Valid name', ingredients=['ingredient1', 'ingredient2'], instructions='Valid instructions', image='valid/image/path.jpg', user=user, ) recipe_str = str(recipe) self.assertEqual(recipe.name, recipe_str)
def test_createRecipe_whenValidData_shouldCreateRecipe(self): user = RecipesUser( email='*****@*****.**', password='******', ) user.save() recipe = Recipe.objects.create( recipe_type=Recipe.MAIN_DISH, name='Valid name', ingredients=['ingredient1', 'ingredient2'], instructions='Valid instructions', image='valid/image/path.jpg', user=user, ) recipe.full_clean() recipe.save() self.assertIsNotNone(recipe)
def test_createRecipe_whenMissingOrInvalidData_shouldRaiseError(self): user = RecipesUser( email='*****@*****.**', password='******', ) user.save() recipe = Recipe.objects.create( recipe_type='invalid', name='', ingredients=['ingredient1', 'ingredient2'], instructions='Valid instructions', image='', user=user, ) try: recipe.full_clean() recipe.save() self.fail() except ValidationError as ex: self.assertIsNotNone(ex)
def test_userCreate_whenValidEmailAndPass_shouldCreateUser(self): user = RecipesUser( email='*****@*****.**', password='******', ) user.full_clean() user.save() self.assertIsNotNone(user)
def test_userCreate_whenInvalidEmail_shouldRaiseError(self): user = RecipesUser( email='invalid', password='******', ) try: user.full_clean() user.save() self.fail() except ValidationError as ex: self.assertIsNotNone(ex)