Skip to content

Commit

Permalink
Reinstate test_download_granules_without_subsetting (#581)
Browse files Browse the repository at this point in the history
Ensure that granules can be ordered from NSIDC and downloaded with the `subset=False` option.

Also fix a possible race condition in case the NSIDC order status is completed right at the start (e.g. when order was cached/done already).

Co-authored-by: Jessica Scheick <[email protected]>
  • Loading branch information
weiji14 and JessicaS11 authored Sep 3, 2024
1 parent 572e48c commit 6d6a085
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
5 changes: 5 additions & 0 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ def place_order(
status = statuslist[0]
print("Initial status of your order request at NSIDC is: ", status)

# If status is already finished without going into pending/processing
if status.startswith("complete"):
loop_response = self.session.get(statusURL)
loop_root = ET.fromstring(loop_response.content)

# Continue loop while request is still processing
while status == "pending" or status == "processing":
print(
Expand Down
47 changes: 42 additions & 5 deletions icepyx/tests/test_behind_NSIDC_API_login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
Integration tests that require authentication to Earthdata login.
"""

import glob
import json
import os

Expand Down Expand Up @@ -49,8 +54,40 @@ def test_download_granules_with_subsetting(reg, session):
reg.download_granules(path)


# def test_download_granules_without_subsetting(reg_a, session):
# path = './downloads'
# reg_a.order_granules(session, subset=False)
# reg_a.download_granules(session, path)
# #check that the max extent of the downloaded granules isn't subsetted
def test_download_granules_without_subsetting(reg, session, capsys):
"""
Test that granules can be ordered from NSIDC and downloaded with the `subset=False`
option.
"""
path = "./downloads"

reg.order_granules(verbose=False, subset=False, email=False)
out, err = capsys.readouterr() # capture stdout and stderr
assert out.startswith(
"Total number of data order requests is 1 for 3 granules.\n"
"Data request 1 of 1 is submitting to NSIDC\n"
)
assert err == ""

assert reg.reqparams == {
"client_string": "icepyx",
"include_meta": "Y",
"page_num": 0,
"page_size": 2000,
"request_mode": "async",
"short_name": "ATL06",
"version": "006",
}
assert len(reg.granules.orderIDs) == 2
assert int(reg.granules.orderIDs[0]) >= 5_000_000_000_000

reg.download_granules(path=path)
# check that there are the right number of files of the correct size
assert len(glob.glob(pathname=f"{path}/ATL06_201902*.iso.xml")) == 3
h5_paths = sorted(glob.glob(pathname=f"{path}/ATL06_201902*.h5"))
assert len(h5_paths) == 3
assert [os.path.getsize(filename=p) for p in h5_paths] == [
53228429, # 50.8 MiB
65120027, # 62.1 MiB
49749227, # 47.4 MiB
]

0 comments on commit 6d6a085

Please sign in to comment.