From 95fe9cacaee4ae8f2c2d246f42215bbafe2f751a Mon Sep 17 00:00:00 2001 From: hackermd Date: Mon, 26 Mar 2018 12:01:03 -0400 Subject: [PATCH] Fix parsing of ``includefield`` query parameters There can be more than one ``includefield`` key-value pair in the query string. --- src/dicomweb_client/api.py | 3 ++- src/dicomweb_client/tests/test_api.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/dicomweb_client/api.py b/src/dicomweb_client/api.py index 8ded39f..8c618d6 100644 --- a/src/dicomweb_client/api.py +++ b/src/dicomweb_client/api.py @@ -256,10 +256,11 @@ def _parse_query_parameters(self, fuzzymatching, limit, offset, else: params['fuzzymatching'] = 'false' if fields is not None: + params['includefield'] = list() for field in set(fields): if not(isinstance(field, str)): raise TypeError('Elements of "fields" must be a string.') - params['includefield'] = field + params['includefield'].append(field) for field, criterion in search_filters.items(): if not(isinstance(field, str)): raise TypeError('Keys of "search_filters" must be strings.') diff --git a/src/dicomweb_client/tests/test_api.py b/src/dicomweb_client/tests/test_api.py index cdea196..397b9a3 100644 --- a/src/dicomweb_client/tests/test_api.py +++ b/src/dicomweb_client/tests/test_api.py @@ -99,6 +99,23 @@ def test_search_instances_limit_offset(httpserver, client, cache_dir): assert request.accept_mimetypes == [('application/dicom+json', 1)] +def test_search_instances_includefields(httpserver, client, cache_dir): + headers = {'content-type': 'application/dicom+json'} + httpserver.serve_content(content='', code=200, headers=headers) + f1 = 'StudyInstanceUID' + f2 = 'SeriesInstanceUID' + client.search_instances(fields={f1, f2}) + request = httpserver.requests[0] + query_string_opt_1 = 'includefield={}&includefield={}'.format(f1, f2) + query_string_opt_2 = 'includefield={}&includefield={}'.format(f2, f1) + assert ( + request.query_string.decode() == query_string_opt_1 or + request.query_string.decode() == query_string_opt_2 + ) + assert request.path == '/instances' + assert request.accept_mimetypes == [('application/dicom+json', 1)] + + def test_retrieve_instance_metadata(httpserver, client, cache_dir): cache_filename = os.path.join(cache_dir, 'retrieve_instance_metadata.json') with open(cache_filename, 'r') as f: