mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add test for postgres boolean
This commit is contained in:
parent
88a8a2c94d
commit
e7e73bafcf
@ -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")
|
||||
|
14
tests/testdata/provider/testdata_pg.sql
vendored
14
tests/testdata/provider/testdata_pg.sql
vendored
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user