Skip to content

Commit

Permalink
extended json type server tests
Browse files Browse the repository at this point in the history
not working because of the \n in the response
  • Loading branch information
signedav committed Oct 18, 2018
1 parent 4f55e9d commit d34fdf2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -48,15 +48,18 @@ class TestQgsServerWMSTestBase(QgsServerTestBase):
# Set to True to re-generate reference files for this class
regenerate_reference = False

def wms_request_compare(self, request, extra=None, reference_file=None, project='test_project.qgs', version='1.3.0'):
def wms_request(self, request, extra=None, project='test_project.qgs', version='1.3.0'):
project = self.testdata_path + project
assert os.path.exists(project), "Project file not found: " + project

query_string = 'https://www.qgis.org/?MAP=%s&SERVICE=WMS&VERSION=%s&REQUEST=%s' % (urllib.parse.quote(project), version, request)
if extra is not None:
query_string += extra
header, body = self._execute_request(query_string)
response = header + body
return (header, body, query_string)

def wms_request_compare(self, request, extra, reference_file=None, project='test_project.qgs', version='1.3.0'):
response_header, response_body, query_string = self.wms_request(request, extra, project, version)
response = response_header + response_body
reference_path = self.testdata_path + (request.lower() if not reference_file else reference_file) + '.txt'
self.store_reference(reference_path, response)
f = open(reference_path, 'rb')
Expand Down
38 changes: 38 additions & 0 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -428,5 +428,43 @@ def testGetFeatureInfoPostgresTypes(self):
'get_postgres_types_json_dict',
'test_project_postgres_types.qgs')

#compare decoded json field list
response_header, response_body, query_string = self.wms_request('GetFeatureInfo',
'&layers=json' +
'&info_format=text%2Fxml' +
'&srs=EPSG%3A3857' +
'&QUERY_LAYERS=json' +
'&FILTER=json' + urllib.parse.quote(':"pk" = 1'),
'test_project_postgres_types.qgs')
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])
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])

#compare decoded json field dict
response_header, response_body, query_string = self.wms_request('GetFeatureInfo',
'&layers=json' +
'&info_format=text%2Fxml' +
'&srs=EPSG%3A3857' +
'&QUERY_LAYERS=json' +
'&FILTER=json' + urllib.parse.quote(':"pk" = 2'),
'test_project_postgres_types.qgs')
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})
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})

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

0 comments on commit d34fdf2

Please sign in to comment.