1#!/usr/bin/env python 2from __future__ import print_function 3import sys 4import os 5import os.path 6from datetime import datetime, timedelta 7 8 9simple = os.environ.get('MWS_MERCHANT', None) 10if not simple: 11 print(""" 12 Please set the MWS_MERCHANT environmental variable 13 to your Merchant or SellerId to enable MWS tests. 14 """) 15 16 17advanced = False 18isolator = True 19if __name__ == "__main__": 20 devpath = os.path.relpath(os.path.join('..', '..', '..'), 21 start=os.path.dirname(__file__)) 22 sys.path = [devpath] + sys.path 23 advanced = simple and True or False 24 if advanced: 25 print('>>> advanced MWS tests; using local boto sources') 26 27from boto.mws.connection import MWSConnection 28from tests.compat import unittest 29 30 31class MWSTestCase(unittest.TestCase): 32 33 def setUp(self): 34 self.mws = MWSConnection(Merchant=simple, debug=0) 35 36 @unittest.skipUnless(simple and isolator, "skipping simple test") 37 def test_feedlist(self): 38 self.mws.get_feed_submission_list() 39 40 @unittest.skipUnless(simple and isolator, "skipping simple test") 41 def test_inbound_status(self): 42 response = self.mws.get_inbound_service_status() 43 status = response.GetServiceStatusResult.Status 44 self.assertIn(status, ('GREEN', 'GREEN_I', 'YELLOW', 'RED')) 45 46 @property 47 def marketplace(self): 48 try: 49 return self._marketplace 50 except AttributeError: 51 response = self.mws.list_marketplace_participations() 52 result = response.ListMarketplaceParticipationsResult 53 self._marketplace = result.ListMarketplaces.Marketplace[0] 54 return self.marketplace 55 56 @property 57 def marketplace_id(self): 58 return self.marketplace.MarketplaceId 59 60 @unittest.skipUnless(simple and isolator, "skipping simple test") 61 def test_marketplace_participations(self): 62 response = self.mws.list_marketplace_participations() 63 result = response.ListMarketplaceParticipationsResult 64 self.assertTrue(result.ListMarketplaces.Marketplace[0].MarketplaceId) 65 66 @unittest.skipUnless(simple and isolator, "skipping simple test") 67 def test_get_product_categories_for_asin(self): 68 asin = '144930544X' 69 response = self.mws.get_product_categories_for_asin( 70 MarketplaceId=self.marketplace_id, 71 ASIN=asin) 72 self.assertEqual(len(response._result.Self), 3) 73 categoryids = [x.ProductCategoryId for x in response._result.Self] 74 self.assertSequenceEqual(categoryids, ['285856', '21', '491314']) 75 76 @unittest.skipUnless(simple and isolator, "skipping simple test") 77 def test_list_matching_products(self): 78 response = self.mws.list_matching_products( 79 MarketplaceId=self.marketplace_id, 80 Query='boto') 81 products = response._result.Products 82 self.assertTrue(len(products)) 83 84 @unittest.skipUnless(simple and isolator, "skipping simple test") 85 def test_get_matching_product(self): 86 asin = 'B001UDRNHO' 87 response = self.mws.get_matching_product( 88 MarketplaceId=self.marketplace_id, 89 ASINList=[asin]) 90 attributes = response._result[0].Product.AttributeSets.ItemAttributes 91 self.assertEqual(attributes[0].Label, 'Serengeti') 92 93 @unittest.skipUnless(simple and isolator, "skipping simple test") 94 def test_get_matching_product_for_id(self): 95 asins = ['B001UDRNHO', '144930544X'] 96 response = self.mws.get_matching_product_for_id( 97 MarketplaceId=self.marketplace_id, 98 IdType='ASIN', 99 IdList=asins) 100 self.assertEqual(len(response._result), 2) 101 for result in response._result: 102 self.assertEqual(len(result.Products.Product), 1) 103 104 @unittest.skipUnless(simple and isolator, "skipping simple test") 105 def test_get_lowest_offer_listings_for_asin(self): 106 asin = '144930544X' 107 response = self.mws.get_lowest_offer_listings_for_asin( 108 MarketplaceId=self.marketplace_id, 109 ItemCondition='New', 110 ASINList=[asin]) 111 listings = response._result[0].Product.LowestOfferListings 112 self.assertTrue(len(listings.LowestOfferListing)) 113 114 @unittest.skipUnless(simple and isolator, "skipping simple test") 115 def test_list_inventory_supply(self): 116 asof = (datetime.today() - timedelta(days=30)).isoformat() 117 response = self.mws.list_inventory_supply(QueryStartDateTime=asof, 118 ResponseGroup='Basic') 119 self.assertTrue(hasattr(response._result, 'InventorySupplyList')) 120 121if __name__ == "__main__": 122 unittest.main() 123