|
16 | 16 | get_opendap_nc4, |
17 | 17 | get_value_or_default, |
18 | 18 | move_downloaded_nc4, |
| 19 | + unexecuted_url_requested, |
19 | 20 | ) |
20 | 21 |
|
21 | 22 |
|
@@ -151,13 +152,34 @@ def test_get_opendap_nc4(self, mock_download, mock_move_download): |
151 | 152 | access_token = 'secret_token!!!' |
152 | 153 | expected_data = {'dap4.ce': 'variable'} |
153 | 154 |
|
| 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 | + |
154 | 175 | with self.subTest('Request with variables includes dap4.ce'): |
155 | 176 | output_file = get_opendap_nc4( |
156 | 177 | url, |
157 | 178 | required_variables, |
158 | 179 | output_dir, |
159 | 180 | access_token, |
160 | 181 | self.config, |
| 182 | + 'fake-mimetype', |
161 | 183 | ) |
162 | 184 |
|
163 | 185 | self.assertEqual(output_file, moved_file_name) |
@@ -279,3 +301,29 @@ def test_get_value_or_default(self): |
279 | 301 |
|
280 | 302 | with self.subTest('Value = None returns the supplied default'): |
281 | 303 | 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