Skip to content
Permalink
Browse files

Add unit test for json exporter and alias

  • Loading branch information
pblottiere committed Jan 28, 2019
1 parent 7e414b0 commit 3f38365d4d55bf7ab2cda253b612907ae49728a9
Showing with 32 additions and 0 deletions.
  1. +32 −0 tests/src/python/test_qgsjsonutils.py
@@ -726,6 +726,38 @@ def testExportFeaturesWithLocale_regression20053(self):
exporter.setVectorLayer(source)
self.assertEqual(exporter.exportFeatures([feature]), expected)

def testExportFieldAlias(self):
""" Test exporting a feature with fields' alias """

# source layer
source = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
"parent", "memory")
pr = source.dataProvider()
pf1 = QgsFeature()
pf1.setFields(source.fields())
pf1.setAttributes(["test1", 1])
pf2 = QgsFeature()
pf2.setFields(source.fields())
pf2.setAttributes(["test2", 2])
assert pr.addFeatures([pf1, pf2])

source.setFieldAlias(0, "alias_fldtxt")
source.setFieldAlias(1, "alias_fldint")

exporter = QgsJsonExporter()
exporter.setVectorLayer(source)

expected = """{
"type":"Feature",
"id":0,
"geometry":null,
"properties":{
"alias_fldtxt":"test1",
"alias_fldint":1
}
}"""
self.assertEqual(exporter.exportFeature(pf1), expected)


if __name__ == "__main__":
unittest.main()

0 comments on commit 3f38365

Please sign in to comment.
You can’t perform that action at this time.