Beispiel #1
0
    def test_is_available(self):
        self.assertTrue(SystemTable.is_available(self.store))

        store = mock.Mock()
        store.table_exists.return_value = False
        self.assertFalse(SystemTable.is_available(store))

        self.assertEquals(store.find.call_count, 0)

        store.table_exists.return_value = True
        store.find.return_value = False
        self.assertFalse(SystemTable.is_available(store))

        store.find.assert_called_once_with(SystemTable)
Beispiel #2
0
    def test_is_available(self):
        self.assertTrue(SystemTable.is_available(self.store))

        store = mock.Mock()
        store.table_exists.return_value = False
        self.assertFalse(SystemTable.is_available(store))

        self.assertEquals(store.find.call_count, 0)

        store.table_exists.return_value = True
        store.find.return_value = False
        self.assertFalse(SystemTable.is_available(store))

        store.find.assert_called_once_with(SystemTable)
Beispiel #3
0
    def test_confirm(self, save, generator, localtoday):
        save.return_value = True

        value = datetime.datetime(2012, 1, 31)
        localtoday.return_value = value

        # we need to create a system table because it is used by the sintegra
        # dialog to populate the date filter
        SystemTable(updated=datetime.datetime(2012, 1, 1),
                    patchlevel=0,
                    generation=1,
                    store=self.store)
        branch = api.get_current_branch(self.store)
        branch.manager = self.create_employee()

        dialog = SintegraDialog(self.store)
        with mock.patch.object(generator, 'write'):
            self.click(dialog.ok_button)
            self.check_dialog(dialog, 'dialog-sintegra-confirm',
                              [dialog.retval])

            self.assertEqual(save.call_count, 1)
            args, kwargs = save.call_args
            label, toplevel, filename = args
            self.assertEqual(label, _("Save Sintegra file"))
            self.assertTrue(isinstance(toplevel, Gtk.Dialog))
            self.assertEqual(filename, 'sintegra-2012-01.txt')
Beispiel #4
0
    def check_incomplete_database(self):
        logger.info('check_incomplete_database (db_is_local=%s)' %
                   (self.db_is_local, ))
        # If we don't have postgres installed we cannot have
        # an incomplete database
        if self.db_is_local and not test_local_database():
            return False

        # a database which doesn't exist isn't incomplete
        try:
            if not self.settings.has_database():
                return False
        except DatabaseError as e:
            # If we're install stoq locally and hasn't created a database
            # user yet, we'll receive an authentiction error, there's no
            # way to reliably check for this, so assume all errors are
            # authentication errors
            # first install on 9.1: FATAL: role "stoq" does not exist.
            if self.db_is_local:
                return False
            msg = (_('It was not possible to connect to the database.') +
                   '\n' + _('Check the server configuration and try again.'))
            warning(msg, str(e))
            return True

        # If we have the SystemTable we are pretty much there,
        # could verify a few more tables in the future, including
        # row content of the tables.
        store = self.settings.create_store()
        if SystemTable.is_available(store):
            store.close()
            return False
        store.close()

        # okay, we have a database which exists and doesn't have
        # the "SystemTable" SQL table present, means that we cannot use
        # it and should warn the user

        # Not 100% correct, should perhaps say "unix socket"
        address = self.settings.address or "localhost"
        msg = _("Database {dbname} at {address}:{port} is not "
                "a Stoq database.").format(
            dbname=self.settings.dbname,
            address=address,
            port=self.settings.port)
        description = _(
            "Stoq was able to succesfully connect to the database "
            "{dbname} at the database server {address}, however it "
            "is not a Stoq database or it was corrupted, please select "
            "another one.").format(dbname=self.settings.dbname,
                                   address=self.settings.address or "localhost")
        warning(msg, description)
        return True
Beispiel #5
0
    def check_incomplete_database(self):
        logger.info('check_incomplete_database (db_is_local=%s)' %
                    (self.db_is_local, ))
        # If we don't have postgres installed we cannot have
        # an incomplete database
        if self.db_is_local and not test_local_database():
            return False

        # a database which doesn't exist isn't incomplete
        try:
            if not self.settings.has_database():
                return False
        except DatabaseError as e:
            # If we're install stoq locally and hasn't created a database
            # user yet, we'll receive an authentiction error, there's no
            # way to reliably check for this, so assume all errors are
            # authentication errors
            # first install on 9.1: FATAL: role "stoq" does not exist.
            if self.db_is_local:
                return False
            msg = (_('It was not possible to connect to the database.') +
                   '\n' + _('Check the server configuration and try again.'))
            warning(msg, str(e))
            return True

        # If we have the SystemTable we are pretty much there,
        # could verify a few more tables in the future, including
        # row content of the tables.
        store = self.settings.create_store()
        if SystemTable.is_available(store):
            store.close()
            return False
        store.close()

        # okay, we have a database which exists and doesn't have
        # the "SystemTable" SQL table present, means that we cannot use
        # it and should warn the user

        # Not 100% correct, should perhaps say "unix socket"
        address = self.settings.address or "localhost"
        msg = _("Database {dbname} at {address}:{port} is not "
                "a Stoq database.").format(dbname=self.settings.dbname,
                                           address=address,
                                           port=self.settings.port)
        description = _(
            "Stoq was able to succesfully connect to the database "
            "{dbname} at the database server {address}, however it "
            "is not a Stoq database or it was corrupted, please select "
            "another one.").format(dbname=self.settings.dbname,
                                   address=self.settings.address
                                   or "localhost")
        warning(msg, description)
        return True
Beispiel #6
0
 def try_connect(self, settings, warn=True):
     logger.info('try_connect (warn=%s)' % (warn))
     logger.info('settings: address=%s username=%s, dbname=%s' % (
                     settings.address, settings.username, settings.dbname))
     self.config.load_settings(settings)
     try:
         if settings.has_database():
             store = settings.create_store()
             self.has_installed_db = SystemTable.is_available(store)
             store.close()
     except DatabaseError, e:
         if warn:
             warning(e.short, str(e.msg))
         logger.info('Failed to connect')
         return False
Beispiel #7
0
    def try_connect(self, settings, warn=True):
        logger.info('try_connect (warn=%s)' % (warn))
        logger.info('settings: address=%s username=%s, dbname=%s' %
                    (settings.address, settings.username, settings.dbname))
        self.config.load_settings(settings)
        try:
            if settings.has_database():
                store = settings.create_store()
                self.has_installed_db = SystemTable.is_available(store)
                store.close()
        except DatabaseError as e:
            if warn:
                warning(e.short, str(e.msg))
            logger.info('Failed to connect')
            return False

        logger.info('Connected')
        return True
Beispiel #8
0
            # user yet, we'll receive an authentiction error, there's no
            # way to reliably check for this but looking for a auth string
            # should make it work with posgres running in both english and
            # portuguese
            if self.db_is_local and 'auth' in str(e):
                return False
            msg = (_('It was not possible to connect to the database.') +
                  '\n' + _('Check the server configuration and try again.'))
            warning(msg, str(e))
            return True

        # If we have the SystemTable we are pretty much there,
        # could verify a few more tables in the future, including
        # row content of the tables.
        store = self.settings.create_store()
        if SystemTable.is_available(store):
            store.close()
            return False
        store.close()

        # okay, we have a database which exists and doesn't have
        # the "SystemTable" SQL table present, means that we cannot use
        # it and should warn the user

        # Not 100% correct, should perhaps say "unix socket"
        address = self.settings.address or "localhost"
        msg = _("Database {dbname} at {address}:{port} is not "
                "a Stoq database.").format(
            dbname=self.settings.dbname,
            address=address,
            port=self.settings.port)