From 34f4102e2066e01cb0666a0462ffa021ddeec582 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Wed, 16 Oct 2024 15:06:19 -0800 Subject: [PATCH] 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",