Skip to content

Commit

Permalink
Add test for postgres boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 10, 2017
1 parent 88a8a2c commit e7e73ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/src/python/test_provider_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions tests/testdata/provider/testdata_pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7e73ba

Please sign in to comment.