def make_load(): # Categories if not category_repo.get_all(): drinks = Category(name='Drinks') jellies = Category(name='Breads') breads = Category(name='Jellies') categories = [drinks, breads, jellies] category_repo.save_many(categories) category_repo.commit() else: drinks = category_repo.get_by_name(name='Drinks') breads = category_repo.get_by_name(name='Breads') jellies = category_repo.get_by_name(name='Jellies') # SubCategories if not sub_category_repo.get_all(): milks = SubCategory(name='Milks', category=drinks) low_calorie_jellies = SubCategory(name='Low Calories Jellies', category=jellies) white_breads = SubCategory(name='White Breads', category=breads) subcategories = [milks, low_calorie_jellies, white_breads] sub_category_repo.save_many(subcategories) sub_category_repo.commit() else: milks = sub_category_repo.get_by_name(name='Milks') low_calorie_jellies = sub_category_repo.get_by_name( name='Low Calories Jellies') white_breads = sub_category_repo.get_by_name(name='White Breads') print('inserting Milks...') milk_a = Product(name='Milk A', price=3.99, gtin='1234', sub_category=milks) milk_b = Product(name='Milk B', price=4.01, gtin='1235', sub_category=milks) prod_repo.save(milk_a) prod_repo.save(milk_b) prod_repo.commit() print('inserting Bread and Jelly from a list...') products = [ Product(name='Bread', price=0.99, gtin='4321', sub_category=white_breads), Product(name='Jelly', price=5.99, gtin='1111', sub_category=low_calorie_jellies) ] prod_repo.save_many(products) prod_repo.commit()
def test_check_invalid_price(self): no_price = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=0, sub_category=self.sub_category) greater_then_one_million = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=1000001, sub_category=self.sub_category) self.assertFalse(ProductGuard().check(no_price), 'No price expected.') self.assertFalse(ProductGuard().check(greater_then_one_million), 'Price greater than 1 million expected.')
def setUp(self): self.category = Category('Breads') self.sub_category = SubCategory('Gluten Free Breads', category=self.category) self.product = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.product_with_id = Product( name='Warburtons Gluten Free Multiseed Loaf', gtin='1234567890321', price=3.20, sub_category=self.sub_category, _id='b07e1d28b7cf45deb63ff5f19e764f90')
def test_check_invalid_gtin(self): less_than_13 = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='123456789012', price=3.20, sub_category=self.sub_category) greater_than_13 = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='12345678901234', price=3.20, sub_category=self.sub_category) self.assertFalse(ProductGuard().check(less_than_13), 'GTIN less than 13 characters expected.') self.assertFalse(ProductGuard().check(greater_than_13), 'GTIN greater than 13 characters expected.')
def test_check_no_gtin(self): product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin=None, price=3.20, sub_category=self.sub_category) self.assertFalse(ProductGuard().check(product), 'No GTIN expected')
def test_check_no_name(self): product = Product(name=None, gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.assertFalse(ProductGuard().check(product), 'Name not expected.')
def test_check_ok(self): product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.assertTrue(ProductGuard().check(product))
def test_check_invalid_name(self): product = Product(name='Wa', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.assertFalse(ProductGuard().check(product), 'A short name is expected')
def test_check_invalid_category(self): no_category = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=None) self.assertFalse(ProductGuard().check(no_category), 'No category expected.')
def setUp(self): self.category = Category('Breads') self.sub_category = SubCategory('Gluten Free Breads', category=self.category) self.product = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.supermarket = SupermarketVO( _id='e6981d6ea68b4cc682bbb03139ef679e', name='MySupermarket', is_active=True)
def default_product_with(self, name, gtin, price, sub_category_id): sub_category = self.__sub_category_repo.get_by_id(sub_category_id) if not sub_category: raise ProductRequiresSubCategoryException(sub_category_id) # if not gtin_should_be_unique_validation(self.__product_repo, gtin): # raise ProductWithDuplicatedGtinException(gtin) product = Product(name=name, gtin=gtin, price=price, sub_category=sub_category) guard = ProductGuard() if not guard.check(product): raise ProductException(guard.get_issues()) return product
def setUp(self): self.category = Category('Breads') self.sub_category = SubCategory('Gluten Free Breads', category=self.category) product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) supermarket = SupermarketVO(_id='e6981d6ea68b4cc682bbb03139ef679e', name='MySupermarket', is_active=True) self.product_supermarket = ProductSupermarket( product=product, supermarket=supermarket, price_update_url='http://www.mysupermarket.co.uk') self.product_supermarket_with_id = ProductSupermarket( product=product, supermarket=supermarket, price_update_url='http://www.mysupermarket.co.uk', _id='fdf88acb94984a859bd342c05ead9beb')
def test_default_product_to_update(self): category = Category(_id='418f5f846e1149e28b5f5310bc7ea8c5', name='Breads') sub_category = SubCategory(_id='b07e1d28b7cf45deb63ff5f19e764f90', name='White Breads', category=category) self.sub_category_repo.get_by_id.return_value = sub_category self.product_repo.get_by_id.return_value = Product( name='Warburtons Gluten Free Multiseed Loaf', gtin='1234567890123', price=5.99, sub_category=sub_category) product = self.product_factory.default_product_to_update( name='Warburtons Gluten Free Multiseed Loaf', gtin='1234567890123', price=7.99, sub_category_id=sub_category.id, _id='6fc9713877dc40f78ba5f77136c6c67b') self.assertIsNotNone(product) self.assertEqual(product.price, 7.99)
class ProductTest(TestCase): def setUp(self): self.category = Category('Breads') self.sub_category = SubCategory('Gluten Free Breads', category=self.category) self.product = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.product_with_id = Product( name='Warburtons Gluten Free Multiseed Loaf', gtin='1234567890321', price=3.20, sub_category=self.sub_category, _id='b07e1d28b7cf45deb63ff5f19e764f90') def test_create_product(self): self.assertIsNotNone(self.product) def test_create_product_with_id(self): self.assertIsNotNone(self.product_with_id) self.assertEqual(self.product_with_id.id, 'b07e1d28b7cf45deb63ff5f19e764f90') def test_product_as_json(self): expected = { 'id': self.product.id, 'name': 'Warburtons Gluten Free Tiger Artisan Bloomer', 'gtin': '1234567890123', 'price': 3.20, 'sub_category': { 'id': self.sub_category.id, 'name': 'Gluten Free Breads' } } self.assertEqual(self.product.as_json(), expected)
def setUp(self): self.product_repo = mock.Mock() self.supermarket_dao = mock.Mock() self.product_supermarket_repo = mock.Mock() self.product_supermarket_factory = ProductSupermarketFactory( self.product_repo, self.supermarket_dao, self.product_supermarket_repo) self.category = Category('Breads') self.sub_category = SubCategory('Gluten Free Breads', category=self.category) self.product = Product( name='Warburtons Gluten Free Tiger Artisan Bloomer', gtin='1234567890123', price=3.20, sub_category=self.sub_category) self.supermarket = SupermarketVO( _id='e6981d6ea68b4cc682bbb03139ef679e', name='MySupermarket', is_active=True) self.existing_product_supermarket = ProductSupermarket( product=self.product, supermarket=self.supermarket, price_update_url='http://www.mysupermarket.co.uk')
def create_db(): db.create_all() category_repo = CategoryRepository() sub_category_repo = SubCategoryRepository() prod_repo = ProductRepository() supermarket_dao = SupermarketDAO() # Categories if not category_repo.get_all(): drinks = Category(name='Drinks') jellies = Category(name='Breads') breads = Category(name='Jellies') categories = [drinks, breads, jellies] category_repo.save_many(categories) category_repo.commit() else: drinks = category_repo.get_by_name(name='Drinks') breads = category_repo.get_by_name(name='Breads') jellies = category_repo.get_by_name(name='Jellies') # SubCategories if not sub_category_repo.get_all(): milks = SubCategory(name='Milks', category=drinks) low_calorie_jellies = SubCategory(name='Low Calories Jellies', category=jellies) white_breads = SubCategory(name='White Breads', category=breads) subcategories = [milks, low_calorie_jellies, white_breads] sub_category_repo.save_many(subcategories) sub_category_repo.commit() else: milks = sub_category_repo.get_by_name(name='Milks') low_calorie_jellies = sub_category_repo.get_by_name( name='Low Calories Jellies') white_breads = sub_category_repo.get_by_name(name='White Breads') # Products if not prod_repo.get_all(): products = [ Product(name='Milk A', price=3.99, gtin='1234', sub_category=milks), Product(name='Milk B', price=4.01, gtin='1235', sub_category=milks), Product(name='Bread', price=0.99, gtin='4321', sub_category=white_breads), Product(name='Jelly', price=5.99, gtin='1111', sub_category=low_calorie_jellies) ] prod_repo.save_many(products) prod_repo.commit() # Supermarkets if not supermarket_dao.get_all(): supermarkets = [ SupermarketVO( _id='d441a91ce8cc4d838eb3ccf69de3f932', name='Supermercados Boa', is_active=True, module_name='src.domain.pricing_updates.boa_scraping', class_name='BoaScraping'), SupermarketVO( _id='73dadb6c0d164e6b8a48c52a8aa1091f', name='Carrefour', is_active=True, module_name='src.domain.pricing_updates.carrefour_scraping', class_name='CarrefourScraping') ] supermarket_dao.save_many(supermarkets)