def test_update_extra_fields(self): sp = spoke.Spoke( Customer=CUSTOMER_NAME, Key=CUSTOMER_KEY, production=False, transport=FauxTransport(), ) self.assertRaises( spoke.ValidationError, sp.update, OrderId=1, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), Extra='foo', )
def test_update_required_fields(self): sp = spoke.Spoke( Customer=CUSTOMER_NAME, Key=CUSTOMER_KEY, production=False, transport=FauxTransport(), ) params = dict( OrderId=1, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), ) for k in params.keys(): copy = params.copy() del copy[k] self.assertRaises(spoke.ValidationError, sp.update, **copy)
def test_constructor_optional_fields(self): spoke.Spoke( Customer=CUSTOMER_NAME, Key=CUSTOMER_KEY, production=False, Logo=spoke.Image( ImageType='jpg', Url='file:///tmp/test.jpg', ), )
def test_new_extra_fields(self): sp = spoke.Spoke( Customer=CUSTOMER_NAME, Key=CUSTOMER_KEY, production=False, transport=FauxTransport(), ) self.assertRaises( spoke.ValidationError, sp.new, Cases=[ dict( CaseId=1234, CaseType='iph4tough', PrintImage=dict( ImageType='jpg', Url='http://threadless.com/nothing.jpg', ), Quantity=1, ) ], OrderId=2, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), ShippingMethod='FirstClass', PackSlip=spoke.Image( ImageType='jpg', Url='file:///tmp/nothing.jpg', ), Comments=[dict( Type='Printer', CommentText='testing', )], Extra='foo', )
def test_conditionally_required_fields(self): sp = spoke.Spoke( Customer=CUSTOMER_NAME, Key=CUSTOMER_KEY, production=False, transport=FauxTransport(), ) params = dict( Cases=[ dict( CaseId=1234, CaseType='iph4tough', PrintImage=dict( ImageType='jpg', Url='http://threadless.com/nothing.jpg', ), Quantity=1, ) ], OrderId=2, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), ShippingAccount='5110896', ShippingMethodId=66, ) for k in params.keys(): copy = params.copy() del copy[k] self.assertRaises(spoke.ValidationError, sp.new, **copy) del params['ShippingAccount'] del params['ShippingMethodId'] self.assertRaises(spoke.ValidationError, sp.new, **params)
import datetime import pprint import spoke CUSTOMER_CODE = ... API_KEY = ... api = spoke.Spoke( production=True, Customer=CUSTOMER_CODE, Key=API_KEY, Logo={ 'ImageType' : 'svg', 'Url' : "https://d1s82l1atzspzx.cloudfront.net/threadless-media/static/imgs/global/threadless-logo.svg", }, ) order_id = 2 shipment_id = 2 shipping_address = { 'FirstName' : 'Mister', 'LastName' : 'Mittens', 'Address1' : '1260 W Madison St', 'City' : 'Chicago', 'State' : 'IL', 'PostalCode' : '60607', 'CountryCode' : 'US',
def test_roundtrip_artist_shop(self): customer = os.getenv('AS_SPOKE_CUSTOMER') key = os.getenv('AS_SPOKE_KEY') sp = spoke.Spoke( Customer=customer, Key=key, production=False, ) order_id = random.randint(1000000, 2000000) result = sp.new( Cases=[ dict( CaseId=1234, CaseType='iph4tough', PrintImage=dict( ImageType='jpg', Url='http://threadless.com/nothing.jpg', ), Quantity=1, ) ], OrderId=order_id, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), ShippingMethodId=66, ShippingAccount='5110896', PackSlip=spoke.Image( ImageType='jpg', Url='file:///tmp/nothing.jpg', ), Comments=[dict( Type='Printer', CommentText='testing', )]) self.assertTrue('immc_id' in result) result = sp.update( OrderId=order_id, OrderInfo=dict( Address1=FAUX_ADDRESS, City=FAUX_CITY, CountryCode='US', FirstName=FAUX_FIRST_NAME, LastName=FAUX_LAST_NAME, OrderDate=datetime.now(), PhoneNumber=FAUXN_NUMBER, PostalCode=FAUX_ZIP, State=FAUX_STATE, ), ) self.assertTrue('immc_id' in result) result = sp.cancel(order_id) self.assertTrue('immc_id' in result)