Changeset 35 for trunk

Show
Ignore:
Timestamp:
03/25/08 01:11:34 (4 years ago)
Author:
tim
Message:

Parsing Pay responses, with a simple test

Location:
trunk/fpys
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/fpys/client.py

    r34 r35  
    4545                                                   "%Y-%m-%dT%H:%M:%S") 
    4646 
     47class TransactionResponse(object): 
     48    def __init__(self, id=None, status=None): 
     49        self.id = id 
     50        self.status = status 
     51 
    4752class FPSResponse(object): 
    4853    def __init__(self, document=None): 
    4954        if document is not None: 
    5055            document = ET.ElementTree(document) 
     56            log.debug(ET.tostring(document.getroot())) 
    5157        self.document = document 
    5258 
     
    9197                self.balances[bal] = (float(document.find("//" + bal).find("Amount").text), 
    9298                                      document.find("//" + bal).find("CurrencyCode").text) 
     99 
     100        if document.getroot().tag.find("PayResponse") >= 0: 
     101            self.transaction = TransactionResponse() 
     102            self.transaction.id = document.find("//TransactionId").text 
     103            self.transaction.status = document.find("//Status").text 
    93104             
    94105 
     
    195206            data = httperror.read() 
    196207            httperror.close() 
    197         log.debug("returned_data == %s" % data) 
    198208 
    199209        return FPSResponse(ET.fromstring(data)) 
  • trunk/fpys/tests/client_test.py

    r34 r35  
    132132    pass 
    133133 
     134def test_pay(): 
     135    """Initiates a payment""" 
     136    response = fps_client.pay(caller_token="Z34XMGF4GCILGV7EV2D45DDO4Q6WXEJZ9175UNR5I9LFEC1H8MMX3R6NBJUJH8MQ", 
     137                              sender_token="2646ZQ3Z19JBRPIBXCM97QRHKT6APPGB2VE9ATJD48N7CF1LXNEZ3YFHBDBPXFGM", 
     138                              recipient_token="Z44X4G84G1ILGV4ER2DQ5HDO3Q2WXBJS91C5QNREICLF3CZH8SMA3RXN1JUDH9MC", 
     139                              amount=2.0, 
     140                              caller_reference="FPeS Invoice 37") 
     141    assert response.success == True 
     142    assert response.transaction.id == "133I77HJS56JVM7M54OZIRITRVLUT5F227U" 
     143    assert response.transaction.status == "Initiated" 
  • trunk/fpys/tests/wsgi_responder.py

    r34 r35  
    5757        return [response] 
    5858 
     59    def Pay(self, environ): 
     60        response = """<ns0:PayResponse xmlns:ns0="http://fps.amazonaws.com/doc/2007-01-08/"><ns0:TransactionResponse><TransactionId>133I77HJS56JVM7M54OZIRITRVLUT5F227U</TransactionId><Status>Initiated</Status></ns0:TransactionResponse><Status>Success</Status><RequestId>99a81daa-1a13-46eb-872e-98c61bde612e:0</RequestId></ns0:PayResponse>""" 
     61        return [response] 
    5962 
    6063flexible_payment_service = FlexiblePaymentService()