Skip to content

Commit 9d6f685

Browse files
committed
HARMONY-1929: Test that POST body matches opendap query
1 parent 3c27921 commit 9d6f685

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

harmony/harmony.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ def _download_file(self, url: str, directory: str = '', overwrite: bool = False)
13021302
chunksize = int(self.config.DOWNLOAD_CHUNK_SIZE)
13031303
session = self._session()
13041304
filename = self.get_download_filename_from_url(url)
1305+
new_url = url
13051306

13061307
if directory:
13071308
filename = os.path.join(directory, filename)
@@ -1317,12 +1318,12 @@ def _download_file(self, url: str, directory: str = '', overwrite: bool = False)
13171318
is_opendap = parse_result.netloc.startswith('opendap')
13181319
method = 'post' if is_opendap else 'get'
13191320
if is_opendap: # remove the query params from the URL and convert to dict
1320-
url = parse.urlunparse(parse_result._replace(query=""))
1321+
new_url = parse.urlunparse(parse_result._replace(query=""))
13211322
data_dict = dict(parse.parse_qsl(parse.urlsplit(url).query))
13221323
headers = {
13231324
"Accept-Encoding": "identity"
13241325
}
1325-
with getattr(session, method)(url, data=data_dict, stream=True, headers=headers) as r:
1326+
with getattr(session, method)(new_url, data=data_dict, stream=True, headers=headers) as r:
13261327
with open(filename, 'wb') as f:
13271328
shutil.copyfileobj(r.raw, f, length=chunksize)
13281329
if verbose and verbose.upper() == 'TRUE':

tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,16 +1019,16 @@ def test_download_opendap_file():
10191019
file_obj.write(expected_data)
10201020
file_obj.seek(0)
10211021
with responses.RequestsMock() as resp_mock:
1022-
resp_mock.add(responses.POST, path + expected_filename, body=file_obj.read(), stream=True)
1022+
resp_mock.add(responses.POST, path + expected_filename, body=file_obj.read(), stream=True,
1023+
match=[responses.matchers.urlencoded_params_matcher({"dap4.ce": "/ds_surf_type[0:1:4]"})])
10231024
client = Client(should_validate_auth=False)
10241025
actual_output = client._download_file(url, overwrite=False)
10251026

1026-
# TODO assert POST body params are as expected
1027-
10281027
assert actual_output == expected_filename
10291028
with open(expected_filename, 'rb') as temp_file:
10301029
data = temp_file.read()
10311030
assert data == expected_data
1031+
10321032
os.unlink(actual_output)
10331033

10341034
def test_download_all(mocker):

0 commit comments

Comments
 (0)