Skip to content

Commit

Permalink
Add test to make sure geometry type columns are filled properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrocha committed Oct 7, 2019
1 parent 089911a commit 0656f72
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -4853,8 +4853,6 @@ bool QgsPostgresProviderMetadata::saveStyle( const QString &uri, const QString &
sql = QStringLiteral( "BEGIN; %1; %2; COMMIT;" ).arg( removeDefaultSql, sql );
}

QgsDebugMsg( QStringLiteral( "-------------------------COSTA NOVA: %1 " ).arg( sql ) );

res = conn->PQexec( sql );

bool saved = res.PQresultStatus() == PGRES_COMMAND_OK;
Expand Down
39 changes: 39 additions & 0 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -1129,6 +1129,45 @@ def testStyle(self):
self.assertEqual(desclist, [])
self.assertEqual(errmsg, "")

def testStyleWithGeometryType(self):
"""Test saving styles with the additional geometry type
Layers are created from geometries_table
"""

myconn = 'service=\'qgis_test\''
if 'QGIS_PGTEST_DB' in os.environ:
myconn = os.environ['QGIS_PGTEST_DB']

# point layer
myPoint = QgsVectorLayer(myconn + ' sslmode=disable srid=4326 type=POINT table="qgis_test"."geometries_table" (geom) sql=', 'Point', 'postgres')
self.assertTrue(myPoint.isValid())
myPoint.saveStyleToDatabase('myPointStyle', '', False, '')

# polygon layer
myPolygon = QgsVectorLayer(myconn + ' sslmode=disable srid=4326 type=POLYGON table="qgis_test"."geometries_table" (geom) sql=', 'Poly', 'postgres')
self.assertTrue(myPoint.isValid())
myPolygon.saveStyleToDatabase('myPolygonStyle', '', False, '')

# how many
related_count, idlist, namelist, desclist, errmsg = myPolygon.listStylesInDatabase()
self.assertEqual(len(idlist), 2)
self.assertEqual(namelist, ['myPolygonStyle', 'myPointStyle'])

# raw psycopg2 query
self.assertTrue(self.con)
cur = self.con.cursor()
self.assertTrue(cur)
cur.execute("select stylename, type from layer_styles order by type")
self.assertEqual(cur.fetchall(), [('myPointStyle', 'Point'), ('myPolygonStyle', 'Polygon')])
cur.close()

# delete them
myPolygon.deleteStyleFromDatabase(idlist[1])
myPolygon.deleteStyleFromDatabase(idlist[0])
styles = myPolygon.listStylesInDatabase()
ids = styles[1]
self.assertEqual(len(ids), 0)

def testHasMetadata(self):
# views don't have metadata
vl = QgsVectorLayer('{} table="qgis_test"."{}" key="pk" sql='.format(self.dbconn, 'bikes_view'), "bikes_view", "postgres")
Expand Down

0 comments on commit 0656f72

Please sign in to comment.