Skip to content

Commit

Permalink
Fix parsing of includefield query parameters
Browse files Browse the repository at this point in the history
There can be more than one ``includefield`` key-value pair in the query
string.
  • Loading branch information
hackermd committed Mar 26, 2018
1 parent 2809ea2 commit 95fe9ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dicomweb_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
17 changes: 17 additions & 0 deletions src/dicomweb_client/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 95fe9ca

Please sign in to comment.