def test_limited_search(self, urlopen_mock): """ Test that the limit parameter will not allow more data to be returned. CMR may return more data on the last page if a page value is specified. For this test, 10 results are returned and the API will opt to return fewer to the caller """ # Setup recorded_data_file = 'test/data/cmr/search/ten_results_from_ghrc.json' urlopen_mock.return_value = valid_cmr_response(recorded_data_file) # tests for index in [1,2,5,10]: result = coll.search({'provider':'GHRC_CLOUD'}, limit=index) self.assertEqual(index, len(result)) over_result = coll.search({'provider':'GHRC_CLOUD'}, limit=11) self.assertEqual(10, len(over_result))
def test_logged_search(self, urlopen_mock): """ Test that search still runs as expected when logging is turned on """ # Setup recorded_file = tutil.resolve_full_path( '../data/cmr/search/ten_results_from_ghrc.json') urlopen_mock.return_value = valid_cmr_response(recorded_file) # Test with self.assertLogs(coll.scom.logger, level='DEBUG') as log_collector: coll.set_logging_to("DEBUG") expected = [ 'INFO:cmr.search.common: - POST: https://cmr.earthdata.' 'nasa.gov/search/collections?page_size=1', 'INFO:cmr.search.common:Total records downloaded was 10' ' of 2038 which took 10ms.' ] coll.search({'provider': 'GHRC_CLOUD'}, limit=1) self.assertEqual(expected, log_collector.output)
def _test_live_search(self): """ Make a live call to CMR, this is not normally included in the test suite. Turn it on for doing some local tests """ params = {} config = {} #params["provider"] = "SEDAC" params['keyword'] = 'salt' results = coll.search(query=params, filters=[coll.collection_core_fields, coll.drop_fields('EntryTitle')], limit=None, config=config) for i in results: print (i)
def main(): """The commands main method""" print("running version: {}".format(str(cmr_imp.BUILD))) print(style_input("Enter in a free text search:")) ask = input(">") params = {} if len(ask) > 0: params = {'keyword': ask} else: print("No input given, use a default search") params = {'fake-parameter': 'value for fake parameter'} #params = {'polygon': '10,10,30,10,30,20,10,20,10,10'} print('Searching for {}'.format(params)) coll.set_logging_to('DEBUG') time_start = time.time() raw_results = coll.search(params, limit=5000, config={'env': 'uat'}) time_stop = time.time() durration = time_stop - time_start if 'errors' in raw_results: output_format = style_error('Error while searching: {}') output_result = raw_results['errors'] else: filters = [ coll.collection_core_fields, coll.drop_fields('EntryTitle'), coll.drop_fields('Version'), #coll.drop_fields('ShortName'), coll.drop_fields('concept-id') ] output_format = style_output() output_result = coll.apply_filters(filters, raw_results) #output_result = raw_results for item in output_result: print(output_format.format(item)) print("It took {} seconds to pull {} records.".format( durration, len(raw_results)))
def test_search(self, urlopen_mock): """ def search(query=None, filters=None, limit=None, config=None): """ # Setup recorded_file = tutil.resolve_full_path( '../data/cmr/search/one_cmr_result.json') urlopen_mock.return_value = valid_cmr_response(recorded_file) full_result = coll.search({'provider': 'SEDAC'}, limit=1) self.assertEqual(1, len(full_result)) # Unfiltered Test unfiltered_result = coll.search({'provider': 'SEDAC'}, filters=[coll.all_fields], limit=1) self.assertEqual(full_result, unfiltered_result) # Meta filter Test meta_results = coll.search({'provider': 'SEDAC'}, filters=[coll.meta_fields], limit=1) expected = [{ 'revision-id': 31, 'deleted': False, 'format': 'application/dif10+xml', 'provider-id': 'SEDAC', 'user-id': 'mhansen', 'has-formats': False, 'has-spatial-subsetting': False, 'native-id': '2000 Pilot Environmental Sustainability Index (ESI)', 'has-transforms': False, 'has-variables': False, 'concept-id': 'C179001887-SEDAC', 'revision-date': '2019-07-26T18:37:52.861Z', 'granule-count': 0, 'has-temporal-subsetting': False, 'concept-type': 'collection' }] self.assertEqual(expected, meta_results) # UMM filter Test umm_results = coll.search({'provider': 'SEDAC'}, filters=[coll.umm_fields], limit=1) expected = '2000 Pilot Environmental Sustainability Index (ESI)' self.assertEqual(expected, umm_results[0]['EntryTitle']) self.assertEqual(28, len(umm_results[0].keys())) # Collection ID Filter Test cid_results = coll.search({'provider': 'SEDAC'}, filters=[coll.concept_id_fields], limit=1) expected = [{'concept-id': 'C179001887-SEDAC'}] self.assertEqual(expected, cid_results) # Drop Filter Test drop_results = coll.search( {'provider': 'SEDAC'}, filters=[ coll.meta_fields, coll.drop_fields('has-temporal-subsetting'), coll.drop_fields('revision-date'), coll.drop_fields('has-spatial-subsetting') ], limit=1) expected = [{'concept-id': 'C179001887-SEDAC'}] meta_count = len(meta_results[0].keys()) #from test above drop_count = len(drop_results[0].keys()) self.assertEqual(3, meta_count - drop_count) #IDs Filter Test ids_results = coll.search({'provider': 'SEDAC'}, filters=[coll.collection_core_fields], limit=1) expected = [{ 'concept-id': 'C179001887-SEDAC', 'ShortName': 'CIESIN_SEDAC_ESI_2000', 'Version': '2000.00', 'EntryTitle': '2000 Pilot Environmental Sustainability Index (ESI)' }] self.assertEqual(expected, ids_results) # Granule IDs Filter Tests gids_results = coll.search( {'provider': 'SEDAC'}, filters=[coll.collection_ids_for_granules_fields], limit=1) expected = [{ 'provider-id': 'SEDAC', 'concept-id': 'C179001887-SEDAC', 'ShortName': 'CIESIN_SEDAC_ESI_2000', 'Version': '2000.00', 'EntryTitle': '2000 Pilot Environmental Sustainability Index (ESI)' }] self.assertEqual(expected, gids_results)