Skip to content

Commit 545ddcf

Browse files
committed
DAS-2446 - Add get_opendap_nc4 subtest and new unexecuted_url_requested unit tests.
1 parent 979fa46 commit 545ddcf

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

tests/unit/test_adapter.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,45 @@ def create_message(
8080

8181
return Message(json.dumps(message_content))
8282

83+
@patch('hoss.adapter.unexecuted_url_requested')
84+
def test_opendap_url_request(
85+
self,
86+
mock_unexecuted_url_requested,
87+
mock_stage,
88+
mock_subset_granule,
89+
mock_get_mimetype,
90+
):
91+
"""A request that returns an unexecuted OPeNDAP request URL instead
92+
of subset data.
93+
94+
"""
95+
mock_subset_granule.return_value = (
96+
'https://opendap.earthdata.nasa.gov/requst_url'
97+
)
98+
mock_unexecuted_url_requested.return_value = True
99+
100+
message = self.create_message(
101+
'C123456789-EEDTEST',
102+
'short_name',
103+
['variable'],
104+
'some_user',
105+
)
106+
107+
hoss = HossAdapter(message, config=self.config, catalog=self.africa_stac)
108+
109+
with patch.object(HossAdapter, 'process_item', self.process_item_spy):
110+
hoss.invoke()
111+
112+
mock_subset_granule.assert_called_once_with(
113+
self.africa_granule_url,
114+
message.sources[0],
115+
ANY,
116+
hoss.message,
117+
hoss.config,
118+
)
119+
mock_stage.assert_not_called()
120+
mock_get_mimetype.assert_not_called()
121+
83122
def test_temporal_request(self, mock_stage, mock_subset_granule, mock_get_mimetype):
84123
"""A request that specifies a temporal range should result in a
85124
temporal subset.

tests/unit/test_utilities.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
get_opendap_nc4,
1717
get_value_or_default,
1818
move_downloaded_nc4,
19+
unexecuted_url_requested,
1920
)
2021

2122

@@ -151,13 +152,34 @@ def test_get_opendap_nc4(self, mock_download, mock_move_download):
151152
access_token = 'secret_token!!!'
152153
expected_data = {'dap4.ce': 'variable'}
153154

155+
with self.subTest('Request with OPeNDAP URL mimetype'):
156+
opendap_url_mimetype = 'application/x-netcdf4;profile="opendap_url"'
157+
output_url = get_opendap_nc4(
158+
url,
159+
required_variables,
160+
output_dir,
161+
access_token,
162+
self.config,
163+
opendap_url_mimetype,
164+
)
165+
self.assertEqual(
166+
'https://opendap.earthdata.nasa.gov/granule.dap.nc4?dap4.ce=variable',
167+
output_url,
168+
)
169+
mock_download.assert_not_called()
170+
mock_move_download.assert_not_called()
171+
172+
mock_download.reset_mock()
173+
mock_move_download.reset_mock()
174+
154175
with self.subTest('Request with variables includes dap4.ce'):
155176
output_file = get_opendap_nc4(
156177
url,
157178
required_variables,
158179
output_dir,
159180
access_token,
160181
self.config,
182+
'fake-mimetype',
161183
)
162184

163185
self.assertEqual(output_file, moved_file_name)
@@ -279,3 +301,29 @@ def test_get_value_or_default(self):
279301

280302
with self.subTest('Value = None returns the supplied default'):
281303
self.assertEqual(get_value_or_default(None, 20), 20)
304+
305+
def test_unexecuted_url_requested(self):
306+
"""Ensure that True is returned when a valid OPeNDAP URL format
307+
string is in the Harmony message, otherwise False should be returned.
308+
309+
"""
310+
with self.subTest('Valid opendap_url format 1'):
311+
self.assertTrue(
312+
unexecuted_url_requested('application/x-netcdf4; profile="opendap_url"')
313+
)
314+
315+
with self.subTest('Valid opendap_url format 2'):
316+
self.assertTrue(
317+
unexecuted_url_requested('application/x-netcdf4;profile="opendap_url"')
318+
)
319+
320+
with self.subTest('Valid opendap_url format 3'):
321+
self.assertTrue(
322+
unexecuted_url_requested('application/x-netcdf4;profile=opendap_url')
323+
)
324+
325+
with self.subTest('NetCDF4 format'):
326+
self.assertFalse(unexecuted_url_requested('application/x-netcdf4'))
327+
328+
with self.subTest('Some other format'):
329+
self.assertFalse(unexecuted_url_requested('fake-mimetype'))

0 commit comments

Comments
 (0)