def test_notifyCollaborators_should_throw_whenEmailInvalid(self):
     book = Book()
     invalid_collaborators = [
         ChefDataProvider.get().withEmail("invalid-email").build(),
         ChefDataProvider.get().withEmail("*****@*****.**").build()
     ]
     self.assertRaises(InvalidMailException, self.sut.notify_collaborators,
                       book, invalid_collaborators)
 def test_notifyCollaborators_should_sendEmails(self):
     book = Book()
     collaborators = [
         ChefDataProvider.get().withEmail("*****@*****.**").build(),
         ChefDataProvider.get().withEmail("*****@*****.**").build(),
         ChefDataProvider.get().withEmail("*****@*****.**").build()
     ]
     self.sut.notify_collaborators(book, collaborators)
     self.assertEqual(self.mailerStub.send_email.call_count, 3)
    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])
Exemple #4
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
Exemple #5
0
 def setUp(self):
     super(BookRepositoryTest, self).setUp()
     self.chef = ChefDataProvider.getDefault()
     self.chef.id = 9999
     self.chef.save()
     self.sut = BookRepository.new()
     self.test_material = self.exercise_create_book_with_recipes()
 def test_get_costing_table_shouldCallWithRepositoryMethod(self):
     chef = ChefDataProvider.getDefault()
     self.repositoryStub.find_by_chef_id.return_value = 'result'
     actual = self.sut.get_costing_table(chef, 'filter', 2)
     self.repositoryStub.find_by_chef_id.assert_called_with(chef_id=chef.id,
                                                            filter='filter',
                                                            page=2)
     self.assertEqual(actual, 'result')
 def test_find_by_chef_should_returnListOfRecipeAccessibleByChef(self):
     chef = ChefDataProvider.get().withEmail('*****@*****.**').build()
     chef.save()
     instances = self.exercise_create_test_data(chef)
     actual = self.sut.find_by_chef(chef)
     actual = map(lambda x: x.recipe_name, actual)
     expected = ['recipe-1', 'recipe-2', 'recipe-3', 'recipe-4']
     self.assertEqual(actual, expected)
     self.delete_all(instances)
    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]
        }
Exemple #9
0
    def exercise_create_test_data(self):
        chef1 = ChefDataProvider.get().withEmail('*****@*****.**').build()
        chef2 = ChefDataProvider.get().withEmail('*****@*****.**').build()
        self.save_instances([chef1, chef2])

        gen_ingr1 = GenericIngredientDataProvider.get().withIngredient('ingr1').build()
        gen_ingr2 = GenericIngredientDataProvider.get().withIngredient('ingr2').build()
        gen_ingr3 = GenericIngredientDataProvider.get().withIngredient('ingr3').build()
        gen_ingr4 = GenericIngredientDataProvider.get().withIngredient('ingr4').build()
        gen_ingr5 = GenericIngredientDataProvider.get().withIngredient('ingr5').build()
        self.save_instances([gen_ingr1, gen_ingr2, gen_ingr3, gen_ingr4, gen_ingr5])

        custom_ingr1 = CustomChangesIngredientDataProvider.get() \
            .with_chef_id(chef1.id) \
            .with_ingredient('new_ingr1') \
            .build()

        custom_ingr2 = CustomChangesIngredientDataProvider.get() \
            .with_chef_id(chef1.id) \
            .with_ingredient('new_ingr2') \
            .build()

        custom_ingr3 = CustomChangesIngredientDataProvider.get() \
            .with_chef_id(chef1.id) \
            .with_generic_ingredient_id(gen_ingr2.id) \
            .with_is_deleted(True) \
            .build()

        custom_ingr4 = CustomChangesIngredientDataProvider.get() \
            .with_chef_id(chef2.id) \
            .with_ingredient('new_ingr1') \
            .build()

        self.save_instances([custom_ingr1, custom_ingr2, custom_ingr3, custom_ingr4])

        return dict(
            custom_ingr=[custom_ingr1, custom_ingr2, custom_ingr3, custom_ingr4],
            generic_ingr=[gen_ingr1, gen_ingr2, gen_ingr3, gen_ingr4, gen_ingr5],
            chef=[chef1, chef2]
        )
    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()
Exemple #11
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]
        )
Exemple #12
0
    def toDTO(self):
        chef = ChefDataProvider.get()\
            .withId(1)\
            .withName('first')\
            .withSurname('surname')\
            .withEmail('*****@*****.**')

        chef.avatar_thumb = mock.Mock()
        chef.avatar_thumb.return_value = 'avatar_link'

        expected = {
            'id': 1,
            'name': 'first',
            'surname': 'surname',
            'email': '*****@*****.**',
            'avatar': 'avatar_link'
        }

        sut = self.sut(chef)
        actual = sut.toDTO()

        self.assertEqual(actual, expected)
Exemple #13
0
    def test_getCollaborators_should_returnListOfChefs(self):
        chef = ChefDataProvider.get() \
            .withName('chef') \
            .withEmail('*****@*****.**') \
            .withSurname('01') \
            .withId(1) \
            .build()

        collaborators = "[1],[2],[3],[4],"
        self.chefServiceStub.getByIds.return_value = [chef]

        actual = self.sut.getCollaborators(collaborators)
        expected = [{
            'email': '*****@*****.**',
            'surname': '01',
            'id': 1,
            'avatar': '/static/img/chef_avatar.jpg',
            'name': 'chef'
        }]

        self.chefServiceStub.getByIds.assert_called_with([1, 2, 3, 4])
        self.assertEqual(actual, expected)
 def test_count_suggestion_list_should_returnExpected_whenHasNoMore(self):
     chef = ChefDataProvider.getDefault()
     self.recipe_suggestion_view_repository_stub.count_by_chef.return_value = 100
     actual = self.sut.count_suggestion_list(chef, '')
     self.assertEqual(actual, 100)
 def test_count_suggestion_list_should_returnExpected(self):
     chef = ChefDataProvider.getDefault()
     self.repositoryStub.count_by_chef_id.return_value = 100
     actual = self.sut.count_suggestion_list(chef, '')
     self.assertEqual(actual, 100)
Exemple #16
0
 def setUp(self):
     self.sut = ChefEntity()
     self.CHEF = ChefDataProvider.getDefault()
 def test_get_suggestion_list_should_returnExpected(self):
     chef = ChefDataProvider.getDefault()
     self.repositoryStub.find_by_chef_id.return_value = []
     actual = self.sut.get_suggestion_list(chef, '', 5)
     self.assertEqual(actual, [])
Exemple #18
0
 def test_updateMembership_should_return_chef_with_updated_membership(self):
     chef = ChefDataProvider.get().withMembership('default')
     membership = 'pro'
     actual = self.sut.updateMembership(chef, membership)
     self.assertEqual(actual.membership, 'pro')