Skip to content
Permalink
Browse files

Update postgres project storage unit test

  • Loading branch information
wonder-sk committed Apr 7, 2018
1 parent 4281140 commit d1464a003035d30a03bfcb6e170fc3899429b8bd
@@ -92,7 +92,7 @@ bool QgsPostgresProjectStorage::readProject( const QString &uri, QIODevice *devi

if ( !_projectsTableExists( *conn, projectUri.schemaName ) )
{
// TODO: write to context
context.pushMessage( "Table qgis_projects does not exist or it is not accessible.", Qgis::Critical );
QgsPostgresConnPool::instance()->releaseConnection( conn );
return false;
}
@@ -267,7 +267,7 @@ QString QgsPostgresProjectStorage::encodeUri( const QgsPostgresProjectUri &postU
urlQuery.addQueryItem( "service", postUri.connInfo.service() );
if ( !postUri.connInfo.authConfigId().isEmpty() )
urlQuery.addQueryItem( "authcfg", postUri.connInfo.authConfigId() );
if ( !postUri.connInfo.sslMode() != QgsDataSourceUri::SslPrefer )
if ( postUri.connInfo.sslMode() != QgsDataSourceUri::SslPrefer )
urlQuery.addQueryItem( "sslmode", QgsDataSourceUri::encodeSslMode( postUri.connInfo.sslMode() ) );

urlQuery.addQueryItem( "dbname", postUri.connInfo.database() );
@@ -25,17 +25,48 @@

from qgis.core import (
QgsApplication,
QgsDataSourceUri,
QgsVectorLayer,
QgsProject,
)
from PyQt5.QtCore import QDateTime
from PyQt5.QtCore import QDateTime, QUrl, QUrlQuery
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath

QGISAPP = start_app()
TEST_DATA_DIR = unitTestDataPath()


def encode_uri(ds_uri, schema_name, project_name=None):
u = QUrl()
urlQuery = QUrlQuery()

u.setScheme("postgresql")
u.setHost(ds_uri.host())
if ds_uri.port() != '':
u.setPort(int(ds_uri.port()))
if ds_uri.username() != '':
u.setUserName(ds_uri.username())
if ds_uri.password() != '':
u.setPassword(ds_uri.password())

if ds_uri.service() != '':
urlQuery.addQueryItem("service", ds_uri.service())
if ds_uri.authConfigId() != '':
urlQuery.addQueryItem("authcfg", ds_uri.authConfigId())
if ds_uri.sslMode() != QgsDataSourceUri.SslPrefer:
urlQuery.addQueryItem("sslmode", QgsDataSourceUri.encodeSslMode(ds_uri.sslMode()))

urlQuery.addQueryItem("dbname", ds_uri.database())

urlQuery.addQueryItem("schema", schema_name)
if project_name:
urlQuery.addQueryItem("project", project_name)

u.setQuery(urlQuery)
return str(u.toEncoded(), 'utf-8')


class TestPyQgsProjectStoragePostgres(unittest.TestCase):

@classmethod
@@ -44,6 +75,8 @@ def setUpClass(cls):
cls.dbconn = 'dbname=\'qgis_test\''
if 'QGIS_PGTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_PGTEST_DB']
cls.ds_uri = QgsDataSourceUri(cls.dbconn)

# Create test layers
cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."someData" (geom) sql=', 'test', 'postgres')
assert cls.vl.isValid()
@@ -66,9 +99,8 @@ def dropProjectsTable(self):

def testSaveLoadProject(self):

# TODO: respect QGIS_PGTEST_DB
schema_uri = "postgresql:///?dbname=qgis_test&schema=qgis_test"
project_uri = "postgresql:///?dbname=qgis_test&schema=qgis_test&project=abc"
schema_uri = encode_uri(self.ds_uri, 'qgis_test')
project_uri = encode_uri(self.ds_uri, 'qgis_test', 'abc')

self.dropProjectsTable() # make sure we have a clean start

0 comments on commit d1464a0

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