Skip to content

Commit

Permalink
basic tests for json type in gpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Dec 11, 2018
1 parent 5526975 commit 607dffd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/src/python/test_provider_ogr_gpkg.py
Expand Up @@ -1230,6 +1230,29 @@ def testTransaction(self):
self.assertEqual(len([f for f in vl2_external.getFeatures(QgsFeatureRequest())]), 1)
del vl2_external

def testJson(self):
tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
testdata_path = unitTestDataPath('provider')
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)

vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile, 'foo', 'ogr'))
self.assertTrue(vl.isValid())

fields = vl.dataProvider().fields()
self.assertEqual(fields.at(fields.indexFromName('json_content')).type(), QVariant.Map)

fi = vl.getFeatures(QgsFeatureRequest())
f = QgsFeature()

#test dict value
while fi.nextFeature(f):
fid = vl.fields().lookupField('fid')
if fid == 1:
value = vl.fields().lookupField('json_content')
self.assertIsInstance(f.attributes()[value], dict)
self.assertEqual(f.attributes()[value_idx], {'foo': 'bar'})
break


if __name__ == '__main__':
unittest.main()
Binary file added tests/testdata/provider/test_json.gpkg
Binary file not shown.

0 comments on commit 607dffd

Please sign in to comment.