Skip to content

Commit 4d057e9

Browse files
committed
Test for spatialite load default style
1 parent b1c7734 commit 4d057e9

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/src/python/test_provider_spatialite.py

+37
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,43 @@ def testDecodeUri(self):
752752
components = registry.decodeUri('spatialite', uri)
753753
self.assertEqual(components['path'], filename)
754754

755+
def testLoadStyle(self):
756+
"""Check that we can store and load a style"""
757+
758+
# create test db
759+
dbname = os.path.join(tempfile.gettempdir(), "test_loadstyle.sqlite")
760+
if os.path.exists(dbname):
761+
os.remove(dbname)
762+
con = spatialite_connect(dbname, isolation_level=None)
763+
cur = con.cursor()
764+
cur.execute("BEGIN")
765+
sql = "SELECT InitSpatialMetadata()"
766+
cur.execute(sql)
767+
768+
# simple table with primary key
769+
sql = "CREATE TABLE test_pg (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
770+
cur.execute(sql)
771+
772+
sql = "SELECT AddGeometryColumn('test_pg', 'geometry', 4326, 'POLYGON', 'XY')"
773+
cur.execute(sql)
774+
775+
sql = "INSERT INTO test_pg (id, name, geometry) "
776+
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
777+
cur.execute(sql)
778+
779+
cur.execute("COMMIT")
780+
con.close()
781+
782+
testPath = "dbname=%s table='test_pg' (geometry) key='id'" % dbname
783+
vl = QgsVectorLayer(testPath, 'test', 'spatialite')
784+
self.assertTrue(vl.isValid())
785+
self.assertEqual(vl.featureCount(), 1)
786+
err, ok = vl.loadDefaultStyle()
787+
self.assertFalse(ok)
788+
vl.saveStyleToDatabase('my_style', 'My description', True, '')
789+
err, ok = vl.loadDefaultStyle()
790+
self.assertTrue(ok)
791+
755792

756793
if __name__ == '__main__':
757794
unittest.main()

0 commit comments

Comments
 (0)