OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 from tests.unit import unittest |
| 4 import sys |
| 5 import os |
| 6 import os.path |
| 7 |
| 8 simple = True |
| 9 advanced = False |
| 10 if __name__ == "__main__": |
| 11 devpath = os.path.relpath(os.path.join('..', '..'), |
| 12 start=os.path.dirname(__file__)) |
| 13 sys.path = [devpath] + sys.path |
| 14 print '>>> advanced FPS tests; using local boto sources' |
| 15 advanced = True |
| 16 |
| 17 from boto.fps.connection import FPSConnection |
| 18 from boto.fps.response import ComplexAmount |
| 19 |
| 20 |
| 21 class FPSTestCase(unittest.TestCase): |
| 22 |
| 23 def setUp(self): |
| 24 self.fps = FPSConnection(host='fps.sandbox.amazonaws.com') |
| 25 if advanced: |
| 26 self.activity = self.fps.get_account_activity(\ |
| 27 StartDate='2012-01-01') |
| 28 result = self.activity.GetAccountActivityResult |
| 29 self.transactions = result.Transaction |
| 30 |
| 31 @unittest.skipUnless(simple, "skipping simple test") |
| 32 def test_get_account_balance(self): |
| 33 response = self.fps.get_account_balance() |
| 34 self.assertTrue(hasattr(response, 'GetAccountBalanceResult')) |
| 35 self.assertTrue(hasattr(response.GetAccountBalanceResult, |
| 36 'AccountBalance')) |
| 37 accountbalance = response.GetAccountBalanceResult.AccountBalance |
| 38 self.assertTrue(hasattr(accountbalance, 'TotalBalance')) |
| 39 self.assertIsInstance(accountbalance.TotalBalance, ComplexAmount) |
| 40 self.assertTrue(hasattr(accountbalance, 'AvailableBalances')) |
| 41 availablebalances = accountbalance.AvailableBalances |
| 42 self.assertTrue(hasattr(availablebalances, 'RefundBalance')) |
| 43 |
| 44 @unittest.skipUnless(simple, "skipping simple test") |
| 45 def test_complex_amount(self): |
| 46 response = self.fps.get_account_balance() |
| 47 accountbalance = response.GetAccountBalanceResult.AccountBalance |
| 48 asfloat = float(accountbalance.TotalBalance.Value) |
| 49 self.assertIn('.', str(asfloat)) |
| 50 |
| 51 @unittest.skipUnless(simple, "skipping simple test") |
| 52 def test_required_arguments(self): |
| 53 with self.assertRaises(KeyError): |
| 54 self.fps.write_off_debt(AdjustmentAmount=123.45) |
| 55 |
| 56 @unittest.skipUnless(simple, "skipping simple test") |
| 57 def test_cbui_url(self): |
| 58 inputs = { |
| 59 'transactionAmount': 123.45, |
| 60 'pipelineName': 'SingleUse', |
| 61 'returnURL': 'https://localhost/', |
| 62 'paymentReason': 'a reason for payment', |
| 63 'callerReference': 'foo', |
| 64 } |
| 65 result = self.fps.cbui_url(**inputs) |
| 66 print "cbui_url() yields {0}".format(result) |
| 67 |
| 68 @unittest.skipUnless(simple, "skipping simple test") |
| 69 def test_get_account_activity(self): |
| 70 response = self.fps.get_account_activity(StartDate='2012-01-01') |
| 71 self.assertTrue(hasattr(response, 'GetAccountActivityResult')) |
| 72 result = response.GetAccountActivityResult |
| 73 self.assertTrue(hasattr(result, 'BatchSize')) |
| 74 try: |
| 75 int(result.BatchSize) |
| 76 except: |
| 77 self.assertTrue(False) |
| 78 |
| 79 @unittest.skipUnless(advanced, "skipping advanced test") |
| 80 def test_get_transaction(self): |
| 81 assert len(self.transactions) |
| 82 transactionid = self.transactions[0].TransactionId |
| 83 result = self.fps.get_transaction(TransactionId=transactionid) |
| 84 self.assertTrue(hasattr(result.GetTransactionResult, 'Transaction')) |
| 85 |
| 86 @unittest.skip('cosmetic') |
| 87 def test_bad_request(self): |
| 88 try: |
| 89 self.fps.write_off_debt(CreditInstrumentId='foo', |
| 90 AdjustmentAmount=123.45) |
| 91 except Exception, e: |
| 92 print e |
| 93 |
| 94 @unittest.skip('cosmetic') |
| 95 def test_repr(self): |
| 96 print self.fps.get_account_balance() |
| 97 |
| 98 |
| 99 if __name__ == "__main__": |
| 100 unittest.main() |
OLD | NEW |