From 240bdc9dcffb8045fe747072bf1c47c6be5ab76d Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 2 Oct 2024 18:05:14 -0800 Subject: [PATCH 1/6] Only check if results are cloud hosted when there are results --- earthaccess/search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/earthaccess/search.py b/earthaccess/search.py index d4bf94b6..f9368273 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -468,8 +468,8 @@ def get(self, limit: int = 2000) -> List[DataGranule]: RuntimeError: The CMR query failed. """ response = get_results(self.session, self, limit) - - cloud = self._is_cloud_hosted(response[0]) + if response: + cloud = self._is_cloud_hosted(response[0]) return [DataGranule(granule, cloud_hosted=cloud) for granule in response] From c494978ac097bdacc7de505cab43daa9ba148277 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 2 Oct 2024 18:27:21 -0800 Subject: [PATCH 2/6] Update Changelog --- CHANGELOG.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7493b46..5b26d400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,28 @@ # Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Common Changelog](https://common-changelog.org/), +and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + ## [Unreleased] ### Changed - Use built-in `assert` statements instead of `unittest` assertions in integration tests ([#743](https://github.com/nsidc/earthaccess/issues/743)) - (@chuckwondo) + ([@chuckwondo](https://github.com/chuckwondo)) ### Added - Add support for `NETRC` environment variable to override default `.netrc` file location ([#480](https://github.com/nsidc/earthaccess/issues/480)) - (@chuckwondo) + ([@chuckwondo](https://github.com/chuckwondo)) - Add `nox` session for running integration tests locally - ([#815](https://github.com/nsidc/earthaccess/issues/815)) (@chuckwondo) + ([#815](https://github.com/nsidc/earthaccess/issues/815)) ([@chuckwondo](https://github.com/chuckwondo)) - Auto-add comment to PR that requires maintainer to review and re-run integration tests ([#824](https://github.com/nsidc/earthaccess/issues/824)) - (@chuckwondo) + ([@chuckwondo](https://github.com/chuckwondo)) ### Removed @@ -26,6 +31,9 @@ - Integration tests no longer clobber existing `.netrc` file ([#806](https://github.com/nsidc/earthaccess/issues/806)) (@chuckwondo) +- Return an empty list instead of raising an `IndexError` when searches find no results. + ([#839](https://github.com/nsidc/earthaccess/pull/839)) + ([@jhkennedy](https://github.com/jhkennedy)) ## [0.11.0] 2024-10-01 From d5c0346312baebfb8dc3eccf54a224ad289b261e Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 2 Oct 2024 18:29:28 -0800 Subject: [PATCH 3/6] typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b26d400..f53e94a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -The format is based on [Common Changelog](https://common-changelog.org/), +The format is based on [Common Changelog](https://common-changelog.org/) and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] From 544b4d03053537466c73e080f88760df3bdb7e33 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Fri, 4 Oct 2024 05:21:25 -0800 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Chuck Daniels --- CHANGELOG.md | 3 ++- earthaccess/search.py | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f53e94a8..bc892679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,11 +28,12 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html) ### Fixed + - Integration tests no longer clobber existing `.netrc` file ([#806](https://github.com/nsidc/earthaccess/issues/806)) (@chuckwondo) - Return an empty list instead of raising an `IndexError` when searches find no results. - ([#839](https://github.com/nsidc/earthaccess/pull/839)) + ([#526](https://github.com/nsidc/earthaccess/issues/526)) ([@jhkennedy](https://github.com/jhkennedy)) ## [0.11.0] 2024-10-01 diff --git a/earthaccess/search.py b/earthaccess/search.py index f9368273..f2913b23 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -468,8 +468,7 @@ def get(self, limit: int = 2000) -> List[DataGranule]: RuntimeError: The CMR query failed. """ response = get_results(self.session, self, limit) - if response: - cloud = self._is_cloud_hosted(response[0]) + cloud = response and self._is_cloud_hosted(response[0]) return [DataGranule(granule, cloud_hosted=cloud) for granule in response] From b8c470cf1fd579a48670a83c903bca5e410cddd9 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Fri, 4 Oct 2024 05:48:05 -0800 Subject: [PATCH 5/6] Update earthaccess/search.py --- earthaccess/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/search.py b/earthaccess/search.py index f2913b23..3a2b458d 100644 --- a/earthaccess/search.py +++ b/earthaccess/search.py @@ -468,7 +468,7 @@ def get(self, limit: int = 2000) -> List[DataGranule]: RuntimeError: The CMR query failed. """ response = get_results(self.session, self, limit) - cloud = response and self._is_cloud_hosted(response[0]) + cloud = len(response) > 0 and self._is_cloud_hosted(response[0]) return [DataGranule(granule, cloud_hosted=cloud) for granule in response] From 34f4102e2066e01cb0666a0462ffa021ddeec582 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 16 Oct 2024 15:06:19 -0800 Subject: [PATCH 6/6] Add unit test for no results --- .../TestResults.test_no_results.yaml | 519 ++++++++++++++++++ tests/unit/test_results.py | 11 + 2 files changed, 530 insertions(+) create mode 100644 tests/unit/fixtures/vcr_cassettes/TestResults.test_no_results.yaml diff --git a/tests/unit/fixtures/vcr_cassettes/TestResults.test_no_results.yaml b/tests/unit/fixtures/vcr_cassettes/TestResults.test_no_results.yaml new file mode 100644 index 00000000..554e745b --- /dev/null +++ b/tests/unit/fixtures/vcr_cassettes/TestResults.test_no_results.yaml @@ -0,0 +1,519 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Connection: + - keep-alive + Content-Length: + - '0' + method: POST + uri: https://urs.earthdata.nasa.gov/api/users/REDACTED + response: + body: + string: '{"error": "invalid_credentials", "error_description": "Invalid user + credentials"}' + headers: + Cache-Control: + - no-store + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:35 GMT + Expires: + - Fri, 01 Jan 1990 00:00:00 GMT + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Server: + - nginx/1.22.1 + Strict-Transport-Security: + - max-age=31536000 + Transfer-Encoding: + - chunked + Vary: + - Accept + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - e56652c9-ce18-4e95-b1ee-b19f91ed44fd + X-Runtime: + - '0.025636' + X-XSS-Protection: + - 1; mode=block + status: + code: 401 + message: Unauthorized +- request: + body: null + headers: + Accept: + - application/json + Connection: + - keep-alive + Content-Length: + - '0' + method: POST + uri: https://urs.earthdata.nasa.gov/api/users/REDACTED + response: + body: + string: '{"access_token": "REDACTED", "token_type": "Bearer", "expiration_date": + "11/19/2024"}' + headers: + Cache-Control: + - no-store + Connection: + - keep-alive + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:35 GMT + ETag: + - W/"b08130f1127af90959e77139f467048e" + Expires: + - Fri, 01 Jan 1990 00:00:00 GMT + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Server: + - nginx/1.22.1 + Strict-Transport-Security: + - max-age=31536000 + Transfer-Encoding: + - chunked + Vary: + - Accept + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - b2eb5cfb-47de-4f5a-a234-5deab89ec252 + X-Runtime: + - '0.014511' + X-XSS-Protection: + - 1; mode=block + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Connection: + - keep-alive + method: GET + uri: https://urs.earthdata.nasa.gov/profile + response: + body: + string: '' + headers: + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Type: + - text/html; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:36 GMT + Location: + - https://urs.earthdata.nasa.gov/home + Referrer-Policy: + - strict-origin-when-cross-origin + Server: + - nginx/1.22.1 + Set-Cookie: + - _urs-gui_session=5b31f546ba3d54686775c355465efe3c; path=/; expires=Thu, 17 + Oct 2024 22:55:36 GMT; HttpOnly + Strict-Transport-Security: + - max-age=31536000 + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - 4ed1cafb-ca2d-47ce-8eb5-aac97ec6ea57 + X-Runtime: + - '0.029619' + X-XSS-Protection: + - 1; mode=block + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Connection: + - keep-alive + method: GET + uri: https://urs.earthdata.nasa.gov/home + response: + body: + string: "\n\n\n\n\n \n + \ \n \n + \ Earthdata Login\n \n \n\n + \ \n \n \n\n \n \n \n \n \n \n\n \n\n \n + \ \n \n\n + \ \n \n + \ \n\n
\n \n + \
\n
\n
\n + \

Earthdata Login

\n Earthdata Login\n
\n \"Three\n \n
\n\n
\n + \ You must be logged in to access this page\n
\n\n\n\n\n\n\n\n\n + \
\n
\n

\n \n + \ \n \n

\n

\n
\n \n \n

\n

\n + \ \n

\n

\n \n

\n \n

\n \n Register\n

\n + \

\n \n + \ I don’t remember my username\n + \
\n I + don’t remember my password\n
\n \n + \ Help\n

\n
\n\n\n
\n
\n

Get single sign-on access to all your favorite EOSDIS sites

\n + \ Register + for a Profile\n
\n
\n \n By + clicking the Log In button above, you are acknowledging that all Earthdata + Login applications running in DAACs + \n will have access to my profile information. \n \n
\n
\n

\n \n + \ Protection and maintenance of user profile information is described + in\n NASA's + Web Privacy Policy.\n \n

\n
\n
\n + \

\n \n Protection and maintenance of user profile + information is described in\n NASA's + Web Privacy Policy.\n \n

\n
\n
\n + \ \n US Govt Property. Unauthorized use subject to prosecution. + Use subject to monitoring per\n NPD2810.\n + \ \n
\n
\n \n
\n
\n \n\n \n + \ \n \n + \ \n + \ \n + \ \n\n \n \n + \ \n\n \n \n\n" + headers: + Cache-Control: + - no-store + Connection: + - keep-alive + Content-Type: + - text/html; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:36 GMT + ETag: + - W/"8226ad01c41595f19fcc475ec8741def" + Expires: + - Fri, 01 Jan 1990 00:00:00 GMT + Pragma: + - no-cache + Referrer-Policy: + - strict-origin-when-cross-origin + Server: + - nginx/1.22.1 + Set-Cookie: + - _urs-gui_session=5b31f546ba3d54686775c355465efe3c; path=/; expires=Thu, 17 + Oct 2024 22:55:36 GMT; HttpOnly + Strict-Transport-Security: + - max-age=31536000 + Transfer-Encoding: + - chunked + Vary: + - Accept + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Request-Id: + - e2bf8ef2-1765-446b-8b19-0fb8fa0eadcf + X-Runtime: + - '0.009562' + X-XSS-Protection: + - 1; mode=block + content-length: + - '9091' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Connection: + - keep-alive + method: GET + uri: https://cmr.earthdata.nasa.gov/search/granules.umm_json?bounding_box=-95.19%2C30.59%2C-94.99%2C30.79&page_size=0&short_name=OPERA_L3_DSWX-HLS_V1_1.0&temporal%5B%5D=2024-04-30T00%3A00%3A00Z%2C2024-05-31T23%3A59%3A59Z + response: + body: + string: '{"hits": 0, "took": 68, "items": []}' + headers: + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - CMR-Hits, CMR-Request-Id, X-Request-Id, CMR-Scroll-Id, CMR-Search-After, CMR-Timed-Out, + CMR-Shapefile-Original-Point-Count, CMR-Shapefile-Simplified-Point-Count + CMR-Hits: + - '0' + CMR-Request-Id: + - 7fcc5e93-c326-4740-b029-44ea8ba7be48 + CMR-Took: + - '69' + Connection: + - keep-alive + Content-MD5: + - 7ecf8fe28a2feb57798379414d21a110 + Content-SHA1: + - 9fff6efa49d3d93102f51b54802a672214b44813 + Content-Type: + - application/vnd.nasa.cmr.umm_results+json;version=1.6.6; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:38 GMT + Server: + - ServerTokens ProductOnly + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding, User-Agent + Via: + - 1.1 583992e175976bd59a21b4416890271e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - LiA0bWZ4XuJB08BByFlGF38flrZRiarMQhkXVTal83W-vEjNPHCx6A== + X-Amz-Cf-Pop: + - SEA73-P2 + X-Cache: + - Miss from cloudfront + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Request-Id: + - LiA0bWZ4XuJB08BByFlGF38flrZRiarMQhkXVTal83W-vEjNPHCx6A== + X-XSS-Protection: + - 1; mode=block + content-length: + - '31' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Connection: + - keep-alive + method: GET + uri: https://cmr.earthdata.nasa.gov/search/granules.umm_json?bounding_box=-95.19%2C30.59%2C-94.99%2C30.79&page_size=0&short_name=OPERA_L3_DSWX-HLS_V1_1.0&temporal%5B%5D=2024-04-30T00%3A00%3A00Z%2C2024-05-31T23%3A59%3A59Z + response: + body: + string: '{"hits": 0, "took": 65, "items": []}' + headers: + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - CMR-Hits, CMR-Request-Id, X-Request-Id, CMR-Scroll-Id, CMR-Search-After, CMR-Timed-Out, + CMR-Shapefile-Original-Point-Count, CMR-Shapefile-Simplified-Point-Count + CMR-Hits: + - '0' + CMR-Request-Id: + - 7fa7396e-7bda-4d97-921a-2c460bc39a0a + CMR-Took: + - '65' + Connection: + - keep-alive + Content-MD5: + - f54bebd6ea9e4c90e3ac93c18af6f9b0 + Content-SHA1: + - e1a43d971f0207160ce02664a1326fe4f9f7f6ad + Content-Type: + - application/vnd.nasa.cmr.umm_results+json;version=1.6.6; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:38 GMT + Server: + - ServerTokens ProductOnly + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding, User-Agent + Via: + - 1.1 583992e175976bd59a21b4416890271e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - PBQLOHHuI2Y-ly0t-XKlqF1ybt-3iKm-YABcXI7gRA8utHjGWyjiCQ== + X-Amz-Cf-Pop: + - SEA73-P2 + X-Cache: + - Miss from cloudfront + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Request-Id: + - PBQLOHHuI2Y-ly0t-XKlqF1ybt-3iKm-YABcXI7gRA8utHjGWyjiCQ== + X-XSS-Protection: + - 1; mode=block + content-length: + - '31' + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Connection: + - keep-alive + method: GET + uri: https://cmr.earthdata.nasa.gov/search/granules.umm_json?bounding_box=-95.19%2C30.59%2C-94.99%2C30.79&page_size=0&short_name=OPERA_L3_DSWX-HLS_V1_1.0&temporal%5B%5D=2024-04-30T00%3A00%3A00Z%2C2024-05-31T23%3A59%3A59Z + response: + body: + string: '{"hits": 0, "took": 63, "items": []}' + headers: + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - CMR-Hits, CMR-Request-Id, X-Request-Id, CMR-Scroll-Id, CMR-Search-After, CMR-Timed-Out, + CMR-Shapefile-Original-Point-Count, CMR-Shapefile-Simplified-Point-Count + CMR-Hits: + - '0' + CMR-Request-Id: + - 5d3edeac-f5bc-41ff-893d-bd2ca955e981 + CMR-Took: + - '64' + Connection: + - keep-alive + Content-MD5: + - 390e52714889cc4fb51d21ea1ee6aef1 + Content-SHA1: + - 5dfb2d0a3165065c2c0c9a9d754cac7802f5d639 + Content-Type: + - application/vnd.nasa.cmr.umm_results+json;version=1.6.6; charset=utf-8 + Date: + - Wed, 16 Oct 2024 22:55:38 GMT + Server: + - ServerTokens ProductOnly + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + Vary: + - Accept-Encoding, User-Agent + Via: + - 1.1 020978022b22df6352245f09cfbc410c.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - -brPCza6-w6fM6PoPCPQZJxfs-MSjNVIZt3DqsyABzm2DULXb6OPxQ== + X-Amz-Cf-Pop: + - SEA73-P2 + X-Cache: + - Miss from cloudfront + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Request-Id: + - -brPCza6-w6fM6PoPCPQZJxfs-MSjNVIZt3DqsyABzm2DULXb6OPxQ== + X-XSS-Protection: + - 1; mode=block + content-length: + - '31' + status: + code: 200 + message: OK +version: 1 diff --git a/tests/unit/test_results.py b/tests/unit/test_results.py index b69f5685..135eaa7d 100644 --- a/tests/unit/test_results.py +++ b/tests/unit/test_results.py @@ -96,6 +96,17 @@ def _get_vcr(self, **kwargs): return myvcr + def test_no_results(self): + """If we search for a collection that doesn't exist, we should get no results.""" + granules = earthaccess.search_data( + # STAC collection name; correct short name is OPERA_L3_DSWX-HLS_V1 + # Example discussed in: https://github.com/nsidc/earthaccess/pull/839 + short_name="OPERA_L3_DSWX-HLS_V1_1.0", + bounding_box=(-95.19, 30.59, -94.99, 30.79), + temporal=("2024-04-30", "2024-05-31"), + ) + assert len(granules) == 0 + def test_data_links(self): granules = earthaccess.search_data( short_name="SEA_SURFACE_HEIGHT_ALT_GRIDS_L4_2SATS_5DAY_6THDEG_V_JPL2205",