def test_edit_address(self, warning): client = self.store.find( Person, name=u"Franciso Elisio de Lima Junior")[0].client editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) dump = GUIDumper() dump.dump_editor(editor) def run_dialog2(dialog, parent, *args, **kwargs): d = dialog(*args, **kwargs) dump.dump_dialog(d) # Avoid committing return False def run_dialog(dialog, parent, *args, **kwargs): d = dialog(*args, **kwargs) dump.dump_dialog(d) with mock.patch('stoq.lib.gui.base.lists.run_dialog', new=run_dialog2): self.click(d.list_slave.listcontainer.add_button) return d.retval with mock.patch('stoq.lib.gui.templates.persontemplate.run_dialog', new=run_dialog): self.click(editor.get_person_slave().address_button) self.check_filename(dump, 'editor-client-edit-address')
def test_edit_without_address(self, warning): client = self.create_client() editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) self.click(editor.get_person_slave().address_button) warning.assert_called_once_with( 'You must define a valid main address before\n' 'adding additional addresses')
def test_only_admin_can_add_client_credit(self): client = self.create_client() editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) self.check_editor(editor, 'client-editor-admin-user') admin_user = api.get_current_user(self.store) salesperson_user = self.store.find(LoginUser, username=u'elias').one() provide_utility(ICurrentUser, salesperson_user, replace=True) editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) self.check_editor(editor, 'client-editor-salesperson-user') provide_utility(ICurrentUser, admin_user, replace=True)
def test_queries(self): client = self.create_client() with self.count_tracer() as tracer: ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) # FIXME: The list bellow is broken. It's documenting 26 queries but # only 21 are being executed. Maybe we should compare the queries # (with something like assertRaisesRegex for parts like uuids) # instead of counting them. It will be easier to maintain. # NOTE: Document increases/decreases # 1: select user/branch/station (normally cached) # 4: transaction_entry # 4: insert person/individual/client/address # 2: select individual # 2: select company # 1: select address # 1: select client # 1: select client category # 1: select ui form # 1: select ui field # 1: select address # 4: select city location # 1: update individual # 2: select payment # 1: select current user # 1: select app permissions for the user self.assertEqual(tracer.count, 22)
def test_person_editor(self): sysparam.__init__() client = self.create_client() editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) self.check_editor(editor, 'editor-client-optical-plugin') with mock.patch('plugins.optical.opticalui.run_dialog') as run_dialog_: self.click(editor.patient_history_button) run_dialog_.assert_called_once_with(OpticalPatientDetails, editor, self.store, client)
def test_individual_responsible(self): client = self.create_client() client2 = self.create_client() editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) slave = editor.individual_slave slave.details_slave.person_gadget.set_value(client2.person.individual) self.check_editor(editor, 'client-editor-with-responsible')
def test_validate_email(self): client = self.create_client() editor = ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL) slave = editor._person_slave # Without symbol @ slave.email.update('stoq.com.br') self.assertInvalid(slave, ['email']) # Without a dot afer @ slave.email.update('stoq@com') self.assertInvalid(slave, ['email']) slave.email.update('*****@*****.**') self.assertValid(slave, ['email'])
def test_create_company(self): editor = ClientEditor(self.store, role_type=Person.ROLE_COMPANY) self.check_editor(editor, 'editor-client-company-create')
def test_create_individual(self): editor = ClientEditor(self.store, role_type=Person.ROLE_INDIVIDUAL) self.check_editor(editor, 'editor-client-individual-create')