Exemplo n.º 1
0
    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('stoqlib.gui.base.lists.run_dialog',
                            new=run_dialog2):
                self.click(d.list_slave.listcontainer.add_button)
            return d.retval

        with mock.patch('stoqlib.gui.templates.persontemplate.run_dialog',
                        new=run_dialog):
            self.click(editor.get_person_slave().address_button)

        self.check_filename(dump, 'editor-client-edit-address')
Exemplo n.º 2
0
    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('stoqlib.gui.base.lists.run_dialog',
                            new=run_dialog2):
                self.click(d.list_slave.listcontainer.add_button)
            return d.retval

        with mock.patch('stoqlib.gui.templates.persontemplate.run_dialog',
                        new=run_dialog):
            self.click(editor.get_person_slave().address_button)

        self.check_filename(dump, 'editor-client-edit-address')
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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 assertRaisesRegexp 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
        # 1: select individual
        # 2: select company
        # 1: select address
        # 1: select client
        # 1: select client category
        # 1: select ui form
        # 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.assertEquals(tracer.count, 21)
Exemplo n.º 7
0
    def test_queries(self):
        client = self.create_client()

        with self.count_tracer() as tracer:
            ClientEditor(self.store, client, role_type=Person.ROLE_INDIVIDUAL)

        # NOTE: Document increases/decreases
        # 3: select user/branch/station (normally cached)
        # 4: transaction_entry
        # 4: insert person/individual/client/address
        # 1: select individual
        # 2: select company
        # 1: select address
        # 1: select person
        # 1: select client
        # 1: select client category
        # 1: select ui form
        # 13: select ui field
        # 1: select address
        # 5: select parameters
        # 4: select city location
        # 1: update individual
        # 2: select payment
        # 1: select current user
        # 1: select app permissions for the user
        self.assertEquals(tracer.count, 42)
Exemplo n.º 8
0
    def test_person_editor(self):
        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)
Exemplo n.º 9
0
    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')
Exemplo n.º 10
0
    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'])
Exemplo n.º 11
0
 def test_create_individual(self):
     editor = ClientEditor(self.store, role_type=Person.ROLE_INDIVIDUAL)
     self.check_editor(editor, 'editor-client-individual-create')
Exemplo n.º 12
0
 def test_create_company(self):
     editor = ClientEditor(self.store, role_type=Person.ROLE_COMPANY)
     self.check_editor(editor, 'editor-client-company-create')