예제 #1
0
 def test_form_fields(self):
     from seantisinvoice.views.customer import CustomerController
     from seantisinvoice.views.customer import CustomerSchema
     request = testing.DummyRequest()
     view = CustomerController(None, request)
     fields = view.form_fields()
     self.assertEquals(CustomerSchema.attrs, fields)
예제 #2
0
    def test_form_widgets(self):
        from seantisinvoice.views.customer import CustomerController

        request = testing.DummyRequest()
        view = CustomerController(None, request)
        widgets = view.form_widgets(view.form_fields())
        self.failIf(widgets["contact_list"].sortable)
예제 #3
0
    def test_form_fields(self):
        from seantisinvoice.views.customer import CustomerController
        from seantisinvoice.views.customer import CustomerSchema

        request = testing.DummyRequest()
        view = CustomerController(None, request)
        fields = view.form_fields()
        self.assertEquals(CustomerSchema.attrs, fields)
예제 #4
0
 def test_handle_cancel(self):
     from seantisinvoice.views.customer import CustomerController
     from seantisinvoice import statusmessage
     # Register route for redirect in customer form actions
     testing.registerRoute('/customers', 'customers', factory=None)
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     view = CustomerController(None, request)
     view.handle_cancel()
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
예제 #5
0
    def test_handle_cancel(self):
        from seantisinvoice.views.customer import CustomerController
        from seantisinvoice import statusmessage

        # Register route for redirect in customer form actions
        testing.registerRoute("/customers", "customers", factory=None)
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        view = CustomerController(None, request)
        view.handle_cancel()
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)
예제 #6
0
 def test_call(self):
     from seantisinvoice.views.customer import CustomerController
     request = testing.DummyRequest()
     # No customer with this id
     request.matchdict = dict(customer='2')
     view = CustomerController(None, request)
     result = view()
     self.assertEquals(404, result.status_int)
     # Add a customer
     customer = self._add_customer()
     request.matchdict = dict(customer=str(customer.id))
     view = CustomerController(None, request)
     result = view()
     self.failUnless('main' in result.keys())
예제 #7
0
    def test_handle_add(self):
        from seantisinvoice.models import Customer
        from seantisinvoice.models import DBSession
        from seantisinvoice.views.customer import CustomerController

        # Register route for redirect in customer form actions
        testing.registerRoute("/customers", "customers", factory=None)
        request = testing.DummyRequest()
        view = CustomerController(None, request)
        # Add a new customer
        data = dict(name=u"Customers Inc.", address1=u"Street", postal_code=u"12234", city=u"Dublin")
        data["contact_list"] = [dict(first_name=u"Buck", last_name=u"Mulligan", title=u"Mr.", contact_id="")]
        view.handle_add(data)
        session = DBSession()
        customer = session.query(Customer).one()
        self.assertEquals(u"Customers Inc.", customer.name)
        self.assertEquals(u"Buck", customer.contacts[0].first_name)
예제 #8
0
 def test_handle_add(self):
     from seantisinvoice.models import Customer
     from seantisinvoice.models import DBSession
     from seantisinvoice.views.customer import CustomerController
     # Register route for redirect in customer form actions
     testing.registerRoute('/customers', 'customers', factory=None)
     request = testing.DummyRequest()
     view = CustomerController(None, request)
     # Add a new customer
     data = dict(name=u'Customers Inc.',
                 address1=u'Street',
                 postal_code=u'12234',
                 city=u'Dublin')
     data['contact_list'] = [
         dict(first_name=u'Buck',
              last_name=u'Mulligan',
              title=u'Mr.',
              contact_id='')
     ]
     view.handle_add(data)
     session = DBSession()
     customer = session.query(Customer).one()
     self.assertEquals(u'Customers Inc.', customer.name)
     self.assertEquals(u'Buck', customer.contacts[0].first_name)
예제 #9
0
 def test_form_widgets(self):
     from seantisinvoice.views.customer import CustomerController
     request = testing.DummyRequest()
     view = CustomerController(None, request)
     widgets = view.form_widgets(view.form_fields())
     self.failIf(widgets['contact_list'].sortable)
예제 #10
0
 def test_handle_submit(self):
     from seantisinvoice.views.customer import CustomerController
     from seantisinvoice import statusmessage
     # Register route for redirect in customer form actions
     testing.registerRoute('/customers', 'customers', factory=None)
     # Add a customer
     customer = self._add_customer()
     request = testing.DummyRequest()
     request.matchdict = dict(customer=str(customer.id))
     view = CustomerController(None, request)
     # Check default values
     default_values = view.form_defaults()
     self.assertEquals(u'Customers Inc.', default_values['name'])
     # Change the data
     default_values['name'] = u'Seantis GmbH'
     default_values['contact_list'][0]['first_name'] = u'Leopold'
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(u'Seantis GmbH', default_values['name'])
     self.assertEquals(u'Leopold',
                       default_values['contact_list'][0]['first_name'])
     # Add an additional contact
     contact_date = dict(first_name=u'Stephen',
                         last_name=u'Dedalus',
                         title=u'Mr.',
                         contact_id='')
     default_values['contact_list'].append(contact_date)
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(u'Stephen',
                       default_values['contact_list'][1]['first_name'])
     # Remove one of the contacts
     del default_values['contact_list'][0]
     view.handle_submit(default_values)
     default_values = view.form_defaults()
     self.assertEquals(1, len(default_values['contact_list']))
     # Contacts are alphabetically ordered.
     self.assertEquals(u'Stephen',
                       default_values['contact_list'][0]['first_name'])
     # Submit without changing anything
     request = testing.DummyRequest()
     request.environ['qc.statusmessage'] = []
     request.matchdict = dict(customer=str(customer.id))
     view = CustomerController(None, request)
     view.handle_submit(default_values)
     msgs = statusmessage.messages(request)
     self.assertEquals(1, len(msgs))
     self.assertEquals(u"No changes saved.", msgs[0].msg)
예제 #11
0
    def test_handle_submit(self):
        from seantisinvoice.views.customer import CustomerController
        from seantisinvoice import statusmessage

        # Register route for redirect in customer form actions
        testing.registerRoute("/customers", "customers", factory=None)
        # Add a customer
        customer = self._add_customer()
        request = testing.DummyRequest()
        request.matchdict = dict(customer=str(customer.id))
        view = CustomerController(None, request)
        # Check default values
        default_values = view.form_defaults()
        self.assertEquals(u"Customers Inc.", default_values["name"])
        # Change the data
        default_values["name"] = u"Seantis GmbH"
        default_values["contact_list"][0]["first_name"] = u"Leopold"
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(u"Seantis GmbH", default_values["name"])
        self.assertEquals(u"Leopold", default_values["contact_list"][0]["first_name"])
        # Add an additional contact
        contact_date = dict(first_name=u"Stephen", last_name=u"Dedalus", title=u"Mr.", contact_id="")
        default_values["contact_list"].append(contact_date)
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(u"Stephen", default_values["contact_list"][1]["first_name"])
        # Remove one of the contacts
        del default_values["contact_list"][0]
        view.handle_submit(default_values)
        default_values = view.form_defaults()
        self.assertEquals(1, len(default_values["contact_list"]))
        # Contacts are alphabetically ordered.
        self.assertEquals(u"Stephen", default_values["contact_list"][0]["first_name"])
        # Submit without changing anything
        request = testing.DummyRequest()
        request.environ["qc.statusmessage"] = []
        request.matchdict = dict(customer=str(customer.id))
        view = CustomerController(None, request)
        view.handle_submit(default_values)
        msgs = statusmessage.messages(request)
        self.assertEquals(1, len(msgs))
        self.assertEquals(u"No changes saved.", msgs[0].msg)