Skip to content

Commit

Permalink
json decoding of values
Browse files Browse the repository at this point in the history
before comparing them with the python structs
  • Loading branch information
signedav committed Oct 18, 2018
1 parent d34fdf2 commit 7026dfa
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -26,6 +26,9 @@
import urllib.parse
import urllib.error

import xml.etree.ElementTree as ET
import json

from qgis.testing import unittest
from qgis.PyQt.QtCore import QSize

Expand Down Expand Up @@ -439,13 +442,13 @@ def testGetFeatureInfoPostgresTypes(self):
root = ET.fromstring(response_body)
for attribute in root.iter('Attribute'):
if attribute.get('name') == 'jvalue':
self.assertIsInstance(attribute.get('value'), list)
self.assertEqual(attribute.get('value'), [1, 2, 3])
self.assertEqual(attribute.get('value'), [1.0, 2.0, 3.0])
self.assertIsInstance(json.loads(attribute.get('value')), list)
self.assertEqual(json.loads(attribute.get('value')), [1, 2, 3])
self.assertEqual(json.loads(attribute.get('value')), [1.0, 2.0, 3.0])
if attribute.get('name') == 'jbvalue':
self.assertIsInstance(attribute.get('value'), list)
self.assertEqual(attribute.get('value'), [4, 5, 6])
self.assertEqual(attribute.get('value'), [4.0, 5.0, 6.0])
self.assertIsInstance(json.loads(attribute.get('value')), list)
self.assertEqual(json.loads(attribute.get('value')), [4, 5, 6])
self.assertEqual(json.loads(attribute.get('value')), [4.0, 5.0, 6.0])

#compare decoded json field dict
response_header, response_body, query_string = self.wms_request('GetFeatureInfo',
Expand All @@ -458,13 +461,13 @@ def testGetFeatureInfoPostgresTypes(self):
root = ET.fromstring(response_body)
for attribute in root.iter('Attribute'):
if attribute.get('name') == 'jvalue':
self.assertIsInstance(attribute.get('value'), dict)
self.assertEqual(attribute.get('value'), {'a': 1, 'b': 2})
self.assertEqual(attribute.get('value'), {'a': 1.0, 'b': 2.0})
self.assertIsInstance(json.loads(attribute.get('value')), dict)
self.assertEqual(json.loads(attribute.get('value')), {'a': 1, 'b': 2})
self.assertEqual(json.loads(attribute.get('value')), {'a': 1.0, 'b': 2.0})
if attribute.get('name') == 'jbvalue':
self.assertIsInstance(attribute.get('value'), dict)
self.assertEqual(attribute.get('value'), {'c': 4, 'd': 5})
self.assertEqual(attribute.get('value'), {'c': 4.0, 'd': 5.0})
self.assertIsInstance(json.loads(attribute.get('value')), dict)
self.assertEqual(json.loads(attribute.get('value')), {'c': 4, 'd': 5})
self.assertEqual(json.loads(attribute.get('value')), {'c': 4.0, 'd': 5.0})

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

0 comments on commit 7026dfa

Please sign in to comment.