@@ -83,26 +83,114 @@ def assert_valid_request_data(
8383 self .assertSetEqual (requested_variables , expected_variables )
8484
8585 def assert_expected_output_catalog (
86- self , catalog : Catalog , expected_href : str , expected_title : str
86+ self ,
87+ catalog : Catalog ,
88+ expected_href : str ,
89+ expected_title : str ,
90+ expected_mimetype = 'application/x-netcdf4' ,
8791 ):
8892 """Check the contents of the Harmony output STAC. It should have a
8993 single data item, containing an asset with the supplied URL and
9094 title.
9195
9296 """
9397 items = list (catalog .get_items ())
98+
9499 self .assertEqual (len (items ), 1 )
95100 self .assertListEqual (list (items [0 ].assets .keys ()), ['data' ])
96- self .assertDictEqual (
97- items [0 ].assets ['data' ].to_dict (),
101+
102+ actual_catalog = items [0 ].assets ['data' ].to_dict ()
103+ expected_catalog = {
104+ 'href' : expected_href ,
105+ 'title' : expected_title ,
106+ 'type' : expected_mimetype ,
107+ 'roles' : ['data' ],
108+ }
109+
110+ # Check all the dictionary values match except for the href value.
111+ self .assertTrue (
112+ all (
113+ actual_catalog [key ] == expected_catalog [key ]
114+ for key in actual_catalog
115+ if key != 'href'
116+ )
117+ )
118+
119+ # The href value must be compared separately because it can contain
120+ # an constraint expression in the case where an unexecuted OPeNDAP URL
121+ # is requested, where the variable order is not consistent.
122+ self .assertEqual (
123+ sorted (actual_catalog ['href' ]), sorted (expected_catalog ['href' ])
124+ )
125+
126+ @patch ('hoss.utilities.uuid4' )
127+ @patch ('hoss.adapter.mkdtemp' )
128+ @patch ('shutil.rmtree' )
129+ @patch ('hoss.utilities.util_download' )
130+ @patch ('hoss.adapter.stage' )
131+ def test_opendap_url_end_to_end (
132+ self , mock_stage , mock_util_download , mock_rmtree , mock_mkdtemp , mock_uuid4
133+ ):
134+ """Ensure HOSS will run an unexecuted OPeNDAP URL request end-to-end,
135+ only mocking the HTTP responses, and the output interactions
136+ with Harmony.
137+
138+ """
139+ expected_title = 'OPeNAP Request URL'
140+ expected_dap4 = '.dap.nc4?dap4.ce=%2Flongitude%5B60%3A119%5D%3B%2Fwind_speed%5B%5D%5B540%3A599%5D%5B60%3A119%5D%3B%2Flatitude%5B540%3A599%5D%3B%2Ftime'
141+ expected_opendap_url = f'{ self .granule_url } { expected_dap4 } '
142+
143+ mock_uuid4 .return_value = Mock (hex = 'uuid' )
144+ mock_mkdtemp .return_value = self .tmp_dir
145+
146+ mimetype = 'application/x-netcdf4;profile=opendap_url'
147+
148+ dmr_path = write_dmr (self .tmp_dir , self .rssmif16d_dmr )
149+
150+ dimensions_path = f'{ self .tmp_dir } /dimensions.nc4'
151+ copy ('tests/data/f16_ssmis_lat_lon.nc' , dimensions_path )
152+
153+ all_variables_path = f'{ self .tmp_dir } /variables.nc4'
154+ copy ('tests/data/f16_ssmis_geo.nc' , all_variables_path )
155+
156+ mock_util_download .side_effect = [dmr_path , dimensions_path , all_variables_path ]
157+
158+ message = Message (
98159 {
99- 'href' : expected_href ,
100- 'title' : expected_title ,
101- 'type' : 'application/x-netcdf4' ,
102- 'roles' : ['data' ],
103- },
160+ 'accessToken' : 'fake-token' ,
161+ 'callback' : 'https://example.com/' ,
162+ 'sources' : [
163+ {
164+ 'collection' : 'C1234567890-EEDTEST' ,
165+ 'shortName' : 'RSSMIF16D' ,
166+ 'variables' : [
167+ {
168+ 'id' : '' ,
169+ 'name' : self .rssmif16d_variable ,
170+ 'fullPath' : self .rssmif16d_variable ,
171+ }
172+ ],
173+ }
174+ ],
175+ 'stagingLocation' : self .staging_location ,
176+ 'subset' : {'bbox' : [15 , 45 , 30 , 60 ]},
177+ 'format' : {'mime' : mimetype },
178+ 'user' : 'auser' ,
179+ }
104180 )
105181
182+ hoss = HossAdapter (message , config = config (False ), catalog = self .input_stac )
183+
184+ _ , output_catalog = hoss .invoke ()
185+
186+ # Ensure that there is a single item in the output catalog with the
187+ # expected asset:
188+ self .assert_expected_output_catalog (
189+ output_catalog , expected_opendap_url , expected_title , mimetype
190+ )
191+ mock_stage .assert_not_called ()
192+ mock_rmtree .assert_called_once_with (self .tmp_dir )
193+
106194 @patch ('hoss.utilities.uuid4' )
107195 @patch ('hoss.adapter.mkdtemp' )
108196 @patch ('shutil.rmtree' )
0 commit comments