Skip to content

Commit 7ab24f2

Browse files
authored
Merge pull request #192 from arpitjain099/chore/validate-date-range
Validate that start date precedes end date
2 parents 94eb390 + 23b48d3 commit 7ab24f2

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55

6+
## [Unreleased]
7+
### Fixed
8+
- Raise a clear error when --start-date is later than --end-date instead of an opaque HTTP 400 from CMR [145](https://github.com/podaac/data-subscriber/issues/145)
9+
610
## [1.15.2]
711
### Fixed
812
- Fixed bug where --subset in combination with the subscriber caused errors

subscriber/podaac_access.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,27 @@ def validate(args):
192192
raise ValueError('Error parsing "--bounds": S Latitude must be <= N Latitude')
193193

194194

195+
start = None
196+
end = None
197+
195198
if args.startDate:
196199
try:
197-
datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ')
200+
start = datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ')
198201
except ValueError:
199202
raise ValueError(
200203
"Error parsing '--start-date' date: " + args.startDate + ". Format must be like 2021-01-14T00:00:00Z") # noqa E501
201204

202205
if args.endDate:
203206
try:
204-
datetime.strptime(args.endDate, '%Y-%m-%dT%H:%M:%SZ')
207+
end = datetime.strptime(args.endDate, '%Y-%m-%dT%H:%M:%SZ')
205208
except ValueError:
206209
raise ValueError(
207210
"Error parsing '--end-date' date: " + args.endDate + ". Format must be like 2021-01-14T00:00:00Z") # noqa E501
208211

212+
if start is not None and end is not None and start > end:
213+
raise ValueError(
214+
"--end-date must be greater than or equal to --start-date.")
215+
209216
if 'minutes' in args:
210217
if args.minutes:
211218
try:

tests/test_subscriber.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def test_validate():
146146
assert a.endDate == '2021-01-01T00:00:00Z'
147147
assert a.provider == "POCLOUD"
148148

149+
# start date equal to end date is allowed
150+
validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2021-01-01T00:00:00Z"])
151+
152+
# start date after end date should raise a clear error
153+
with pytest.raises(ValueError):
154+
validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2020-01-01T00:00:00Z"])
155+
149156
a = validate(["-c", "dataset", "-d", "/data", "-p", "ANEWCLOUD"])
150157
assert a.provider == 'ANEWCLOUD'
151158

0 commit comments

Comments
 (0)