Skip to content

Commit e7e73ba

Browse files
committedApr 10, 2017
Add test for postgres boolean
1 parent 88a8a2c commit e7e73ba

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎tests/src/python/test_provider_postgres.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ def testDateTimeTypes(self):
132132
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
133133
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2004, 3, 4), QTime(13, 41, 52)))
134134

135+
def testBooleanType(self):
136+
vl = QgsVectorLayer('{} table="qgis_test"."boolean_table" sql='.format(self.dbconn), "testbool", "postgres")
137+
self.assertTrue(vl.isValid())
138+
139+
fields = vl.dataProvider().fields()
140+
self.assertEqual(fields.at(fields.indexFromName('fld1')).type(), QVariant.Bool)
141+
142+
values = {feat['id']: feat['fld1'] for feat in vl.getFeatures()}
143+
expected = {
144+
1: True,
145+
2: False,
146+
3: NULL
147+
}
148+
self.assertEqual(values, expected)
149+
135150
def testQueryLayers(self):
136151
def test_query(dbconn, query, key):
137152
ql = QgsVectorLayer('%s srid=4326 table="%s" (geom) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), key), "testgeom", "postgres")

‎tests/testdata/provider/testdata_pg.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ CREATE TABLE qgis_test.widget_styles(
459459
INSERT INTO qgis_editor_widget_styles VALUES
460460
('qgis_test', 'widget_styles', 'fld1', 'FooEdit', '<config type="Map"><Option name="param1" value="value1" type="QString"/><Option name="param2" value="2" type="QString"/></config>');
461461

462+
--------------------------------------
463+
-- Table for boolean
464+
--
465+
466+
CREATE TABLE qgis_test.boolean_table
467+
(
468+
id int PRIMARY KEY,
469+
fld1 BOOLEAN
470+
);
471+
472+
INSERT INTO qgis_test.boolean_table VALUES
473+
(1, TRUE),
474+
(2, FALSE),
475+
(3, NULL);
462476

463477
-----------------------------
464478
-- Table for constraint tests

0 commit comments

Comments
 (0)
Please sign in to comment.