- Timestamp:
- 03/24/08 23:13:54 (4 years ago)
- Location:
- trunk/fpys
- Files:
-
- 3 modified
-
client.py (modified) (3 diffs)
-
tests/client_test.py (modified) (1 diff)
-
tests/wsgi_responder.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fpys/client.py
r27 r34 1 import base64, hmac, sha 1 import base64 2 import hmac 3 import sha 2 4 import urllib, urllib2 3 5 import logging 4 6 import time 7 from datetime import datetime, tzinfo 5 8 6 9 try: … … 19 22 return 1 20 23 return 0 24 25 class Token(object): 26 def __init__(self, document=None): 27 if document is not None: 28 document = ET.ElementTree(document) 29 self.document = document 30 31 for name in ['TokenId', 'FriendlyName', 'Status', 32 'DateInstalled', 'CallerInstalled', 33 'CallerReference', 'TokenType', 34 'OldTokenId']: 35 if document.find(name) is not None: 36 attr_name = name[0].lower() + name[1:] 37 setattr(self, attr_name, document.find(name).text) 38 39 if hasattr(self, 'dateInstalled'): 40 # TODO this is a little less than ideal 41 # we truncate the milliseconds and time zone info 42 di = self.dateInstalled 43 di = di[0:di.find(".")] 44 self.dateInstalled = datetime.strptime(di, 45 "%Y-%m-%dT%H:%M:%S") 21 46 22 47 class FPSResponse(object): … … 51 76 52 77 53 for name in ['CallerTokenId', 'SenderTokenId', 'RecipientTokenId', 'TokenId']: 78 for name in ['CallerTokenId', 'SenderTokenId', 'RecipientTokenId', 'TokenId', 79 'PaymentInstruction', 'AccountId', 'TokenFriendlyName']: 54 80 if document.find(name) is not None: 55 81 attr_name = name[0].lower() + name[1:] 56 82 setattr(self, attr_name, document.find(name).text) 83 84 if document.find("Token"): 85 self.token = Token(document.find("Token")) 57 86 58 87 if document.find("AccountBalance"): -
trunk/fpys/tests/client_test.py
r33 r34 106 106 assert response.errors[0]['errorCode'] == "InvalidParams" 107 107 108 def test_getPaymentInstruction(): 109 """Retrive an existing payment instruciton""" 110 response = fps_client.getPaymentInstruction("ZS4X8G44GEIVGVSEN2DI5NDO6Q2WX3JQ9125FNR8IBLF5CFH8ZMT3RLNBJUJH9MN") 111 assert response.success == True 112 assert response.token is not None 113 assert response.token.status == 'Active' 114 assert response.token.tokenType == 'Unrestricted' 115 assert response.paymentInstruction.startswith("MyRole =") 116 108 117 def test_getTokenUsageInvalid(): 109 118 """Retrieve token usage for a SingleUse token""" -
trunk/fpys/tests/wsgi_responder.py
r33 r34 43 43 return [response] 44 44 45 def GetPaymentInstruction(self, environ): 46 response = """<ns0:GetPaymentInstructionResponse xmlns:ns0="http://fps.amazonaws.com/doc/2007-01-08/"><Token><TokenId>ZS4X8G44GEIVGVSEN2DI5NDO6Q2WX3JQ9125FNR8IBLF5CFH8ZMT3RLNBJUJH9MN</TokenId><FriendlyName>fpes.achievewith.us_caller4685bc1eef1311dc952e00142241a3a2</FriendlyName><Status>Active</Status><DateInstalled>2008-03-10T19:31:48.000-07:00</DateInstalled><CallerInstalled>JMXHWUQJONDR53DM28EHVCGFILGI4RGNX541Z9</CallerInstalled><CallerReference>fpes.achievewith.us_caller4685bc1eef1311dc952e00142241a3a2</CallerReference><TokenType>Unrestricted</TokenType><OldTokenId>ZS4X8G44GEIVGVSEN2DI5NDO6Q2WX3JQ9125FNR8IBLF5CFH8ZMT3RLNBJUJH9MN</OldTokenId></Token><PaymentInstruction>MyRole == \'Caller\';</PaymentInstruction><AccountId>JMXHWUQJONDR53DM28EHVCGFILGI4RGNX541Z9</AccountId><TokenFriendlyName>fpes.achievewith.us_caller4685bc1eef1311dc952e00142241a3a2</TokenFriendlyName><Status>Success</Status><RequestId>29a86313-d869-4c94-b5b6-570e95254f10:0</RequestId></ns0:GetPaymentInstructionResponse>""" 47 return [response] 48 45 49 def InstallPaymentInstruction(self, environ): 46 50 if environ['fps.params']['PaymentInstruction'][0].find("Invalid") != -1:
