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

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
We need to test that the start/end dates are using the period's start/end boundaries correctly
  • Loading branch information
nick-gravgaard committed Jan 14, 2014
1 parent 4d00667 commit 2b6a6c3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
19 changes: 19 additions & 0 deletions features/read_api/relative_date_ranges.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@use_read_api_client
Feature: relative date queries for read api

Scenario: querying for data when given one point and a positive delta
Given "licensing_2.json" is in "foo" bucket
and bucket setting raw_queries_allowed is true
when I go to "/foo?date=2012-12-12T01:01:02%2B00:00&delta=1&period=week"
then I should get back a status of "200"
and the JSON should have "1" results
and the "1st" result should be "{"_start_at": "2012-12-10T00:00:00+00:00", "_end_at": "2012-12-17T00:00:00+00:00", "_count": 4.0}"

Scenario: querying for data when given one point and a negative delta
Given "licensing_2.json" is in "foo" bucket
and bucket setting raw_queries_allowed is true
when I go to "/foo?date=2012-12-12T01:01:02%2B00:00&delta=-1&period=week"
then I should get back a status of "200"
and the JSON should have "1" results
and the "1st" result should be "{"_start_at": "2012-12-10T00:00:00+00:00", "_end_at": "2012-12-17T00:00:00+00:00", "_count": 4.0}"

38 changes: 34 additions & 4 deletions tests/read/test_parse_request_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,26 @@ def test_one_collect_is_parsed_with_custom_method(self):

assert_that(args['collect'], is_([("some_key", "mean")]))

@freeze_time('2014-01-09 00:00:00')
def test_now_and_positive_delta_sets_start_end_window(self):
request_args = MultiDict([
('period', 'day'),
('delta', '3'),
])

args = parse_request_args(request_args)

assert_that(args['start_at'], is_(
datetime(2014, 1, 9, 0, 0, 0, tzinfo=pytz.UTC)))

assert_that(args['end_at'], is_(
datetime(2014, 1, 12, 0, 0, 0, tzinfo=pytz.UTC)))

@freeze_time('2014-01-09 00:00:00')
def test_now_and_negative_delta_sets_start_end_window(self):
request_args = MultiDict([
('period', 'day'),
('delta', -3),
('delta', '-3'),
])

args = parse_request_args(request_args)
Expand All @@ -159,11 +174,26 @@ def test_now_and_negative_delta_sets_start_end_window(self):
assert_that(args['end_at'], is_(
datetime(2014, 1, 9, 0, 0, 0, tzinfo=pytz.UTC)))

@freeze_time('2014-01-09 00:00:00')
def test_now_and_positive_delta_sets_start_end_window(self):
def test_date_off_boundary_and_positive_delta_sets_start_end_window(self):
request_args = MultiDict([
('date', '2014-01-09T01:02:03+00:00'),
('period', 'day'),
('delta', '3'),
])

args = parse_request_args(request_args)

assert_that(args['start_at'], is_(
datetime(2014, 1, 9, 0, 0, 0, tzinfo=pytz.UTC)))

assert_that(args['end_at'], is_(
datetime(2014, 1, 12, 0, 0, 0, tzinfo=pytz.UTC)))

def test_date_off_boundary_and_negative_delta_sets_start_end_window(self):
request_args = MultiDict([
('date', '2014-01-11T23:58:57+00:00'),
('period', 'day'),
('delta', 3),
('delta', '-3'),
])

args = parse_request_args(request_args)
Expand Down

0 comments on commit 2b6a6c3

Please sign in to comment.