1
0
mirror of https://github.com/qgis/QGIS.git synced 2025-04-27 00:03:38 -04:00

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
tests
src/python
testdata/provider

@ -132,6 +132,21 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase):
self.assertIsInstance(f.attributes()[datetime_idx], QDateTime) self.assertIsInstance(f.attributes()[datetime_idx], QDateTime)
self.assertEqual(f.attributes()[datetime_idx], QDateTime(QDate(2004, 3, 4), QTime(13, 41, 52))) 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 testQueryLayers(self):
def test_query(dbconn, query, key): def test_query(dbconn, query, key):
ql = QgsVectorLayer('%s srid=4326 table="%s" (geom) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), key), "testgeom", "postgres") 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 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>'); ('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 -- Table for constraint tests