Skip to content

Commit

Permalink
Fix content type of post request messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hackermd committed May 3, 2020
1 parent 1cd9301 commit 2ec6c87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ max_line_length = 80
ignore = E402 F401 W504 E121 E125 E241
statistics = True

[mypy]
warn_unreachable = True

[mypy-google.auth.*]
ignore_missing_imports = True

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'google-oauth>=1.0',
],
},
python_requires='>3.5',
install_requires=[
'pydicom>=1.0',
'requests>=2.18',
Expand Down
8 changes: 3 additions & 5 deletions src/dicomweb_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ def _create_dataelement(
elem_value = value[0].split('\\')
else:
elem_value = value
if value is None:
logger.warning('missing value for data element "{}"'.format(tag))
try:
return pydicom.dataelem.DataElement(tag=tag, value=elem_value, VR=vr)
except Exception:
Expand Down Expand Up @@ -375,7 +373,7 @@ def __init__(
port = match.group('port')
except AttributeError:
raise ValueError('Malformed URL: {}'.format(self.base_url))
if port is not None:
if port:
self.port = int(port)
else:
if self.protocol == 'http':
Expand Down Expand Up @@ -836,7 +834,7 @@ def _assert_media_type_is_valid(self, media_type: str):

def _build_range_header_field_value(
self,
byte_range: Tuple[int, int]
byte_range: Optional[Tuple[int, int]]
) -> str:
'''Builds a range header field value for HTTP GET request messages.
Expand Down Expand Up @@ -1436,7 +1434,7 @@ def _invoke_post_request(
data: bytes,
headers: Optional[Dict[str, str]] = None
) -> requests.models.Response:
return self._session.post(url, headers, data)
return self._session.post(url, data=data, headers=headers)

if self._chunk_size is not None and len(data) > self._chunk_size:
logger.info('store data in chunks using chunked transfer encoding')
Expand Down
8 changes: 8 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ def test_store_instance_error_with_retries(httpserver, client, cache_dir):
with pytest.raises(RetryError):
client.store_instances([dataset])
assert len(httpserver.requests) == max_attempts
request = httpserver.requests[0]
assert request.headers['Content-Type'].startswith(
'multipart/related; type="application/dicom"'
)


def test_store_instance_error_with_no_retries(httpserver, client, cache_dir):
Expand All @@ -634,6 +638,10 @@ def test_store_instance_error_with_no_retries(httpserver, client, cache_dir):
with pytest.raises(HTTPError):
client.store_instances([dataset])
assert len(httpserver.requests) == 1
request = httpserver.requests[0]
assert request.headers['Content-Type'].startswith(
'multipart/related; type="application/dicom"'
)


def test_load_json_dataset_da(httpserver, client, cache_dir):
Expand Down

0 comments on commit 2ec6c87

Please sign in to comment.