def test_transaction(self): logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed logger = logging.getLogger('recurly.http.request') logger.setLevel(logging.DEBUG) account_code = 'transaction%s' % self.test_id log_content = StringIO() log_handler = logging.StreamHandler(log_content) logger.addHandler(log_handler) transaction = Transaction(amount_in_cents=1000, currency='USD', account=Account( account_code=account_code, billing_info=BillingInfo( first_name='Verena', last_name='Example', number='4111-1111-1111-1111', year='2014', address1='123 Main St', city='San Francisco', state='CA', zip='94105', country='US', month='7', verification_value='7777', ), )) with self.mock_request('transaction/created.xml'): transaction.save() logger.removeHandler(log_handler) try: transaction.get_refund_transaction() except ValueError: pass else: self.fail( "Transaction with no refund transaction did not raise a ValueError from get_refund_transaction()" ) with self.mock_request('transaction/account-exists.xml'): account = Account.get(account_code) try: log_content = log_content.getvalue() self.assertTrue('<transaction' in log_content) self.assertTrue('<billing_info' in log_content) # See if we redacted our sensitive fields properly. self.assertTrue('4111' not in log_content) self.assertTrue('7777' not in log_content) with self.mock_request('transaction/refunded.xml'): refunded_transaction = transaction.refund() transaction_2 = Transaction( amount_in_cents=1000, currency='USD', account=Account(account_code=account_code), ) with self.mock_request('transaction/created-again.xml'): transaction_2.save() self.assertNotEqual(transaction_2.uuid, transaction.uuid) self.assertTrue(transaction_2.refundable) with self.mock_request('transaction/partial-refunded.xml'): refunded_transaction = transaction_2.refund( amount_in_cents=700) self.assertTrue(refunded_transaction is transaction_2) self.assertTrue(hasattr(transaction_2, 'get_refund_transaction')) with self.mock_request( 'transaction/partial-refunded-transaction.xml'): refund_transaction = transaction_2.get_refund_transaction() self.assertTrue(isinstance(refund_transaction, Transaction)) self.assertTrue(not refund_transaction.refundable) self.assertNotEqual(refund_transaction.uuid, transaction_2.uuid) finally: with self.mock_request('transaction/account-deleted.xml'): account.delete()
def test_transaction(self): logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed logger = logging.getLogger('recurly.http.request') logger.setLevel(logging.DEBUG) account_code = 'transaction%s' % self.test_id log_content = StringIO() log_handler = logging.StreamHandler(log_content) logger.addHandler(log_handler) transaction = Transaction( amount_in_cents=1000, currency='USD', account=Account( account_code=account_code, billing_info=BillingInfo( first_name='Verena', last_name='Example', number='4111-1111-1111-1111', year='2014', address1='123 Main St', city='San Francisco', state='CA', zip='94105', country='US', month='7', verification_value='7777', ), ) ) with self.mock_request('transaction/created.xml'): transaction.save() logger.removeHandler(log_handler) try: transaction.get_refund_transaction() except ValueError: pass else: self.fail("Transaction with no refund transaction did not raise a ValueError from get_refund_transaction()") with self.mock_request('transaction/account-exists.xml'): account = Account.get(account_code) try: log_content = log_content.getvalue() self.assertTrue('<transaction' in log_content) self.assertTrue('<billing_info' in log_content) # See if we redacted our sensitive fields properly. self.assertTrue('4111' not in log_content) self.assertTrue('7777' not in log_content) with self.mock_request('transaction/refunded.xml'): refunded_transaction = transaction.refund() transaction_2 = Transaction( amount_in_cents=1000, currency='USD', account=Account(account_code=account_code), ) with self.mock_request('transaction/created-again.xml'): transaction_2.save() self.assertNotEqual(transaction_2.uuid, transaction.uuid) self.assertTrue(transaction_2.refundable) with self.mock_request('transaction/partial-refunded.xml'): refunded_transaction = transaction_2.refund(amount_in_cents=700) self.assertTrue(refunded_transaction is transaction_2) self.assertTrue(hasattr(transaction_2, 'get_refund_transaction')) with self.mock_request('transaction/partial-refunded-transaction.xml'): refund_transaction = transaction_2.get_refund_transaction() self.assertTrue(isinstance(refund_transaction, Transaction)) self.assertTrue(not refund_transaction.refundable) self.assertNotEqual(refund_transaction.uuid, transaction_2.uuid) finally: with self.mock_request('transaction/account-deleted.xml'): account.delete()
def test_transaction(self): logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed logger = logging.getLogger("recurly.http.request") logger.setLevel(logging.DEBUG) account_code = "transaction%s" % self.test_id log_content = StringIO() log_handler = logging.StreamHandler(log_content) logger.addHandler(log_handler) transaction = Transaction( amount_in_cents=1000, currency="USD", account=Account( account_code=account_code, billing_info=BillingInfo( first_name="Verena", last_name="Example", number="4111-1111-1111-1111", year="2014", address1="123 Main St", city="San Francisco", state="CA", zip="94105", country="US", month="7", verification_value="7777", ), ), ) with self.mock_request("transaction/created.xml"): transaction.save() logger.removeHandler(log_handler) try: transaction.get_refund_transaction() except ValueError: pass else: self.fail("Transaction with no refund transaction did not raise a ValueError from get_refund_transaction()") with self.mock_request("transaction/account-exists.xml"): account = Account.get(account_code) try: log_content = log_content.getvalue() self.assertTrue("<transaction" in log_content) self.assertTrue("<billing_info" in log_content) # See if we redacted our sensitive fields properly. self.assertTrue("4111" not in log_content) self.assertTrue("7777" not in log_content) with self.mock_request("transaction/refunded.xml"): refunded_transaction = transaction.refund() transaction_2 = Transaction( amount_in_cents=1000, currency="USD", account=Account(account_code=account_code) ) with self.mock_request("transaction/created-again.xml"): transaction_2.save() self.assertNotEqual(transaction_2.uuid, transaction.uuid) self.assertTrue(transaction_2.refundable) with self.mock_request("transaction/partial-refunded.xml"): refunded_transaction = transaction_2.refund(amount_in_cents=700) self.assertTrue(refunded_transaction is transaction_2) self.assertTrue(hasattr(transaction_2, "get_refund_transaction")) with self.mock_request("transaction/partial-refunded-transaction.xml"): refund_transaction = transaction_2.get_refund_transaction() self.assertTrue(isinstance(refund_transaction, Transaction)) self.assertTrue(not refund_transaction.refundable) self.assertNotEqual(refund_transaction.uuid, transaction_2.uuid) finally: with self.mock_request("transaction/account-deleted.xml"): account.delete()