diff options
Diffstat (limited to 'tests/fps/test.py')
-rwxr-xr-x | tests/fps/test.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/fps/test.py b/tests/fps/test.py new file mode 100755 index 00000000..4eba9070 --- /dev/null +++ b/tests/fps/test.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +from unittest import main, skip, skipUnless, TestCase +import uuid +import sys +import os +import os.path + +simple = True +advanced = False +if __name__ == "__main__": + devpath = os.path.relpath(os.path.join('..', '..'), + start=os.path.dirname(__file__)) + sys.path = [devpath] + sys.path + print '>>> advanced FPS tests; using local boto sources' + advanced = True + +from boto.fps.connection import FPSConnection +from boto.fps.response import ComplexAmount + + +class FPSTestCase(TestCase): + + def __init__(self, *args, **kw): + TestCase.__init__(self, *args, **kw) + self.fps = FPSConnection(host='fps.sandbox.amazonaws.com') + if advanced: + self.activity = self.fps.get_account_activity(\ + StartDate='2012-01-01') + result = self.activity.GetAccountActivityResult + self.transactions = result.Transaction + + @skipUnless(simple, "skipping simple test") + def test_get_account_balance(self): + response = self.fps.get_account_balance() + self.assertTrue(hasattr(response, 'GetAccountBalanceResult')) + self.assertTrue(hasattr(response.GetAccountBalanceResult, + 'AccountBalance')) + accountbalance = response.GetAccountBalanceResult.AccountBalance + self.assertTrue(hasattr(accountbalance, 'TotalBalance')) + self.assertIsInstance(accountbalance.TotalBalance, ComplexAmount) + self.assertTrue(hasattr(accountbalance, 'AvailableBalances')) + availablebalances = accountbalance.AvailableBalances + self.assertTrue(hasattr(availablebalances, 'RefundBalance')) + + @skipUnless(simple, "skipping simple test") + def test_complex_amount(self): + response = self.fps.get_account_balance() + accountbalance = response.GetAccountBalanceResult.AccountBalance + asfloat = float(accountbalance.TotalBalance.Value) + self.assertIn('.', str(asfloat)) + + @skipUnless(simple, "skipping simple test") + def test_required_arguments(self): + with self.assertRaises(KeyError): + self.fps.write_off_debt(AdjustmentAmount=123.45) + + @skipUnless(simple, "skipping simple test") + def test_cbui_url(self): + inputs = { + 'transactionAmount': 123.45, + 'pipelineName': 'SingleUse', + 'returnURL': 'https://localhost/', + 'paymentReason': 'a reason for payment', + 'callerReference': 'foo', + } + result = self.fps.cbui_url(**inputs) + print "cbui_url() yields {}".format(result) + + @skipUnless(simple, "skipping simple test") + def test_get_account_activity(self): + response = self.fps.get_account_activity(StartDate='2012-01-01') + self.assertTrue(hasattr(response, 'GetAccountActivityResult')) + result = response.GetAccountActivityResult + self.assertTrue(hasattr(result, 'BatchSize')) + try: + int(result.BatchSize) + except: + self.assertTrue(False) + + @skipUnless(advanced, "skipping advanced test") + def test_get_transaction(self): + assert len(self.transactions) + transactionid = self.transactions[0].TransactionId + result = self.fps.get_transaction(TransactionId=transactionid) + self.assertTrue(hasattr(result.GetTransactionResult, 'Transaction')) + + @skip('cosmetic') + def test_bad_request(self): + try: + self.fps.write_off_debt(CreditInstrumentId='foo', + AdjustmentAmount=123.45) + except Exception, e: + print e + + @skip('cosmetic') + def test_repr(self): + print self.fps.get_account_balance() + + +if __name__ == "__main__": + main() |