Ejemplo n.º 1
0
 def test_handle_add(self):
     from seantisinvoice.models import Invoice
     from seantisinvoice.models import DBSession
     from seantisinvoice.views.invoice import InvoiceController
     # Register route for redirect in invoice form actions
     testing.registerRoute('/', 'invoices', factory=None)
     # Each invoice belongs to a customer, thus add one.
     customer = self._add_customer()
     request = testing.DummyRequest()
     view = InvoiceController(None, request)
     data = view.form_defaults()
     data['customer_contact_id'] = customer.contacts[0].id
     data['project_description'] = u'Project name'
     data['recurring_term'] = 30
     data['date'] = datetime.date(2010, 1, 18)
     data['item_list'] = [
         dict(item_id='',
              service_title=u'Testing',
              service_description=u'Work',
              amount=2000.0)
     ]
     view.handle_add(data)
     session = DBSession()
     invoice = session.query(Invoice).one()
     self.assertEquals(u'Project name', invoice.project_description)
     self.assertEquals(customer.contacts[0], invoice.contact)
     self.assertEquals(1, len(invoice.items))
     self.assertEquals(u'Testing', invoice.items[0].service_title)
Ejemplo n.º 2
0
 def test_form_fields(self):
     from seantisinvoice.views.invoice import InvoiceController
     from seantisinvoice.views.invoice import InvoiceSchema
     request = testing.DummyRequest()
     view = InvoiceController(None, request)
     fields = view.form_fields()
     self.assertEquals(InvoiceSchema.attrs, fields)
Ejemplo n.º 3
0
    def test_form_fields(self):
        from seantisinvoice.views.invoice import InvoiceController
        from seantisinvoice.views.invoice import InvoiceSchema

        request = testing.DummyRequest()
        view = InvoiceController(None, request)
        fields = view.form_fields()
        self.assertEquals(InvoiceSchema.attrs, fields)
Ejemplo n.º 4
0
 def test_form_widgets(self):
     from seantisinvoice.views.invoice import InvoiceController
     customer = self._add_customer()
     contact = customer.contacts[0]
     request = testing.DummyRequest()
     view = InvoiceController(None, request)
     widgets = view.form_widgets(view.form_fields())
     option = (customer.id, u'%s: %s %s' %
               (customer.name, contact.first_name, contact.last_name))
     self.failUnless(option in widgets['customer_contact_id'].options)
Ejemplo n.º 5
0
    def test_form_widgets(self):
        from seantisinvoice.views.invoice import InvoiceController

        customer = self._add_customer()
        contact = customer.contacts[0]
        request = testing.DummyRequest()
        view = InvoiceController(None, request)
        widgets = view.form_widgets(view.form_fields())
        option = (customer.id, u"%s: %s %s" % (customer.name, contact.first_name, contact.last_name))
        self.failUnless(option in widgets["customer_contact_id"].options)
Ejemplo n.º 6
0
 def test_handle_cancel(self):
     from seantisinvoice.views.invoice import InvoiceController
     from seantisinvoice import statusmessage
     # Register route for redirect in customer form actions
     testing.registerRoute('/', 'invoices', factory=None)
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     view = InvoiceController(None, request)
     view.handle_cancel()
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
Ejemplo n.º 7
0
    def test_handle_cancel(self):
        from seantisinvoice.views.invoice import InvoiceController
        from seantisinvoice import statusmessage

        # Register route for redirect in customer form actions
        testing.registerRoute("/", "invoices", factory=None)
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        view = InvoiceController(None, request)
        view.handle_cancel()
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
Ejemplo n.º 8
0
 def test_call(self):
     from seantisinvoice.views.invoice import InvoiceController
     request = testing.DummyRequest()
     # No invoice with this id
     request.matchdict = dict(invoice='1')
     view = InvoiceController(None, request)
     result = view()
     self.assertEquals(404, result.status_int)
     # Add an invoice
     invoice = self._add_invoice()
     request.matchdict = dict(invoice=str(invoice.id))
     view = InvoiceController(None, request)
     result = view()
     self.failUnless('main' in result.keys())
Ejemplo n.º 9
0
    def test_handle_add(self):
        from seantisinvoice.models import Invoice
        from seantisinvoice.models import DBSession
        from seantisinvoice.views.invoice import InvoiceController

        # Register route for redirect in invoice form actions
        testing.registerRoute("/", "invoices", factory=None)
        # Each invoice belongs to a customer, thus add one.
        customer = self._add_customer()
        request = testing.DummyRequest()
        view = InvoiceController(None, request)
        data = view.form_defaults()
        data["customer_contact_id"] = customer.contacts[0].id
        data["project_description"] = u"Project name"
        data["recurring_term"] = 30
        data["date"] = datetime.date(2010, 1, 18)
        data["item_list"] = [dict(item_id="", service_title=u"Testing", service_description=u"Work", amount=2000.0)]
        view.handle_add(data)
        session = DBSession()
        invoice = session.query(Invoice).one()
        self.assertEquals(u"Project name", invoice.project_description)
        self.assertEquals(customer.contacts[0], invoice.contact)
        self.assertEquals(1, len(invoice.items))
        self.assertEquals(u"Testing", invoice.items[0].service_title)
Ejemplo n.º 10
0
 def test_handle_submit(self):
     from seantisinvoice.views.invoice import InvoiceController
     from seantisinvoice import statusmessage
     # Register route for redirect in invoice form actions
     testing.registerRoute('/', 'invoices', factory=None)
     # Create an invoice
     invoice = self._add_invoice()
     request = testing.DummyRequest()
     request.matchdict = dict(invoice=str(invoice.id))
     view = InvoiceController(None, request)
     data = view.form_defaults()
     self.assertEquals(u'Project', data['project_description'])
     # Change some of the invoice date
     data['project_description'] = u'My project'
     data['recurring_term'] = 30
     data['item_list'][0]['service_title'] = u'My service'
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'My project', data['project_description'])
     self.assertEquals(u'My service', data['item_list'][0]['service_title'])
     # Add an additional invoice item
     data['item_list'].append(
         dict(item_id='',
              service_title=u'Training',
              service_description=u'',
              amount=200.0))
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'Training', data['item_list'][1]['service_title'])
     # Reorder the items
     data['item_list'][0] = view.form_defaults()['item_list'][1]
     data['item_list'][1] = view.form_defaults()['item_list'][0]
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(u'Training', data['item_list'][0]['service_title'])
     # And remove one of them
     del data['item_list'][0]
     view.handle_submit(data)
     data = view.form_defaults()
     self.assertEquals(1, len(data['item_list']))
     self.assertEquals(u'My service', data['item_list'][0]['service_title'])
     # Submit without changing anything
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     request.matchdict = dict(invoice=str(invoice.id))
     view = InvoiceController(None, request)
     view.handle_submit(data)
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
Ejemplo n.º 11
0
    def test_handle_submit(self):
        from seantisinvoice.views.invoice import InvoiceController
        from seantisinvoice import statusmessage

        # Register route for redirect in invoice form actions
        testing.registerRoute("/", "invoices", factory=None)
        # Create an invoice
        invoice = self._add_invoice()
        request = testing.DummyRequest()
        request.matchdict = dict(invoice=str(invoice.id))
        view = InvoiceController(None, request)
        data = view.form_defaults()
        self.assertEquals(u"Project", data["project_description"])
        # Change some of the invoice date
        data["project_description"] = u"My project"
        data["recurring_term"] = 30
        data["item_list"][0]["service_title"] = u"My service"
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"My project", data["project_description"])
        self.assertEquals(u"My service", data["item_list"][0]["service_title"])
        # Add an additional invoice item
        data["item_list"].append(dict(item_id="", service_title=u"Training", service_description=u"", amount=200.0))
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"Training", data["item_list"][1]["service_title"])
        # Reorder the items
        data["item_list"][0] = view.form_defaults()["item_list"][1]
        data["item_list"][1] = view.form_defaults()["item_list"][0]
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(u"Training", data["item_list"][0]["service_title"])
        # And remove one of them
        del data["item_list"][0]
        view.handle_submit(data)
        data = view.form_defaults()
        self.assertEquals(1, len(data["item_list"]))
        self.assertEquals(u"My service", data["item_list"][0]["service_title"])
        # Submit without changing anything
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        request.matchdict = dict(invoice=str(invoice.id))
        view = InvoiceController(None, request)
        view.handle_submit(data)
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)