Example #1
0
 def setUp(self):
     self.sut = RecipeHasSubrecipe
     self.recipe1 = RecipeDataProvider.get().with_id(1).build()
     self.recipe2 = RecipeDataProvider.get().with_id(2).with_allergens(
         'allergens').build()
     self.recipe2.chef = ChefDataProvider.getDefault()
     self.order = 0
 def test_get_recipe_by_books_should_returnUniqueRecipes(self):
     recipe1 = RecipeDataProvider.get().with_id(1).build()
     recipe2 = RecipeDataProvider.get().with_id(2).build()
     recipe3 = RecipeDataProvider.get().with_id(1).build()
     self.book_service_stub.get_recipe_by_books.return_value = [
         recipe1, recipe2, recipe3
     ]
     actual = self.sut.get_recipe_by_books('books')
     self.assertEqual(actual, [recipe1, recipe2])
 def test_get_recipe_in_public_books(self):
     recipe1 = RecipeDataProvider.get().with_id(1).build()
     recipe2 = RecipeDataProvider.get().with_id(2).build()
     self.book_service_stub.get_recipe_in_public_books.return_value = [
         recipe1, recipe2
     ]
     recipe = self.recipe_wrapper_stub.return_value = mock.MagicMock()
     recipe.toDTO = mock.MagicMock()
     recipe.toDTO.return_value = {}
     actual = self.sut.get_recipe_in_public_books()
     expected = [{}, {}]
     self.assertEqual(actual, expected)
    def test_find_by_ids_for_explore_should_returnExpected(self):
        chef1 = ChefDataProvider.get().withEmail('*****@*****.**').withId(1).build()
        chef1.save()
        chef2 = ChefDataProvider.get().withEmail('*****@*****.**').withId(2).build()
        chef2.save()
        recipe1 = self.sut.save(RecipeDataProvider.get().active().with_chef(chef1).build())
        recipe2 = self.sut.save(RecipeDataProvider.get().active().with_chef(chef2).build())

        ids = [recipe1.id, recipe2.id]

        actual = self.sut.find_by_ids_for_explore(ids, chef1)
        actual = map(lambda x: x.id, actual)
        self.assertEqual(actual, [recipe2.id])
 def test_get_recipe_by_following_chef(self):
     recipe1 = RecipeDataProvider.get().with_id(1).build()
     recipe2 = RecipeDataProvider.get().with_id(2).build()
     self.book_service_stub.get_recipe_by_following_chef.return_value = [
         recipe1, recipe2
     ]
     recipe = self.recipe_wrapper_stub.return_value = mock.MagicMock()
     recipe.toDTO = mock.MagicMock()
     recipe.toDTO.return_value = {}
     chef = mock.Mock()
     actual = self.sut.get_recipe_by_following_chef(chef)
     expected = [{}, {}]
     self.assertEqual(actual, expected)
    def exercise_create_test_data(self):
        chef1 = ChefDataProvider.get().withEmail(
            get_random_string(length=32) + '@mi.com').build()
        chef1.save()

        chef2 = ChefDataProvider.get().withEmail(
            get_random_string(length=32) + '@mi.com').build()
        chef2.save()

        chef3 = ChefDataProvider.get().withEmail(
            get_random_string(length=32) + '@mi.com').build()
        chef3.save()

        recipe1 = RecipeDataProvider.get().with_chef(chef1).with_name(
            'public-r-private-b').active().publish().build()
        recipe2 = RecipeDataProvider.get().with_chef(chef1).with_name(
            'public-r-public-b').active().publish().build()
        recipe3 = RecipeDataProvider.get().with_chef(chef1).with_name(
            'private-r-public-b').active().build()
        recipe4 = RecipeDataProvider.get().with_chef(chef1).with_name(
            'private-r-private-b').active().build()
        self.save_all([recipe1, recipe2, recipe3, recipe4])

        book1 = BookDataProvider.get().with_chef(chef1).with_name(
            'public').publish().build()
        book2 = BookDataProvider.get().with_chef(chef1) \
            .with_collaborators('[%d],' % chef2.id) \
            .with_name('private').build()
        self.save_all([book1, book2])

        book1.add_recipe(recipe2)
        book1.add_recipe(recipe3)
        book1.save()

        book2.add_recipe(recipe1)
        book2.add_recipe(recipe4)
        book2.save()

        return {
            "recipes": [recipe1, recipe2, recipe3, recipe4],
            "books": [book1, book2],
            "chefs": [chef1, chef2, chef3]
        }
    def setUp(self):
        super(RecipeSubrecipeRepositoryTest, self).setUp()
        self.sut = RecipeHasSubrecipeRepository.new()
        self.recipe1 = RecipeDataProvider.get().with_id(1).build()
        self.recipe2 = RecipeDataProvider.get().with_id(2).with_allergens(
            'allergens').build()
        self.recipe2.chef = ChefDataProvider.getDefault()
        self.order = 1

        RecipeHasSubrecipeDataProvider.get().with_recipe_id(1).with_price(
            100).build().save()
        RecipeHasSubrecipeDataProvider.get().with_recipe_id(1).with_price(
            100).build().save()
        RecipeHasSubrecipeDataProvider.get().with_recipe_id(1).with_price(
            100).build().save()
        RecipeHasSubrecipeDataProvider.get().with_recipe_id(2).with_price(
            100).build().save()
        RecipeHasSubrecipeDataProvider.get().with_recipe_id(3).with_price(
            100).build().save()
    def test_add_subrecipe_should_forwardCorrectArguments(self):
        recipe = RecipeDataProvider.get_default()
        self.recipe_service_stub.get_by_id.return_value = Recipe(recipe)
        self.recipe_ingredient_service_stub.get_price.return_value = 10
        self.recipe_subrecipe_service_stub.get_price.return_value = 10
        self.sut.get_allergens_for_recipe = mock.Mock()
        self.sut.get_allergens_for_recipe.return_value = []
        self.sut.getBigestOrder = mock.Mock()
        self.sut.getBigestOrder.return_value = 1
        self.sut.add_subrecipe('', '', '')

        self.recipe_subrecipe_service_stub.create.assert_called_with(
            recipe, recipe, 20, [], 1, '')
    def exercise_create_test_data(self, chef):
        recipe1 = RecipeDataProvider.get().with_name(
            'recipe-1').active().build()
        recipe2 = RecipeDataProvider.get().with_name(
            'recipe-2').active().build()
        recipe3 = RecipeDataProvider.get().with_name(
            'recipe-3').active().build()
        recipe4 = RecipeDataProvider.get().with_name(
            'recipe-4').active().build()
        recipe5 = RecipeDataProvider.get().with_name(
            'recipe-5').active().build()
        recipe6 = RecipeDataProvider.get().with_name(
            'recipe-6').active().build()
        recipe7 = RecipeDataProvider.get().with_name('recipe-7').build()
        self.save_all(
            [recipe1, recipe2, recipe3, recipe4, recipe5, recipe6, recipe7])

        book1 = BookDataProvider.get().with_name('book-1').with_collaborators('[%d],' % chef.id) \
            .with_book_type('P').build()
        book2 = BookDataProvider.get().with_name('book-2').with_book_type(
            'N').build()
        book3 = BookDataProvider.get().with_name('book-3').with_book_type(
            'P').build()
        book4 = BookDataProvider.get().with_name('book-4').with_book_type(
            'P').build()
        self.save_all([book1, book2, book3, book4])
        # collaborator case - show recipe-1, recipe-3
        book1.add_recipe(recipe1)
        book1.add_recipe(recipe3)
        book1.save()
        # public case - show recipe-2 (recipe-7 is draft, not showing)
        book2.add_recipe(recipe1)
        book2.add_recipe(recipe2)
        book2.add_recipe(recipe7)
        book2.save()
        # owner case - show recipe-4
        book3.chef = chef
        book3.add_recipe(recipe4)
        book3.save()
        # private case - not show
        book4.add_recipe(recipe5)
        book4.add_recipe(recipe6)
        book4.save()

        return {
            "recipes":
            [recipe1, recipe2, recipe3, recipe4, recipe5, recipe6, recipe7],
            "books": [book1, book2, book3, book4],
            "chefs": [chef]
        }
Example #10
0
    def exercise_create_book_with_recipes(self):
        recipe1 = RecipeDataProvider.get().with_name('recipe-1').with_id(1).active().build()
        recipe2 = RecipeDataProvider.get().with_name('recipe-2').with_id(2).active().build()
        recipe3 = RecipeDataProvider.get().with_name('recipe-3').with_id(3).build()
        recipe4 = RecipeDataProvider.get().with_name('recipe-4').with_id(4).active().build()
        recipe5 = RecipeDataProvider.get().with_name('recipe-5').with_id(5).active().build()
        recipe6 = RecipeDataProvider.get().with_name('recipe-6').with_id(6).build()
        recipe7 = RecipeDataProvider.get().with_name('recipe-7').with_id(7).active().build()
        self.save([recipe1, recipe2, recipe3, recipe4, recipe5, recipe6, recipe7])

        book1 = self._saveBook('book-1', '[1],[2],[3]')
        book1.book_type = 'N'
        book1.private = False
        book2 = self._saveBook('book-2', '[2],[5],[6]')
        book3 = self._saveBook('book-3', '[3],[4],[5],[%d]' % self.chef.id)
        book4 = self._saveBook('book-4', '')
        chefFollow = ChefDataProvider.get().withEmail('*****@*****.**').withId(8888).build()
        chefFollow.save()
        self.chef.follow(chefFollow)

        book1.add_recipe(recipe1)
        book1.add_recipe(recipe2)
        book1.chef = self.chef
        book1.save()
        book2.add_recipe(recipe1)
        book2.add_recipe(recipe3)
        book2.add_recipe(recipe7)
        book2.save()
        book3.add_recipe(recipe4)
        book3.save()
        book4.add_recipe(recipe5)
        book4.add_recipe(recipe6)
        book4.private = False
        book4.book_type = 'N'
        book4.status = 'A'
        book4.chef = chefFollow
        book4.save()

        return dict(
            books=[book1, book2, book3, book4],
            recipes=[recipe1, recipe2, recipe1, recipe7, recipe4, recipe5]
        )
    def test_get_allergens_for_recipe_should_returnExpected(self):
        ingr1 = RecipeHasIngredientDataProvider.get().with_allergens(
            "allergen-1, allergen-2, allergen-3").build()
        ingr2 = RecipeHasIngredientDataProvider.get().with_allergens(
            "allergen-1").build()
        reci1 = RecipeHasSubrecipeDataProvider.get().with_allergens(
            "allergen-2, allergen-4").build()

        recipe = RecipeDataProvider.get().with_allergens(
            "recipe-allergen").build()

        self.recipe_ingredient_service_stub.get_by_recipe_id.return_value = [
            ingr1, ingr2
        ]
        self.recipe_subrecipe_service_stub.get_by_recipe_id.return_value = [
            reci1
        ]
        self.recipe_service_stub.get_by_id.return_value = Recipe(recipe)

        actual = self.sut.get_allergens_for_recipe('')
        self.assertEqual(actual, [
            'allergen-1', 'allergen-2', 'allergen-3', 'allergen-4',
            'recipe-allergen'
        ])
 def test_remove_allergens_to_recipe_should_removeAllergensFromRecipe(self):
     self.repositoryStub.findById.return_value = Recipe(RecipeDataProvider.get().with_allergens("Fish, Celery").build())
     allergens = ['Fish']
     actual = self.sut.remove_allergens_from_recipe('', allergens)
     self.assertTrue(self.repositoryStub.save.called)
     self.assertEqual(actual.allergens, "Celery")
 def test_add_allergens_to_recipe_should_addAllergensToRecipe(self):
     self.repositoryStub.findById.return_value = Recipe(RecipeDataProvider.get().with_allergens("Fish, Celery").build())
     allergens = ['Peanuts', 'Fish', 'Milk']
     actual = self.sut.add_allergens_to_recipe('', allergens)
     self.assertTrue(self.repositoryStub.save.called)
     self.assertEqual(actual.allergens, "Celery, Peanuts, Fish, Milk")