Add test for postgres boolean

This commit is contained in:
Matthias Kuhn 2017-04-07 13:56:22 +02:00
parent 88a8a2c94d
commit e7e73bafcf
2 changed files with 29 additions and 0 deletions

View File

@ -132,6 +132,21 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase):
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")

View File

@ -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