def test_delete_report(self): victim = PriceReport.fetch(self.report1_key, self.keeper) product = victim.product victim.delete_from(self.keeper) transaction.commit() self.assertNotIn(victim, product) self.assertNotIn(victim, PriceReport.fetch_all(self.keeper))
def test_delete_report(self): victim = PriceReport.fetch(self.report1_key, self.keeper) product = victim.product victim.delete_from(self.keeper) transaction.commit() self.assertNotIn(victim, product) self.assertNotIn(victim, PriceReport.fetch_all(self.keeper))
def test_report_assembly_new_product(self): from uuid import uuid4 product_title = u'Молоко Great Milk TWO 1L' reporter_name = 'Jill' merchant_title = "Scotty's grocery" raw_data1 = { 'product_title': product_title, 'price_value': 42.6, 'url': 'http://scottys.com/products/milk/1', 'merchant_title': merchant_title, 'date_time': None, 'reporter_name': reporter_name } uuid_ = uuid4() report, stats = PriceReport.assemble(storage_manager=self.keeper, uuid=uuid_, **raw_data1) transaction.commit() self.keeper.close() self.keeper = open_storage() stored_report = PriceReport.fetch(report.key, self.keeper) self.assertEqual(report.key, stored_report.key) self.assertEqual(report.key, str(uuid_)) product = Product.fetch(product_title, self.keeper) self.assertEqual(product_title, product.title) self.assertIn(report, product.reports) category = ProductCategory.fetch('milk', self.keeper) self.assertIn(product, category.products) merchant = Merchant.fetch(merchant_title, self.keeper) self.assertEqual(merchant_title, merchant.title) self.assertIn(product, merchant)
def test_report_assembly_new_product(self): from uuid import uuid4 product_title = u"Молоко Great Milk TWO 1L" reporter_name = "Jill" merchant_title = "Scotty's grocery" raw_data1 = { "product_title": product_title, "price_value": 42.6, "url": "http://scottys.com/products/milk/1", "merchant_title": merchant_title, "date_time": None, "reporter_name": reporter_name, } uuid_ = uuid4() report, stats = PriceReport.assemble(storage_manager=self.keeper, uuid=uuid_, **raw_data1) transaction.commit() self.keeper.close() self.keeper = open_storage() stored_report = PriceReport.fetch(report.key, self.keeper) self.assertEqual(report.key, stored_report.key) self.assertEqual(report.key, str(uuid_)) product = Product.fetch(product_title, self.keeper) self.assertEqual(product_title, product.title) self.assertIn(report, product.reports) category = ProductCategory.fetch("milk", self.keeper) self.assertIn(product, category.products) merchant = Merchant.fetch(merchant_title, self.keeper) self.assertEqual(merchant_title, merchant.title) self.assertIn(product, merchant)
def test_presense_in_references(self): milk = ProductCategory.fetch('milk', self.keeper) diary = Category.fetch('diary', self.keeper) self.assertEqual('diary', diary.title) self.assertEqual(4, len(milk.products)) self.assertIn(64.3, milk.get_prices()) report1 = PriceReport.fetch(self.report1_key, self.keeper) self.assertEqual(55.6, report1.normalized_price_value) self.assertIs(milk, report1.product.category) self.assertEqual(u'Московский магазин', report1.merchant.title) self.assertEqual('Jack', report1.reporter.name) self.assertIs(diary, milk.category) self.assertIn(milk, diary.categories)
def test_presense_in_references(self): milk = ProductCategory.fetch("milk", self.keeper) diary = Category.fetch("diary", self.keeper) self.assertEqual("diary", diary.title) self.assertEqual(4, len(milk.products)) self.assertIn(64.3, milk.get_prices()) report1 = PriceReport.fetch(self.report1_key, self.keeper) self.assertEqual(55.6, report1.normalized_price_value) self.assertIs(milk, report1.product.category) self.assertEqual(u"Московский магазин", report1.merchant.title) self.assertEqual("Jack", report1.reporter.name) self.assertIs(diary, milk.category) self.assertIn(milk, diary.categories)
def display_report(report_key): """Display a report by key""" keeper = get_storage() report = PriceReport.fetch(report_key, keeper) if not report: print(yellow('No report with key ' + report_key)) exit() print('Key: ' + report.key) print('Product: ' + report.product.title) print('Package: ' + report.product.get_package_key()) if report.product.category is None: if confirm(yellow('The report is not valid, remove?'), default=False): report.delete_from(keeper) transaction.commit() else: print('Product category: ' + report.product.category.title) keeper.close()
def display_report(report_key): """Display a report by key""" keeper = get_storage() report = PriceReport.fetch(report_key, keeper) if not report: print(yellow('No report with key ' + report_key)) exit() print('Key: ' + report.key) print('Product: ' + report.product.title) print('Package: ' + report.product.get_package_key()) if report.product.category is None: if confirm(yellow('The report is not valid, remove?'), default=False): report.delete_from(keeper) transaction.commit() else: print('Product category: ' + report.product.category.title) keeper.close()
def test_report_assembly_stored_product(self): product_title = u'Молоко Great Milk three 1L' product = Product(product_title, self.category) self.keeper.register(product) transaction.commit() self.keeper.close() self.keeper = open_storage() reporter_name = 'Jill' merchant_title = "Scotty's grocery 2" raw_data1 = { 'product_title': product_title, 'price_value': 42.6, 'url': 'http://scottys2.com/products/milk/1', 'merchant_title': merchant_title, 'date_time': None, 'reporter_name': reporter_name } report, stats = PriceReport.assemble(self.keeper, **raw_data1) transaction.commit() self.keeper.close() self.keeper = open_storage() stored_report = PriceReport.fetch(report.key, self.keeper) self.assertEqual(report.key, stored_report.key) product = Product.fetch(product_title, self.keeper) self.assertEqual(product_title, product.title) self.assertIn(report, product) category = ProductCategory.fetch('milk', self.keeper) self.assertIn(product, category) merchant = Merchant.fetch(merchant_title, self.keeper) self.assertEqual(merchant_title, merchant.title) self.assertIn(product, merchant) self.assertIn(merchant, product.merchants)
def test_report_assembly_stored_product(self): product_title = u"Молоко Great Milk three 1L" product = Product(product_title, self.category) self.keeper.register(product) transaction.commit() self.keeper.close() self.keeper = open_storage() reporter_name = "Jill" merchant_title = "Scotty's grocery 2" raw_data1 = { "product_title": product_title, "price_value": 42.6, "url": "http://scottys2.com/products/milk/1", "merchant_title": merchant_title, "date_time": None, "reporter_name": reporter_name, } report, stats = PriceReport.assemble(self.keeper, **raw_data1) transaction.commit() self.keeper.close() self.keeper = open_storage() stored_report = PriceReport.fetch(report.key, self.keeper) self.assertEqual(report.key, stored_report.key) product = Product.fetch(product_title, self.keeper) self.assertEqual(product_title, product.title) self.assertIn(report, product) category = ProductCategory.fetch("milk", self.keeper) self.assertIn(product, category) merchant = Merchant.fetch(merchant_title, self.keeper) self.assertEqual(merchant_title, merchant.title) self.assertIn(product, merchant) self.assertIn(merchant, product.merchants)