def test_company_customer_schema(): from autonomie.forms.customer import get_company_customer_schema schema = get_company_customer_schema() args = { "name": u"Test customer", "civilite": "Monsieur", "address": u"1 rue Victor Hugo", "lastname": "Lastname", "zip_code": "21000", "city": u"Paris", } result = schema.deserialize(args) assert result['name'] == u'Test customer' # mandatory fields wrong = args.copy() wrong.pop('name') with pytest.raises(colander.Invalid): schema.deserialize(wrong) wrong = args.copy() wrong['email'] = 'wrongmail' with pytest.raises(colander.Invalid): schema.deserialize(wrong) wrong = args.copy() wrong['civilite'] = 'wrongone' with pytest.raises(colander.Invalid): schema.deserialize(wrong)
def schema(self): """ The getter for our schema property """ if self._schema is None: if self.is_company_form(): self._schema = get_company_customer_schema() else: self._schema = get_individual_customer_schema() return self._schema
def get_schema(self, submitted): if 'formid' in submitted: if submitted['formid'] == 'company': schema = get_company_customer_schema() else: schema = get_individual_customer_schema() else: excludes = ('company_id',) schema = SQLAlchemySchemaNode(Customer, excludes=excludes) return schema
def get_schema(self, submitted): if 'formid' in submitted: if submitted['formid'] == 'company': schema = get_company_customer_schema() else: schema = get_individual_customer_schema() else: excludes = ('company_id', ) schema = get_add_edit_customer_schema(excludes=excludes) return schema
def get_company_customer_form(request, counter=None): """ Returns the customer add/edit form :param obj request: Pyramid's request object :param obj counter: An iterator for field number generation :returns: a deform.Form instance """ schema = get_company_customer_schema() schema = schema.bind(request=request) form = Form( schema, buttons=(submit_btn,), counter=counter, formid='company', ) form.widget = GridFormWidget(named_grid=COMPANY_FORM_GRID) return form