def test_transaction(self): transaction = self.transaction serialized_failures = [ transaction_failure_adapter(f, self.dummy_request) for f in transaction.failures ] json_data = transaction_adapter(transaction, self.dummy_request) self.maxDiff = None expected = dict( guid=transaction.guid, transaction_type='debit', submit_status='staged', status=None, amount=transaction.amount, funding_instrument_uri=transaction.funding_instrument_uri, processor_uri=transaction.processor_uri, appears_on_statement_as=transaction.appears_on_statement_as, failure_count=transaction.failure_count, created_at=transaction.created_at.isoformat(), updated_at=transaction.updated_at.isoformat(), invoice_guid=transaction.invoice_guid, failures=serialized_failures, ) self.assertEqual(json_data, expected) def assert_type(transaction_type, expected_type): transaction.transaction_type = transaction_type json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['transaction_type'], expected_type) assert_type(self.transaction_model.types.DEBIT, 'debit') assert_type(self.transaction_model.types.CREDIT, 'credit') assert_type(self.transaction_model.types.REFUND, 'refund') def assert_submit_status(status, expected_status): transaction.submit_status = status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['submit_status'], expected_status) assert_submit_status(self.transaction_model.submit_statuses.STAGED, 'staged') assert_submit_status(self.transaction_model.submit_statuses.RETRYING, 'retrying') assert_submit_status(self.transaction_model.submit_statuses.FAILED, 'failed') assert_submit_status(self.transaction_model.submit_statuses.DONE, 'done') assert_submit_status(self.transaction_model.submit_statuses.CANCELED, 'canceled') def assert_status(status, expected_status): transaction.status = status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['status'], expected_status) assert_status(self.transaction_model.statuses.PENDING, 'pending') assert_status(self.transaction_model.statuses.SUCCEEDED, 'succeeded') assert_status(self.transaction_model.statuses.FAILED, 'failed')
def test_transaction(self): transaction = self.transaction serialized_failures = [ transaction_failure_adapter(f, self.dummy_request) for f in transaction.failures ] json_data = transaction_adapter(transaction, self.dummy_request) self.maxDiff = None expected = dict( guid=transaction.guid, transaction_type='charge', status='init', amount=transaction.amount, funding_instrument_uri=transaction.funding_instrument_uri, processor_uri=transaction.processor_uri, appears_on_statement_as=transaction.appears_on_statement_as, failure_count=transaction.failure_count, created_at=transaction.created_at.isoformat(), updated_at=transaction.updated_at.isoformat(), invoice_guid=transaction.invoice_guid, failures=serialized_failures, ) self.assertEqual(json_data, expected) def assert_type(transaction_type, expected_type): transaction.transaction_type = transaction_type json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['transaction_type'], expected_type) assert_type(self.transaction_model.TYPE_CHARGE, 'charge') assert_type(self.transaction_model.TYPE_PAYOUT, 'payout') assert_type(self.transaction_model.TYPE_REFUND, 'refund') def assert_status(transaction_status, expected_status): transaction.status = transaction_status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['status'], expected_status) assert_status(self.transaction_model.STATUS_INIT, 'init') assert_status(self.transaction_model.STATUS_RETRYING, 'retrying') assert_status(self.transaction_model.STATUS_FAILED, 'failed') assert_status(self.transaction_model.STATUS_DONE, 'done') assert_status(self.transaction_model.STATUS_CANCELED, 'canceled')
def test_transaction(self): from billy.models.transaction import TransactionModel from billy.renderers import transaction_adapter transaction_model = TransactionModel(self.testapp.session) transaction = transaction_model.get(self.transaction_guid) json_data = transaction_adapter(transaction, self.dummy_request) expected = dict( guid=transaction.guid, transaction_type='charge', status='init', amount=transaction.amount, payment_uri=transaction.payment_uri, external_id=transaction.external_id, failure_count=transaction.failure_count, error_message=transaction.error_message, created_at=transaction.created_at.isoformat(), updated_at=transaction.updated_at.isoformat(), scheduled_at=transaction.scheduled_at.isoformat(), subscription_guid=transaction.subscription_guid, ) self.assertEqual(json_data, expected) def assert_type(transaction_type, expected_type): transaction.transaction_type = transaction_type json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['transaction_type'], expected_type) assert_type(TransactionModel.TYPE_CHARGE, 'charge') assert_type(TransactionModel.TYPE_PAYOUT, 'payout') assert_type(TransactionModel.TYPE_REFUND, 'refund') def assert_status(transaction_status, expected_status): transaction.status = transaction_status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['status'], expected_status) assert_status(TransactionModel.STATUS_INIT, 'init') assert_status(TransactionModel.STATUS_RETRYING, 'retrying') assert_status(TransactionModel.STATUS_FAILED, 'failed') assert_status(TransactionModel.STATUS_DONE, 'done') assert_status(TransactionModel.STATUS_CANCELED, 'canceled')
def assert_status(transaction_status, expected_status): transaction.status = transaction_status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['status'], expected_status)
def assert_type(transaction_type, expected_type): transaction.transaction_type = transaction_type json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['transaction_type'], expected_type)
def assert_status(status, expected_status): transaction.status = status json_data = transaction_adapter(transaction, self.dummy_request) self.assertEqual(json_data['status'], expected_status)