test transactions

This commit is contained in:
zhangshine 2015-06-11 22:17:42 +08:00
parent 6dccb3927a
commit 2919442e7d
3 changed files with 37 additions and 7 deletions

View file

@ -139,7 +139,7 @@ class Transaction(object):
:param transaction_datetime:
:type transaction_datetime: date or datetime or str or unicode
:param amount: $$
:type amount: int or str or unicode
:type amount: int or float or str or unicode
:return:
"""
self.gateway = gateway

View file

@ -249,8 +249,7 @@ class SimpleInvoice(SimpleDocTemplate):
if item_data:
self._story.append(TableWithHeader(item_data, horizontal_align='LEFT', style=style))
def _build_transactions(self):
# Transaction
def _transactions_data(self):
transaction_table_data = [
(
t.transaction_id,
@ -261,10 +260,16 @@ class SimpleInvoice(SimpleDocTemplate):
]
if transaction_table_data:
self._story.append(
Paragraph('Transaction', self._defined_styles.get('Heading1'))
)
transaction_table_data.insert(0, ('Transaction id', 'Gateway', 'Transaction date', 'Amount'))
return transaction_table_data
def _build_transactions(self):
# Transaction
transaction_table_data = self._transactions_data()
if transaction_table_data:
self._story.append(Paragraph('Transaction', self._defined_styles.get('Heading1')))
self._story.append(TableWithHeader(transaction_table_data, horizontal_align='LEFT'))
def _build_bottom_tip(self):

View file

@ -251,4 +251,29 @@ class TestSimpleInvoice(unittest.TestCase):
invoice.finish()
self.assertTrue(os.path.exists(invoice_path))
self.assertTrue(os.path.exists(invoice_path))
def test_transaction(self):
invoice_path = os.path.join(self.file_base_dir, 'transaction.pdf')
if os.path.exists(invoice_path):
os.remove(invoice_path)
invoice = SimpleInvoice(invoice_path)
transaction_data = invoice._transactions_data()
self.assertEqual(transaction_data, [])
invoice.add_transaction(Transaction('A', 1, date.today(), 9.9))
invoice.add_transaction(Transaction('B', 3, date(2015, 6, 1), 3.3))
transaction_data = invoice._transactions_data()
self.assertEqual(len(transaction_data), 3)
self.assertEqual(transaction_data[0][0], 'Transaction id')
self.assertEqual(transaction_data[1][3], 9.9)
self.assertEqual(transaction_data[2][0], 3)
self.assertEqual(transaction_data[2][2], '2015-06-01')
self.assertEqual(transaction_data[2][3], 3.3)
invoice.finish()
self.assertTrue(os.path.exists(invoice_path))