diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd5b05..30ff501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/subscriber/podaac_access.py b/subscriber/podaac_access.py index a898569..6e4c226 100644 --- a/subscriber/podaac_access.py +++ b/subscriber/podaac_access.py @@ -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: diff --git a/tests/test_subscriber.py b/tests/test_subscriber.py index 01e468b..8cd93a6 100644 --- a/tests/test_subscriber.py +++ b/tests/test_subscriber.py @@ -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'