コード例 #1
0
    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)