mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
add test for postgres domains
This commit is contained in:
parent
498e55186c
commit
781b587090
@ -64,7 +64,6 @@ class TestQgsPostgresProvider: public QObject
|
||||
qDebug() << "actual: " << decoded;
|
||||
QCOMPARE( decoded.toList(), expected );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QGSTEST_MAIN( TestQgsPostgresProvider )
|
||||
|
@ -127,6 +127,7 @@ ADD_PYTHON_TEST(PyQgsPanelWidgetStack test_qgspanelwidgetstack.py)
|
||||
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
|
||||
ADD_PYTHON_TEST(PyQgsPointClusterRenderer test_qgspointclusterrenderer.py)
|
||||
ADD_PYTHON_TEST(PyQgsPointDisplacementRenderer test_qgspointdisplacementrenderer.py)
|
||||
ADD_PYTHON_TEST(PyQgsPostgresDomain test_qgspostgresdomain.py)
|
||||
ADD_PYTHON_TEST(PyQgsProjectionSelectionWidgets test_qgsprojectionselectionwidgets.py)
|
||||
ADD_PYTHON_TEST(PyQgsRange test_qgsrange.py)
|
||||
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
|
||||
|
48
tests/src/python/test_qgspostgresdomain.py
Normal file
48
tests/src/python/test_qgspostgresdomain.py
Normal file
@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""QGIS Unit tests for Postgres domains.
|
||||
|
||||
.. note:: This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
"""
|
||||
__author__ = 'Denis Rouzaud'
|
||||
__date__ = '10/02/2018'
|
||||
__copyright__ = 'Copyright 2018, The QGIS Project'
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
import qgis # NOQA
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import QgsVectorLayer, QgsProject
|
||||
|
||||
from qgis.testing import start_app, unittest
|
||||
|
||||
start_app()
|
||||
|
||||
|
||||
class TestQgsPostgresDomain(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Setup the involved layer
|
||||
:return:
|
||||
"""
|
||||
cls.dbconn = 'service=\'qgis_test\''
|
||||
if 'QGIS_PGTEST_DB' in os.environ:
|
||||
cls.dbconn = os.environ['QGIS_PGTEST_DB']
|
||||
# Create test layer
|
||||
cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."colors" sql=', 'colors', 'postgres')
|
||||
|
||||
QgsProject.instance().addMapLayer(cls.vl)
|
||||
|
||||
def test_postgres_domain(self):
|
||||
self.assertEqual(self.vl.dataProvider().enumValues(1), ['red', 'green', 'blue'])
|
||||
self.assertEqual(self.vl.dataProvider().enumValues(2), ['yellow', 'cyan', 'magenta'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
1
tests/testdata/provider/testdata_pg.sh
vendored
1
tests/testdata/provider/testdata_pg.sh
vendored
@ -11,6 +11,7 @@ SCRIPTS="
|
||||
tests/testdata/provider/testdata_pg_hstore.sql
|
||||
tests/testdata/provider/testdata_pg_array.sql
|
||||
tests/testdata/provider/testdata_pg_raster.sql
|
||||
tests/testdata/provider/testdata_pg_domain.sql
|
||||
"
|
||||
|
||||
dropdb qgis_test 2> /dev/null || true
|
||||
|
19
tests/testdata/provider/testdata_pg_domain.sql
vendored
Normal file
19
tests/testdata/provider/testdata_pg_domain.sql
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
|
||||
CREATE DOMAIN public.colordomain
|
||||
AS text
|
||||
COLLATE pg_catalog."default"
|
||||
CONSTRAINT domainconstraint CHECK (VALUE = ANY (ARRAY['red'::text, 'green'::text, 'blue'::text]));
|
||||
|
||||
CREATE DOMAIN qgis_test.colordomain
|
||||
AS text
|
||||
COLLATE pg_catalog."default"
|
||||
CONSTRAINT domainconstraint CHECK (VALUE = ANY (ARRAY['yellow'::text, 'cyan'::text, 'magenta'::text]));
|
||||
|
||||
CREATE TABLE qgis_test.colors
|
||||
(
|
||||
id SERIAL NOT NULL,
|
||||
color_public colordomain,
|
||||
color_qgis qgis_test.colordomain
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user