Skip to content
Permalink
Browse files
Add test for postgres boolean
  • Loading branch information
m-kuhn committed Apr 10, 2017
1 parent 88a8a2c commit e7e73bafcfbcb5956e11be31a84803d78e7232d5
Showing with 29 additions and 0 deletions.
  1. +15 −0 tests/src/python/test_provider_postgres.py
  2. +14 −0 tests/testdata/provider/testdata_pg.sql
@@ -132,6 +132,21 @@ def testDateTimeTypes(self):
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2004, 3, 4), QTime(13, 41, 52)))

def testBooleanType(self):
vl = QgsVectorLayer('{} table="qgis_test"."boolean_table" sql='.format(self.dbconn), "testbool", "postgres")
self.assertTrue(vl.isValid())

fields = vl.dataProvider().fields()
self.assertEqual(fields.at(fields.indexFromName('fld1')).type(), QVariant.Bool)

values = {feat['id']: feat['fld1'] for feat in vl.getFeatures()}
expected = {
1: True,
2: False,
3: NULL
}
self.assertEqual(values, expected)

def testQueryLayers(self):
def test_query(dbconn, query, key):
ql = QgsVectorLayer('%s srid=4326 table="%s" (geom) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), key), "testgeom", "postgres")
@@ -459,6 +459,20 @@ CREATE TABLE qgis_test.widget_styles(
INSERT INTO qgis_editor_widget_styles VALUES
('qgis_test', 'widget_styles', 'fld1', 'FooEdit', '<config type="Map"><Option name="param1" value="value1" type="QString"/><Option name="param2" value="2" type="QString"/></config>');

--------------------------------------
-- Table for boolean
--

CREATE TABLE qgis_test.boolean_table
(
id int PRIMARY KEY,
fld1 BOOLEAN
);

INSERT INTO qgis_test.boolean_table VALUES
(1, TRUE),
(2, FALSE),
(3, NULL);

-----------------------------
-- Table for constraint tests

0 comments on commit e7e73ba

Please sign in to comment.