extended json type server tests

not working because of the \n in the response
This commit is contained in:
signedav 2018-10-18 08:54:24 +02:00
parent 4f55e9d8a2
commit d34fdf277d
2 changed files with 44 additions and 3 deletions

View File

@ -48,15 +48,18 @@ class TestQgsServerWMSTestBase(QgsServerTestBase):
# Set to True to re-generate reference files for this class # Set to True to re-generate reference files for this class
regenerate_reference = False 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 project = self.testdata_path + project
assert os.path.exists(project), "Project file not found: " + 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) 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: if extra is not None:
query_string += extra query_string += extra
header, body = self._execute_request(query_string) 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' reference_path = self.testdata_path + (request.lower() if not reference_file else reference_file) + '.txt'
self.store_reference(reference_path, response) self.store_reference(reference_path, response)
f = open(reference_path, 'rb') f = open(reference_path, 'rb')

View File

@ -428,5 +428,43 @@ class TestQgsServerWMSGetFeatureInfo(TestQgsServerWMSTestBase):
'get_postgres_types_json_dict', 'get_postgres_types_json_dict',
'test_project_postgres_types.qgs') '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__': if __name__ == '__main__':
unittest.main() unittest.main()