test Service provider

This commit is contained in:
zhangshine 2015-06-11 21:23:28 +08:00
parent 230452b590
commit c318180f48
3 changed files with 51 additions and 12 deletions

View file

@ -72,7 +72,7 @@ class ServiceProviderInfo(AddressInfo):
:type state: str or unicode or None :type state: str or unicode or None
:type country: str or unicode or None :type country: str or unicode or None
:type post_code: str or unicode or None :type post_code: str or unicode or None
:type vat_tax_number: str or unicode or None :type vat_tax_number: str or unicode or int or None
""" """
super(ServiceProviderInfo, self).__init__(name, street, city, state, country, post_code) super(ServiceProviderInfo, self).__init__(name, street, city, state, country, post_code)
self.vat_tax_number = vat_tax_number self.vat_tax_number = vat_tax_number

View file

@ -109,21 +109,20 @@ class SimpleInvoice(SimpleDocTemplate):
self._story.append(SimpleTable(invoice_info_data, horizontal_align='RIGHT')) self._story.append(SimpleTable(invoice_info_data, horizontal_align='RIGHT'))
def _service_provider_data(self): def _service_provider_data(self):
if isinstance(self.service_provider_info, ServiceProviderInfo):
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'), props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
('country', 'Country'), ('post_code', 'Post code'), ('vat_tax_number', 'Vat/Tax number')] ('country', 'Country'), ('post_code', 'Post code'), ('vat_tax_number', 'Vat/Tax number')]
return self._attribute_to_table_data(self.service_provider_info, props) return self._attribute_to_table_data(self.service_provider_info, props)
return []
def _build_service_provider_info(self): def _build_service_provider_info(self):
# Merchant # Merchant
if isinstance(self.service_provider_info, ServiceProviderInfo): service_provider_info_data = self._service_provider_data()
self._story.append( if service_provider_info_data:
Paragraph('Merchant', self._defined_styles.get('RightHeading1')) self._story.append(Paragraph('Merchant', self._defined_styles.get('RightHeading1')))
) self._story.append(SimpleTable(service_provider_info_data, horizontal_align='RIGHT'))
self._story.append(
SimpleTable(self._service_provider_data(), horizontal_align='RIGHT')
)
def _client_info_data(self): def _client_info_data(self):
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'), props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),

View file

@ -171,3 +171,43 @@ class TestSimpleInvoice(unittest.TestCase):
invoice.finish() invoice.finish()
self.assertTrue(os.path.exists(invoice_path)) self.assertTrue(os.path.exists(invoice_path))
def test_service_provider_info(self):
invoice_path = os.path.join(self.file_base_dir, 'service_provider_info.pdf')
if os.path.exists(invoice_path):
os.remove(invoice_path)
invoice = SimpleInvoice(invoice_path)
# Before add service provider info
info_data = invoice._service_provider_data()
self.assertEqual(info_data, [])
# Empty info
invoice.service_provider_info = ServiceProviderInfo()
info_data = invoice._service_provider_data()
self.assertEqual(info_data, [])
invoice.service_provider_info = ServiceProviderInfo(
name='CiCiApp',
street='Street xxx',
city='City ccc',
state='State sss',
country='Country rrr',
post_code='Post code ppp',
vat_tax_number=666
)
# After add service provider info
info_data = invoice._service_provider_data()
self.assertEqual(len(info_data), 7)
self.assertEqual(info_data[0][0], 'Name:')
self.assertEqual(info_data[0][1], 'CiCiApp')
self.assertEqual(info_data[4][0], 'Country:')
self.assertEqual(info_data[4][1], 'Country rrr')
self.assertEqual(info_data[6][0], 'Vat/Tax number:')
self.assertEqual(info_data[6][1], 666)
invoice.finish()
self.assertTrue(os.path.exists(invoice_path))