Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

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

## [Unreleased]
### Fixed
- 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)

## [1.15.2]
### Fixed
- Fixed bug where --subset in combination with the subscriber caused errors
Expand Down
11 changes: 9 additions & 2 deletions subscriber/podaac_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,27 @@ def validate(args):
raise ValueError('Error parsing "--bounds": S Latitude must be <= N Latitude')


start = None
end = None

if args.startDate:
try:
datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ')
start = datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ')
except ValueError:
raise ValueError(
"Error parsing '--start-date' date: " + args.startDate + ". Format must be like 2021-01-14T00:00:00Z") # noqa E501

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

if start is not None and end is not None and start > end:
raise ValueError(
"--end-date must be greater than or equal to --start-date.")

if 'minutes' in args:
if args.minutes:
try:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def test_validate():
assert a.endDate == '2021-01-01T00:00:00Z'
assert a.provider == "POCLOUD"

# start date equal to end date is allowed
validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2021-01-01T00:00:00Z"])

# start date after end date should raise a clear error
with pytest.raises(ValueError):
validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2020-01-01T00:00:00Z"])

a = validate(["-c", "dataset", "-d", "/data", "-p", "ANEWCLOUD"])
assert a.provider == 'ANEWCLOUD'

Expand Down
Loading