Skip to content
Permalink
Browse files

Simple tests for style load, insert and remove from Postgis provider

  • Loading branch information
jgrocha committed Jan 30, 2017
1 parent bbf6ec0 commit a4637a6af5db59e03da72a275fa4643188e925d2
Showing with 59 additions and 1 deletion.
  1. +59 −1 tests/src/python/test_provider_postgres.py
@@ -33,7 +33,7 @@
QgsVectorLayerUtils
)
from qgis.gui import QgsEditorWidgetRegistry
from qgis.PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from qgis.PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant, QDir
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
from providertestbase import ProviderTestCase
@@ -639,6 +639,64 @@ def testKey(lyr, key, kfnames):
testKey(lyr, '"f1","F2","f3"', ['f1', 'F2', 'f3'])
testKey(lyr, None, ['id'])

def testStyle(self):
self.execSQLCommand('DROP TABLE IF EXISTS layer_styles CASCADE')

vl = self.getEditableLayer()
self.assertTrue(vl.isValid())
self.assertTrue(vl.dataProvider().isSaveAndLoadStyleToDBSupported())
self.assertTrue(vl.dataProvider().isDeleteStyleFromDBSupported())

# table layer_styles does not exit
related_count, idlist, namelist, desclist, errmsg = vl.listStylesInDatabase()
self.assertEqual(related_count, -1)
self.assertEqual(idlist, [])
self.assertEqual(namelist, [])
self.assertEqual(desclist, [])
self.assertNotEqual(errmsg, "")

qml, errmsg = vl.getStyleFromDatabase("1")
self.assertEqual(qml, "")
self.assertNotEqual(errmsg, "")

mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "singleSymbol"))
status = vl.loadNamedStyle(mFilePath)
self.assertTrue(status)

errorMsg = vl.saveStyleToDatabase("name", "description", False, "")
self.assertEqual(errorMsg, "")

qml, errmsg = vl.getStyleFromDatabase("not_existing")
self.assertEqual(qml, "")
self.assertNotEqual(errmsg, "")

related_count, idlist, namelist, desclist, errmsg = vl.listStylesInDatabase()
self.assertEqual(related_count, 1)
self.assertEqual(errmsg, "")
self.assertEqual(idlist, ['1'])
self.assertEqual(namelist, ['name'])
self.assertEqual(desclist, ['description'])

qml, errmsg = vl.getStyleFromDatabase("100")
self.assertEqual(qml, "")
self.assertNotEqual(errmsg, "")

qml, errmsg = vl.getStyleFromDatabase("1")
self.assertTrue(qml.startswith('<!DOCTYPE qgis'), qml)
self.assertEqual(errmsg, "")

uri = vl.dataProvider().dataSourceUri()
vl.dataProvider().deleteStyleById(uri, "1", errmsg)
self.assertEqual(errmsg, "")

# table layer_styles does exit, but is now empty
related_count, idlist, namelist, desclist, errmsg = vl.listStylesInDatabase()
self.assertEqual(related_count, 0)
self.assertEqual(idlist, [])
self.assertEqual(namelist, [])
self.assertEqual(desclist, [])
self.assertEqual(errmsg, "")


class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):

0 comments on commit a4637a6

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