@@ -20,6 +20,11 @@ def setUpClass(cls):
2020 cls .launchpad_token_header = 'launchpad-token'
2121 cls .netcdf4_basename = 'f16_ssmis_20210426v7.nc'
2222 cls .netcdf4_url = f'https://example.com/{ cls .netcdf4_basename } '
23+ cls .example_dmr_basename = 'foo_HDF_EOS_granule.hdf'
24+ cls .opendap_url = (
25+ f'https://fake.opendap.earthdata.nasa.gov/{ cls .example_dmr_basename } '
26+ )
27+ cls .opendap_xml_download_url = f'https://fake.opendap.earthdata.nasa.gov/{ cls .example_dmr_basename } .dmr.xml'
2328 cls .query_granule_return = [
2429 {
2530 'links' : [
@@ -30,6 +35,18 @@ def setUpClass(cls):
3035 ]
3136 }
3237 ]
38+ cls .query_granule_return_opendap = [
39+ {
40+ 'links' : [
41+ {
42+ 'rel' : 'http://esipfed.org/ns/fedsearch/1.1/service#' ,
43+ 'title' : 'OPeNDAP request URL (GET DATA : OPENDAP DATA)' ,
44+ 'hreflang' : 'en-US' ,
45+ 'href' : cls .opendap_url ,
46+ }
47+ ]
48+ }
49+ ]
3350 cls .rssmif16d_variables = [
3451 'atmosphere_cloud_liquid_water_content' ,
3552 'atmosphere_water_vapor_content' ,
@@ -53,6 +70,18 @@ def download_granule_side_effect(granule_link, auth_header, out_directory):
5370 netcdf4_file_path = 'tests/unit/data/f16_ssmis_20210426v7.nc'
5471 return copy (netcdf4_file_path , out_directory )
5572
73+ @staticmethod
74+ def download_dmr_side_effect (granule_link , auth_header , out_directory ):
75+ """A helper method that will copy a test dmr file to the temporary
76+ directory being used for a specific test.
77+
78+ Static methods do not have access to class attributes, so the test
79+ file path is defined in this method as well as setUpClass.
80+
81+ """
82+ dmr_file_path = 'tests/unit/data/M2I3NPASM_example.dmr'
83+ return copy (dmr_file_path , out_directory )
84+
5685 @patch ('varinfo.umm_var.publish_umm_var' )
5786 @patch ('varinfo.cmr_search.GranuleQuery' )
5887 @patch ('varinfo.generate_umm_var.download_granule' )
@@ -144,6 +173,52 @@ def test_generate_collection_umm_var_with_publication(
144173 # Ensure the output looks as expected
145174 self .assertSetEqual (set (published_umm_var ), set (expected_concept_ids ))
146175
176+ @patch ('varinfo.umm_var.publish_umm_var' )
177+ @patch ('varinfo.generate_umm_var.get_dmr_xml_url' )
178+ @patch ('varinfo.cmr_search.GranuleQuery' )
179+ @patch ('varinfo.generate_umm_var.download_granule' )
180+ def test_generate_collection_umm_var_dmr (
181+ self ,
182+ mock_download_granule ,
183+ mock_granule_query ,
184+ mock_get_dmr_xml_url ,
185+ mock_publish_umm_var ,
186+ ):
187+ """Test an end-to-end request for a DMR file."""
188+ mock_granule_query .return_value .get .return_value = (
189+ self .query_granule_return_opendap
190+ )
191+
192+ # Add side effect that will copy test file to the temporary directory,
193+ # simulating a download.
194+ mock_download_granule .side_effect = self .download_dmr_side_effect
195+
196+ # Set return value for get_dmr_xml_url
197+ mock_get_dmr_xml_url .return_value = self .opendap_xml_download_url
198+
199+ # Check call arguments when use_dmr=True
200+ generate_collection_umm_var (
201+ self .collection_concept_id ,
202+ self .bearer_token_header ,
203+ use_dmr = True ,
204+ )
205+
206+ mock_get_dmr_xml_url .assert_called_once_with (self .query_granule_return_opendap )
207+ # Ensure the granule query used expected query parameters
208+ mock_granule_query .return_value .parameters .assert_called_once_with (
209+ downloadable = True ,
210+ sort_key = '-start_date' ,
211+ concept_id = self .collection_concept_id ,
212+ )
213+
214+ # Ensure the call to download the granule had correct parameters
215+ mock_download_granule .assert_called_once_with (
216+ self .opendap_xml_download_url , self .bearer_token_header , out_directory = ANY
217+ )
218+
219+ # Check that no attempt was made to publish a UMM-Var record to CMR:
220+ mock_publish_umm_var .assert_not_called ()
221+
147222 @patch ('varinfo.umm_var.publish_umm_var' )
148223 @patch ('varinfo.cmr_search.GranuleQuery' )
149224 @patch ('varinfo.generate_umm_var.download_granule' )
0 commit comments