Exemple #1
0
 def test_get_offerings_from_product(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(len(offerings0), 3)
     self.assertEqual(len(offerings1), 4)
     self.assertEqual(len(offerings2), 1)
     self.assertEqual(offerings0[0]["Price"]["LandedPrice"]["Amount"]["value"], "17.99")
     # test raise KeyError
     self.assertRaises(KeyError, papi.get_offerings_from_product, {})
Exemple #2
0
 def test_get_offerings_from_product(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(len(offerings0), 3)
     self.assertEqual(len(offerings1), 4)
     self.assertEqual(len(offerings2), 1)
     self.assertEqual(
         offerings0[0]['Price']['LandedPrice']['Amount']['value'], '17.99')
     # test raise KeyError
     self.assertRaises(KeyError, papi.get_offerings_from_product, {})
Exemple #3
0
 def test_products(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     papi.make_products()
     ps = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(ps[0])
     products = papi.products
     lp = products["B00KUP84L2"].lowest_price
     self.assertEqual(lp, 17.99)
Exemple #4
0
 def test_get_seller_from_listing(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(papi.get_seller_from_listing(offerings0[0]), "Amazon")
     self.assertEqual(papi.get_seller_from_listing(offerings0[1]), "Merchant")
     offerings0[0]["Qualifiers"]["FulfillmentChannel"] = {}
     # catch KeyError
     self.assertEqual(papi.get_seller_from_listing(offerings0[0]), None)
     # Test response as a dict
     papi2 = PAPI(deepcopy(TEST_RESPONSE_SM))
     products = papi2.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     seller = papi2.get_seller_from_listing(offerings0[0])
     self.assertEqual(seller, "Amazon")
Exemple #5
0
 def test_products(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     papi.make_products()
     ps = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(ps[0])
     products = papi.products
     lp = products['B00KUP84L2'].lowest_price
     self.assertEqual(lp, 17.99)
Exemple #6
0
 def test_get_seller_from_listing(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(papi.get_seller_from_listing(offerings0[0]), 'Amazon')
     self.assertEqual(papi.get_seller_from_listing(offerings0[1]),
                      'Merchant')
     offerings0[0]['Qualifiers']['FulfillmentChannel'] = {}
     # catch KeyError
     self.assertEqual(papi.get_seller_from_listing(offerings0[0]), None)
     # Test response as a dict
     papi2 = PAPI(deepcopy(TEST_RESPONSE_SM))
     products = papi2.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     seller = papi2.get_seller_from_listing(offerings0[0])
     self.assertEqual(seller, 'Amazon')
Exemple #7
0
 def test_get_price_from_listing(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), 17.99)
     self.assertEqual(papi.get_price_from_listing(offerings0[1]), 21.39)
     offerings0[0]["Price"]["LandedPrice"]["Amount"]["value"] = "$17.99"
     # catch ValueError
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), "$17.99")
     # catch KeyError
     offerings0[0]["Price"] = {}
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), None)
     # Test response as a dict
     papi2 = PAPI(deepcopy(TEST_RESPONSE_SM))
     products = papi2.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     price = papi2.get_price_from_listing(offerings0[0])
     self.assertEqual(price, 15.99)
Exemple #8
0
 def test_get_price_from_listing(self):
     papi = PAPI(deepcopy(TEST_RESPONSE))
     products = papi.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     offerings1 = papi.get_offerings_from_product(products[1])
     offerings2 = papi.get_offerings_from_product(products[2])
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), 17.99)
     self.assertEqual(papi.get_price_from_listing(offerings0[1]), 21.39)
     offerings0[0]['Price']['LandedPrice']['Amount']['value'] = '$17.99'
     # catch ValueError
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), '$17.99')
     # catch KeyError
     offerings0[0]['Price'] = {}
     self.assertEqual(papi.get_price_from_listing(offerings0[0]), None)
     # Test response as a dict
     papi2 = PAPI(deepcopy(TEST_RESPONSE_SM))
     products = papi2.get_products_from_response()
     offerings0 = papi.get_offerings_from_product(products[0])
     price = papi2.get_price_from_listing(offerings0[0])
     self.assertEqual(price, 15.99)