當前位置: 首頁>>代碼示例>>Python>>正文


Python Product.fetch方法代碼示例

本文整理匯總了Python中price_watch.models.Product.fetch方法的典型用法代碼示例。如果您正苦於以下問題:Python Product.fetch方法的具體用法?Python Product.fetch怎麽用?Python Product.fetch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在price_watch.models.Product的用法示例。


在下文中一共展示了Product.fetch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_remove_from_category

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_remove_from_category(self):
        product = Product.fetch(u"Молоко Farmers Milk 1L", self.keeper)
        product.category.remove_product(product)
        transaction.commit()

        product = Product.fetch(u"Молоко Farmers Milk 1L", self.keeper)
        milk = ProductCategory.fetch("milk", self.keeper)
        self.assertIsNone(product.category)
        self.assertEqual(55.6, milk.get_price())
        self.assertEqual(45.9, milk.get_price(cheap=True))
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:12,代碼來源:unit_tests.py

示例2: test_category_add_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_category_add_product(self):
        milk = self.category
        product1 = Product(u"Молоко Great Milk 1L")
        product2 = Product(u"Молоко Greatest Milk 1L")
        milk.add_product(product1, product2)
        self.keeper.register(product1, product2)
        transaction.commit()
        self.keeper.close()

        self.keeper = open_storage()
        milk = ProductCategory.fetch("milk", self.keeper)
        stored_product1 = Product.fetch(u"Молоко Great Milk 1L", self.keeper)
        stored_product2 = Product.fetch(u"Молоко Greatest Milk 1L", self.keeper)
        self.assertIn(stored_product1, milk.products)
        self.assertIn(stored_product2, milk.products)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:17,代碼來源:unit_tests.py

示例3: fix_normalized_price

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
def fix_normalized_price():
    """
    Walk through all reports and fix normalized price_value
    and product package
    """

    keeper = get_storage()
    reports = PriceReport.fetch_all(keeper)
    for report in reports:
        try:
            correct_package_key = report.product.get_package_key()
            if report.product.package.key != correct_package_key:
                correct_package = ProductPackage.acquire(correct_package_key,
                                                         keeper)
                product = Product.fetch(report.product.key, keeper)
                print(yellow(u'Fixing package for {}: {}-->{}'.format(
                    report.product, product.package, correct_package)))
                product.package = correct_package
                report.product = product

            old_norm_price = report.normalized_price_value
            new_norm_price = report._get_normalized_price(report.price_value)
            if old_norm_price != new_norm_price:
                print(yellow(u'Fixing normal price {}-->{}'.format(
                      old_norm_price, new_norm_price)))
                report.normalized_price_value = new_norm_price
        except PackageLookupError, e:
            print(e.message)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:30,代碼來源:fabfile.py

示例4: test_category_remove_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_category_remove_product(self):
        self.category.add_product(self.product)
        transaction.commit()
        self.keeper.close()

        keeper = open_storage()
        milk = ProductCategory.fetch("milk", keeper)
        stored_product = Product.fetch(self.product.key, keeper)
        milk.remove_product(stored_product)
        transaction.commit()
        keeper.close()

        keeper = open_storage()
        stored_product = Product.fetch(self.product.key, keeper)
        milk = ProductCategory.fetch("milk", keeper)
        self.assertNotIn(stored_product, milk.products)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:18,代碼來源:unit_tests.py

示例5: test_report_assembly_new_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    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)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:36,代碼來源:unit_tests.py

示例6: test_merchant_remove_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_merchant_remove_product(self):
        self.merchant.add_product(self.product)
        transaction.commit()
        self.keeper.close()

        keeper = open_storage()
        product = Product.fetch(u"Молоко Great Milk 1L", keeper)
        merchant = Merchant.fetch("test merchant", keeper)
        merchant.remove_product(product)
        transaction.commit()
        keeper.close()

        keeper = open_storage()
        product = Product.fetch(u"Молоко Great Milk 1L", keeper)
        merchant = Merchant.fetch("test merchant", keeper)
        self.assertNotIn(product, merchant.products)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:18,代碼來源:unit_tests.py

示例7: test_product_add_merchant

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_product_add_merchant(self):
        product = self.product
        merchant = Merchant("test merchant")
        product.add_merchant(merchant)
        transaction.commit()
        self.keeper.close()

        self.keeper = open_storage()
        product = Product.fetch(u"Молоко Great Milk 1L", self.keeper)
        self.assertIn(merchant, product.merchants)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:12,代碼來源:unit_tests.py

示例8: test_merchant_added_to_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
 def test_merchant_added_to_product(self):
     raw_data = {
         "price_value": 50.4,
         "url": "http://eddies.com/products/milk/1",
         "product_title": u"Молоко Красная Цена у/паст. 3.2% 1л",
         "merchant_title": "Eddie's grocery",
         "reporter_name": "Jack",
         "date_time": DAY_AGO,
     }
     PriceReport.assemble(storage_manager=self.keeper, **raw_data)
     transaction.commit()
     product = Product.fetch(u"Молоко Красная Цена у-паст. 3.2% 1л", self.keeper)
     merchants = list(product.merchants)
     self.assertEqual(2, len(merchants))
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:16,代碼來源:unit_tests.py

示例9: test_product_add_report

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_product_add_report(self):
        product = self.product
        product.category = self.category
        report1 = PriceReport(
            price_value=42.6, product=product, reporter=Reporter("Jill"), merchant=Merchant("Scotty's grocery")
        )
        product.add_report(report1)
        product.add_report(report1)
        transaction.commit()
        self.keeper.close()

        self.keeper = open_storage()
        product = Product.fetch(u"Молоко Great Milk 1L", self.keeper)
        self.assertIn(report1, product.reports)
        self.assertEqual(1, len(product.reports))
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:17,代碼來源:unit_tests.py

示例10: test_qualified_products

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_qualified_products(self):
        milk = ProductCategory.fetch("milk", self.keeper)
        fancy_milk_title = u"Молоко The Luxury Milk!!! 0,5л"
        PriceReport.assemble(
            price_value=40,
            product_title=fancy_milk_title,
            url='http"//blah',
            merchant_title="Howie's grocery",
            reporter_name="John",
            storage_manager=self.keeper,
        )
        transaction.commit()

        fancy_milk = Product.fetch(fancy_milk_title, self.keeper)
        qual_products = [p for p, pr in milk.get_qualified_products()]
        self.assertNotIn(fancy_milk, qual_products)
        self.assertEqual(4, len(qual_products))
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:19,代碼來源:unit_tests.py

示例11: setUp

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
 def setUp(self):
     try:
         shutil.rmtree(STORAGE_DIR)
     except OSError:
         pass
     os.mkdir(STORAGE_DIR)
     self.keeper = open_storage()
     category = ProductCategory("milk")
     product = Product(u"Молоко Great Milk 1L")
     merchant = Merchant("test merchant")
     self.keeper.register(category, product, merchant)
     transaction.commit()
     self.keeper.close()
     self.keeper = open_storage()
     self.category = ProductCategory.fetch("milk", self.keeper)
     self.product = Product.fetch(u"Молоко Great Milk 1L", self.keeper)
     self.merchant = Merchant.fetch("test merchant", self.keeper)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:19,代碼來源:unit_tests.py

示例12: test_price_from_past_date

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def test_price_from_past_date(self):
        milk = ProductCategory.fetch("milk", self.keeper)
        cheapest_milk_title = u"Молоко The Cheapest Milk!!! 1л"
        PriceReport.assemble(
            price_value=30.10,
            product_title=cheapest_milk_title,
            reporter_name="John",
            merchant_title="Howie's grocery",
            url="http://someshop.com/item/344",
            date_time=HOUR_AGO,
            storage_manager=self.keeper,
        )
        PriceReport.assemble(
            price_value=29.10,
            product_title=cheapest_milk_title,
            reporter_name="John",
            merchant_title="Howie's grocery",
            url="http://someshop.com/item/344",
            date_time=WEEK_AGO,
            storage_manager=self.keeper,
        )
        PriceReport.assemble(
            price_value=25.22,
            product_title=cheapest_milk_title,
            reporter_name="John",
            merchant_title="Howie's grocery",
            url="http://someshop.com/item/344",
            date_time=MONTH_AGO,
            storage_manager=self.keeper,
        )

        transaction.commit()
        cheapest_milk = Product.fetch(cheapest_milk_title, self.keeper)

        self.assertEqual(30.10, cheapest_milk.get_price())
        self.assertEqual(1, cheapest_milk.get_price_delta(DAY_AGO, relative=False))
        self.assertEqual(0.034364261168384876, cheapest_milk.get_price_delta(DAY_AGO))
        self.assertEqual(30.10, min(milk.get_prices()))
        self.assertEqual(45.9, milk.get_price())
        self.assertEqual(0.5773195876288658, milk.get_price_delta(DAY_AGO))
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:42,代碼來源:unit_tests.py

示例13: test_report_assembly_stored_product

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    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)
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:39,代碼來源:unit_tests.py

示例14: cycle

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
    def cycle(entity_class_name_, keeper):
        """Perform all needed routines on an `entity_class`"""

        print(cyan('{} check...'.format(entity_class_name_)))
        entity_class = globals()[entity_class_name_]
        instances = entity_class.fetch_all(keeper, objects_only=False)

        for key in instances.keys():
            instance = instances[key]
            if entity_class is ProductCategory:

                if not hasattr(instance, 'category') or not instance.category:
                    category_key = instance.get_category_key()
                    category = Category.acquire(category_key, keeper)
                    instance.category = category
                    category.add(instance)
                    print(green(u'Added {} to {}'.format(instance, category)))

                for product in instance.products:
                    if product.category is not instance:
                        instance.remove_product(product)
                        print(yellow(u'Removed '
                                     u'`{}` from `{}`...'.format(product,
                                                                 instance)))
                    if len(product.reports) == 0:
                        instance.remove_product(product)
                        print(yellow(u'Removed stale '
                                     u'`{}` from `{}`...'.format(product,
                                                                 instance)))
                    if product.key not in keeper[product.namespace]:
                        try:
                            instance.remove_product(product)
                            print(yellow(u'Removed `{}` from `{}` '
                                         u'as its not '
                                         u'registered...'.format(product,
                                                                 instance)))
                        except ValueError:
                            pass

            if entity_class is Product:

                if type(instance.reports) is not list:
                    print(yellow(u'Fixing product report '
                                 u'list for `{}`...'.format(instance)))
                    instance.reports = list(instance.reports.values())

                if type(instance.merchants) is not list:
                    print(yellow(u'Fixing product merchant '
                                 u'list for `{}`...'.format(instance)))
                    instance.merchants = list(instance.merchants.values())

                if len(instance.reports) == 0:
                    print(yellow(u'Removing stale `{}`...'.format(instance)))
                    instance.delete_from(keeper)

                # check category
                try:
                    cat_key = instance.get_category_key()
                    category = ProductCategory.fetch(cat_key, keeper)
                    if instance.category is not category:
                        print(yellow(u'Adding `{}` to '
                                     u'`{}`...'.format(instance, category)))
                        category.add_product(instance)
                        instance.category = category
                except CategoryLookupError:
                    print(yellow(u'Removing `{}` as no '
                                 u'category found...'.format(instance)))
                    instance.delete_from(keeper)

                # check key
                if key != instance.key:
                    print(yellow(u'Fixing key for `{}`...'.format(key)))
                    keeper.register(instance)
                    keeper.delete_key(instance.namespace, key)

            if entity_class is Merchant:
                if type(instance.products) is not list:
                    instance.products = list(instance.products.values())
                for product in instance.products:
                    if len(product.reports) == 0:
                        print(yellow(u'Deleting `{}` '
                                     u'from `{}`...'.format(product,
                                                            instance)))
                        instance.remove_product(product)
                    for report in product.reports:
                        if type(report) is str:
                            print(yellow('Removing product with str report ...'))
                            product.delete_from(keeper)

            if entity_class is PriceReport:
                if instance.product.category is None:
                    print(yellow(u'Removing report '
                                 u'for {}'.format(instance.product)))
                    instance.delete_from(keeper)
                    break
                try:
                    correct_package_key = instance.product.get_package_key()
                except PackageLookupError, e:
                    print(e.message)
                else:
#.........這裏部分代碼省略.........
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:103,代碼來源:fabfile.py

示例15: test_strait_product_price

# 需要導入模塊: from price_watch.models import Product [as 別名]
# 或者: from price_watch.models.Product import fetch [as 別名]
 def test_strait_product_price(self):
     product = Product.fetch(u"Молоко Красная Цена у-паст. 3.2% 1л", self.keeper)
     self.assertEqual(55.6, product.get_price())
開發者ID:gitter-badger,項目名稱:price_watch,代碼行數:5,代碼來源:unit_tests.py


注:本文中的price_watch.models.Product.fetch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。