Changeset 34 for trunk

Show
Ignore:
Timestamp:
03/24/08 23:13:54 (4 years ago)
Author:
tim
Message:

Add support for getPaymentInstruction

Location:
trunk/fpys
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/fpys/client.py

    r27 r34  
    1 import base64, hmac, sha 
     1import base64 
     2import hmac 
     3import sha 
    24import urllib, urllib2 
    35import logging 
    46import time 
     7from datetime import datetime, tzinfo 
    58 
    69try: 
     
    1922        return 1 
    2023    return 0 
     24 
     25class 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") 
    2146 
    2247class FPSResponse(object): 
     
    5176 
    5277 
    53         for name in ['CallerTokenId', 'SenderTokenId', 'RecipientTokenId', 'TokenId']: 
     78        for name in ['CallerTokenId', 'SenderTokenId', 'RecipientTokenId', 'TokenId', 
     79                     'PaymentInstruction', 'AccountId', 'TokenFriendlyName']: 
    5480            if document.find(name) is not None: 
    5581                attr_name = name[0].lower() + name[1:] 
    5682                setattr(self, attr_name, document.find(name).text) 
     83 
     84        if document.find("Token"): 
     85            self.token = Token(document.find("Token")) 
    5786 
    5887        if document.find("AccountBalance"): 
  • trunk/fpys/tests/client_test.py

    r33 r34  
    106106    assert response.errors[0]['errorCode'] == "InvalidParams" 
    107107 
     108def 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 
    108117def test_getTokenUsageInvalid(): 
    109118    """Retrieve token usage for a SingleUse token""" 
  • trunk/fpys/tests/wsgi_responder.py

    r33 r34  
    4343        return [response] 
    4444 
     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 
    4549    def InstallPaymentInstruction(self, environ): 
    4650        if environ['fps.params']['PaymentInstruction'][0].find("Invalid") != -1: