def test_createUser_shouldCreateUserProfile(self):
        user = RecipesUser(
            email='*****@*****.**',
            password='******',
        )
        user.save()

        profile = RecipesUserProfile.objects.last()
        self.assertEqual(profile.user_id, user.id)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    def test_userCreate_whenValidEmailAndPass_shouldCreateUser(self):
        user = RecipesUser(
            email='*****@*****.**',
            password='******',
        )

        user.full_clean()
        user.save()

        self.assertIsNotNone(user)
예제 #7
0
    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)