Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Exclude hour from midnight boundary check
Browse files Browse the repository at this point in the history
  • Loading branch information
phss committed Oct 18, 2013
1 parent 4af72c1 commit c5fae7e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backdrop/core/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def valid_start_at(self, timestamp):
DAY = Day()
WEEK = Week()
MONTH = Month()
PERIODS = [DAY, WEEK, MONTH]
PERIODS = [HOUR, DAY, WEEK, MONTH]


def parse_period(period_name):
Expand Down
2 changes: 1 addition & 1 deletion backdrop/read/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _is_valid_date_query(self, request_args):
class MidnightValidator(Validator):
def validate(self, request_args, context):
timestamp = request_args.get(context['param_name'])
if _is_valid_date(timestamp):
if _is_valid_date(timestamp) and request_args.get('period') != 'hour':
dt = parser.parse(timestamp).astimezone(pytz.UTC)
if dt.time() != time(0):
self.add_error('%s must be midnight' % context['param_name'])
Expand Down
10 changes: 9 additions & 1 deletion tests/read/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def test_queries_with_period_values_must_be_certain_values(self):
})

assert_that(validation_result, is_invalid_with_message(
"'period' must be one of ['day', 'week', 'month']"))
"'period' must be one of ['hour', 'day', 'week', 'month']"))

def test_queries_without_a_colon_in_sort_by_are_disallowed(self):
validation_result = validate_request_args({
Expand Down Expand Up @@ -349,6 +349,14 @@ def test_queries_with_dates_at_middle_of_day_are_not_allowed(self):
"start_at must be midnight"
))

def test_queries_for_hour_period_with_dates_at_middle_of_day_are_allowed(self):
validation_result = validate_request_args({
'period': 'hour',
'start_at': '2000-02-02T12:00:00+00:00',
'end_at': '2000-02-19T13:00:00+00:00'
}, False)
assert_that(validation_result, is_valid())


class TestValidationHelpers(TestCase):
def test_timestamp_is_valid_method(self):
Expand Down

0 comments on commit c5fae7e

Please sign in to comment.