Esempio n. 1
0
 def test_invoices(self):
     from seantisinvoice.views.reports import ReportsController
     request = testing.DummyRequest()
     view = ReportsController(None, request)
     self.assertEquals([], view.invoices())
     invoice = self._add_invoice()
     invoice.date = datetime.date(2010, 3, 1)
     self.assertEquals([invoice], view.invoices())
     invoice2 = self._add_invoice()
     invoice2.date = datetime.date(2010, 4, 25)
     view = ReportsController(None, request)
     self.assertEquals([invoice2, invoice], view.invoices())
Esempio n. 2
0
 def test_call(self):
     from seantisinvoice.views.reports import ReportsController
     request = testing.DummyRequest()
     # No invoices yet
     view = ReportsController(None, request)
     result = view()
     self.assertEquals([], result['invoices'])
     # Add an invoice
     invoice = self._add_invoice()
     invoice.tax = 7.6
     invoice.items[0].amount = 10000
     view = ReportsController(None, request)
     result = view()
     self.assertEquals([invoice], result['invoices'])
     self.assertEquals(10760, result['total_amount'])
     self.assertEquals(760, result['total_tax'])
Esempio n. 3
0
 def test_form_fields(self):
     from seantisinvoice.views.reports import ReportsController
     from seantisinvoice.views.reports import ReportsSchema
     request = testing.DummyRequest()
     view = ReportsController(None, request)
     fields = view.form_fields()
     self.assertEquals(ReportsSchema.attrs, fields)
Esempio n. 4
0
 def test_form_defaults(self):
     from seantisinvoice.views.reports import ReportsController
     request = testing.DummyRequest()
     view = ReportsController(None, request)
     defaults = view.form_defaults()
     self.assertEquals(None, defaults['from_date'])
     self.assertEquals(None, defaults['to_date'])
     # Add an invoice
     invoice = self._add_invoice()
     invoice.date = datetime.date(2010, 3, 1)
     view = ReportsController(None, request)
     defaults = view.form_defaults()
     self.assertEquals(datetime.date(2010, 3, 1), defaults['from_date'])
     self.assertEquals(datetime.date(2010, 3, 1), defaults['to_date'])
     # Add a second invoice
     invoice2 = self._add_invoice()
     invoice2.date = datetime.date(2010, 4, 1)
     view = ReportsController(None, request)
     defaults = view.form_defaults()
     self.assertEquals(datetime.date(2010, 3, 1), defaults['from_date'])
     self.assertEquals(datetime.date(2010, 4, 1), defaults['to_date'])
Esempio n. 5
0
 def test_form_widgets(self):
     from seantisinvoice.views.reports import ReportsController
     from formish import DateParts
     request = testing.DummyRequest()
     view = ReportsController(None, request)
     widgets = view.form_widgets(view.form_fields())
     self.assertEquals(DateParts, type(widgets['from_date']))
     self.assertEquals(DateParts, type(widgets['to_date']))
     self.assertEquals([], widgets['customer'].options)
     customer = self._add_customer()
     widgets = view.form_widgets(view.form_fields())
     self.assertEquals([(customer.id, customer.name)],
                       widgets['customer'].options)
Esempio n. 6
0
 def test_handle_submit(self):
     from seantisinvoice.views.reports import ReportsController
     request = testing.DummyRequest()
     view = ReportsController(None, request)
     data = view.form_defaults()
     results = view.handle_submit(data)
     self.assertEquals([], results['invoices'])
     data['from_date'] = datetime.date(2010, 1, 1)
     data['to_date'] = datetime.date(2010, 12, 31)
     results = view.handle_submit(data)
     self.assertEquals([], results['invoices'])
     # Add two invoices
     invoice1 = self._add_invoice()
     invoice1.date = datetime.date(2010, 3, 1)
     invoice2 = self._add_invoice()
     invoice2.date = datetime.date(2010, 4, 25)
     data['from_date'] = datetime.date(2010, 3, 1)
     data['to_date'] = datetime.date(2010, 3, 31)
     results = view.handle_submit(data)
     self.assertEquals([invoice1], results['invoices'])
     data['from_date'] = datetime.date(2010, 3, 1)
     data['to_date'] = datetime.date(2010, 4, 30)
     results = view.handle_submit(data)
     self.assertEquals([invoice2, invoice1], results['invoices'])
     data['from_date'] = datetime.date(2010, 4, 25)
     data['to_date'] = datetime.date(2010, 4, 25)
     results = view.handle_submit(data)
     self.assertEquals([invoice2], results['invoices'])
     data['customer'] = invoice2.contact.customer.id
     results = view.handle_submit(data)
     self.assertEquals([invoice2], results['invoices'])
     # Add a second customer
     customer2 = self._add_customer()
     invoice2.contact = customer2.contacts[0]
     results = view.handle_submit(data)
     self.assertEquals([], results['invoices'])