Skip to content
Permalink
Browse files

DB Manager: fix tests and minor cleanup

  • Loading branch information
elpaso committed Jan 31, 2020
1 parent a6e9050 commit 949efbd84ea729ed67381fb59e72c4cae301644d
@@ -67,7 +67,7 @@ def __init__(self, uri, connection):
# QgsAbstractDatabaseProviderConnection instance
self.core_connection = md.findConnection(connection.connectionName())
if self.core_connection is None:
self.core_connection = md.createConnection(uri, {})
self.core_connection = md.createConnection(uri.uri(), {})
self.has_raster = False
self.mapSridToName = {}
# To be removed when migration to new API is completed
@@ -243,7 +243,7 @@ class DbItemObject(QObject):
deleted = pyqtSignal()

def __init__(self, parent=None):
QObject.__init__(self, parent)
super().__init__(parent)

def database(self):
return None
@@ -264,7 +264,7 @@ def registerActions(self, mainWindow):
class Database(DbItemObject):

def __init__(self, dbplugin, uri):
DbItemObject.__init__(self, dbplugin)
super().__init__(dbplugin)
self.connector = self.connectorsFactory(uri)

def connectorsFactory(self, uri):
@@ -186,6 +186,8 @@ def __init__(self, uri, connection):
:param uri: data source URI
:type uri: QgsDataSourceUri
:param connection: the plugin parent instance
:type connection: PostGisDBPlugin
"""
DBConnector.__init__(self, uri)

@@ -207,7 +209,7 @@ def __init__(self, uri, connection):
# QgsAbstractDatabaseProviderConnection instance
self.core_connection = md.findConnection(connection.connectionName())
if self.core_connection is None:
self.core_connection = md.createConnection(uri, {})
self.core_connection = md.createConnection(uri.uri(), {})

c = self._execute(None, u"SELECT current_user,current_database()")
self.user, self.dbname = self._fetchone(c)
@@ -26,6 +26,7 @@
from qgis.testing import start_app, unittest
from qgis.core import QgsDataSourceUri
from qgis.utils import iface
from qgis.PyQt.QtCore import QObject

start_app()

@@ -51,7 +52,12 @@ def _getDatabase(self, connector):
# See https://github.com/qgis/QGIS/issues/24525
# and https://github.com/qgis/QGIS/issues/19005
def test_dbnameLessURI(self):
c = PostGisDBConnector(QgsDataSourceUri())

obj = QObject() # needs to be kept alive
obj.connectionName = lambda: 'fake'
obj.providerName = lambda: 'postgres'

c = PostGisDBConnector(QgsDataSourceUri(), obj)
self.assertIsInstance(c, PostGisDBConnector)
uri = c.uri()

@@ -96,6 +96,8 @@ def check_rasterTableURI(expected_dbname):
self.assertGreaterEqual(raster_tables_count, 1)

obj = QObject() # needs to be kept alive
obj.connectionName = lambda: 'fake'
obj.providerName = lambda: 'postgres'

# Test for empty URI
# See https://github.com/qgis/QGIS/issues/24525
@@ -134,6 +136,8 @@ def check_rasterTableURI(expected_dbname):
def test_unicodeInQuery(self):
os.environ['PGDATABASE'] = self.testdb
obj = QObject() # needs to be kept alive
obj.connectionName = lambda: 'fake'
obj.providerName = lambda: 'postgres'
database = PGDatabase(obj, QgsDataSourceUri())
self.assertIsInstance(database, PGDatabase)
# SQL as string literal

0 comments on commit 949efbd

Please sign in to comment.
You can’t perform that action at this time.