Skip to content
Permalink
Browse files

Unit test for 4ec97c3

  • Loading branch information
m-kuhn committed Apr 7, 2016
1 parent 4ec97c3 commit e98e16f1b2b0129e949f7d40409119cee4a1c6fd
Showing with 38 additions and 1 deletion.
  1. +11 −1 tests/src/python/test_provider_postgres.py
  2. +27 −0 tests/testdata/provider/testdata_pg.sql
@@ -17,7 +17,7 @@
import os
from qgis.core import NULL

from qgis.core import QgsVectorLayer, QgsFeatureRequest
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature
from PyQt.QtCore import QSettings, QDate, QTime, QDateTime, QVariant
from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
@@ -165,6 +165,16 @@ def test_query_attribute(dbconn, query, att, val, fidval):
test_query_attribute(self.dbconn, '(SELECT -1::int8 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -65535::int8 i, NULL::geometry(Point) g)', 'i', -65535, 1)

def testPktMapInsert(self):
vl = QgsVectorLayer('{} table="qgis_test"."{}" key="pk" sql='.format(self.dbconn, 'books_view'), "books_view", "postgres")
self.assertTrue(vl.isValid())
f = QgsFeature(vl.fields())
f.setAttribute(0, NULL)
f.setAttribute(1, 'Das Drama des begabten Kindes')
r, f = vl.dataProvider().addFeatures([f])
self.assertTrue(r)
self.assertIsNotNone(f[0]['pk'])
vl.deleteFeatures([f[0].id()])

if __name__ == '__main__':
unittest.main()
@@ -309,3 +309,30 @@ INSERT INTO qgis_test.child_table_good (geom, code1) VALUES ('srid=4326;Point(1
INSERT INTO qgis_test.child_table2_good (geom, code2) VALUES ('srid=4326;Point(-1 -1)'::geometry, 'child2 1');
INSERT INTO qgis_test.child_table2_good (geom, code2) VALUES ('srid=4326;Point(-1 1)'::geometry, 'child2 2');

--------------------------------------
-- A writable view
--
CREATE OR REPLACE VIEW qgis_test.books_view
AS
SELECT *
FROM qgis_test.books;

CREATE OR REPLACE FUNCTION qgis_test.books_view_insert()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO qgis_test.books (
"name"
)
VALUES (
NEW.name
)
RETURNING pk INTO NEW.pk;

RETURN NEW;
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

CREATE TRIGGER books_view_ON_INSERT INSTEAD OF INSERT ON qgis_test.books_view
FOR EACH ROW EXECUTE PROCEDURE qgis_test.books_view_insert();

0 comments on commit e98e16f

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