Skip to content

Commit c9a4076

Browse files
authored
Merge pull request #178 from podaac/feature/PODAAC-6303
[Feature/PODAAC-6303][issue/167] Fixed issue where -gr and -sd/-ed (temporal) cannot be used together as a query
2 parents d6953f2 + cf1aac7 commit c9a4076

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
## [Unreleased]
77
### Added
88
- Added error messages to inform user if .harmony file is formatted incorrectly or missing a key
9+
### Fixed
10+
- **PODAAC-6303 (issues/167)**
11+
- Fixed issue where -gr and -sd/-ed (temporal) cannot be used together as a query
912

1013
## [1.15.2]
1114
### Fixed

subscriber/podaac_data_downloader.py

+24-30
Original file line numberDiff line numberDiff line change
@@ -213,55 +213,49 @@ def cmr_downloader(args, token, data_path):
213213
if args.offset:
214214
ts_shift = timedelta(hours=int(args.offset))
215215

216+
# Base param values
217+
params = [
218+
('page_size', page_size),
219+
('sort_key', "-start_date"),
220+
('provider', provider),
221+
('ShortName', short_name)
222+
]
223+
216224
if search_cycles is not None:
217225
cmr_cycles = search_cycles
218-
params = [
219-
('page_size', page_size),
220-
('provider', provider),
221-
('ShortName', short_name),
222-
('token', token),
223-
]
224226
for v in cmr_cycles:
225227
params.append(("cycle[]", v))
226228
if args.verbose:
227229
logging.info("cycles: " + str(cmr_cycles))
228230

229-
elif granule is not None:
230-
#This line is added to strip out the extensions. Not sure if this works across the board for all collections but it seem to work on few collections that were tested.
231-
cmr_granule = granule.rsplit( ".", 1 )[ 0 ]
232-
params = [
233-
('page_size', page_size),
234-
('sort_key', "-start_date"),
235-
('provider', provider),
236-
('ShortName', short_name),
237-
('GranuleUR[]', cmr_granule),
238-
('token', token),
239-
]
240-
#jmcnelis, 2023/06/14 - provide for wildcards in granuleur-based search
231+
if granule is not None:
232+
# This line is added to strip out the extensions. Not sure if this works across the board for all collections,
233+
# but it seems to work on few collections that were tested.
234+
# This isn't perfect, since it cannot deal with compound extensions
235+
cmr_granule = granule.rsplit(".", 1)[0]
236+
params.append(('GranuleUR[]', cmr_granule))
237+
# jmcnelis, 2023/06/14 - provide for wildcards in granuleur-based search
241238
if '*' in cmr_granule or '?' in cmr_granule:
242239
params.append(('options[GranuleUR][pattern]', 'true'))
243240
if args.verbose:
244241
logging.info("Granule: " + str(cmr_granule))
245242

246-
else:
243+
if start_date_time is not None and end_date_time is not None:
247244
temporal_range = pa.get_temporal_range(start_date_time, end_date_time,
248245
datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")) # noqa E501
249-
params = [
250-
('page_size', page_size),
251-
('sort_key', "-start_date"),
252-
('provider', provider),
253-
('ShortName', short_name),
254-
('temporal', temporal_range),
255-
('token', token),
256-
]
246+
params.append(('temporal', temporal_range))
257247
if args.verbose:
258248
logging.info("Temporal Range: " + temporal_range)
259249

260-
if args.verbose:
261-
logging.info("Provider: " + provider)
262250
if args.bbox is not None:
263251
params.append(('bounding_box', args.bbox))
264252

253+
if args.verbose:
254+
logging.info("Provider: " + provider)
255+
256+
# Final token appending; seems to bug urlencode(params) when it's not last
257+
params.append(('token', token))
258+
265259
# If 401 is raised, refresh token and try one more time
266260
try:
267261
results = pa.get_search_results(params, args.verbose)
@@ -270,7 +264,7 @@ def cmr_downloader(args, token, data_path):
270264
token = pa.refresh_token(token)
271265
# Updated: This is not always a dictionary...
272266
# in fact, here it's always a list of tuples
273-
for i, p in enumerate(params) :
267+
for i, p in enumerate(params):
274268
if p[1] == "token":
275269
params[i] = ("token", token)
276270
results = pa.get_search_results(params, args.verbose)

tests/test_downloader_regression.py

+15
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ def test_downloader_GRACE_with_SHA_512(tmpdir):
109109
modified_time_2 = os.path.getmtime(filename)
110110
print( modified_time_2 )
111111
assert modified_time_1 == modified_time_2
112+
113+
@pytest.mark.regression
114+
def test_downloader_temporal_and_granule_together():
115+
# Command: podaac-data-downloader -c TRPSDL2ALLCRSMGLOS -d data -p GES_DISC -sd 2020-01-01T00:00:00Z -ed 2020-01-02T23:59:59Z -gr *NH3*
116+
shutil.rmtree('./TMP', ignore_errors=True)
117+
args2 = create_downloader_args(
118+
'-c TRPSDL2ALLCRSMGLOS -d ./TMP -p GES_DISC -sd 2020-01-01T00:00:00Z -ed 2020-01-02T23:59:59Z -gr *NH3*'
119+
.split())
120+
pdd.run(args2)
121+
# So running the test in parallel, sometimes we get a 401 on the token...
122+
# Let's ensure we're only looking for data files here
123+
assert len([name for name in os.listdir('./TMP') if
124+
os.path.isfile('./TMP/' + name) and "citation.txt" not in name]) == 2
125+
shutil.rmtree('./TMP')
126+
assert True

tests/test_subscriber.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ def test_search_after():
8585
'bounding_box': "-180,-90,180,90",
8686
}
8787
results = pa.get_search_results(params, True)
88-
assert results['hits'] == 3762
89-
assert len(results['items']) == 3762
88+
# hits and items should always be more than 2000, ignoring page_size set
89+
assert results['hits'] > 2000
90+
assert len(results['items']) != 2000
9091

9192
def test_update_format_change(cleanup_update_test):
9293
print("Running Test")

0 commit comments

Comments
 (0)