Skip to content
Open
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
3 changes: 1 addition & 2 deletions abe/resource_models/event_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def get(self, event_id=None, rec_id=None):

rec_id the rec_id of the sub_event information requested to be retrieved
"""

if event_id: # use event id if present
logging.debug('Event requested: ' + event_id)
result = db.Event.objects(id=event_id).first()
Expand Down Expand Up @@ -98,7 +97,7 @@ def get(self, event_id=None, rec_id=None):
events_list = []
for event in results:

if 'recurrence' in event: # checks for recurrent events
if 'recurrence' in event and request.args.get('expand') != 'false': # checks for recurrent events
# expands a recurring event defintion into a json response with individual events
events_list = recurring_to_full(event, events_list, start, end)
else: # appends the event information as a dictionary
Expand Down
29 changes: 28 additions & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,31 @@ def test_add_sample_labels(self):
data=flask.json.dumps(event),
content_type='application/json'
)
self.assertEqual(response.status_code, 201)
self.assertEqual(response._status_code, 201)

def test_date_range(self):
Copy link
Contributor

@osteele osteele May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was moved to test_events.py. It looks like the change is the addition of the last subtest. It should go in that file instead of adding this method here.

from abe import database as db
sample_data.load_data(db)

with self.subTest("a six-month query returns some events"):
response = self.app.get('/events/?start=2017-01-01&end=2017-07-01')
self.assertEqual(response._status_code, 200)
self.assertEqual(len(flask.json.loads(response.data)), 25)

with self.subTest("a one-year query returns all events"):
response = self.app.get('/events/?start=2017-01-01&end=2018-01-01')
self.assertEqual(response._status_code, 200)
self.assertEqual(len(flask.json.loads(response.data)), 69)

with self.subTest("a two-year query is too long"):
response = self.app.get('/events/?start=2017-01-01&end=2019-01-01')
self.assertEqual(response._status_code, 404)

with self.subTest("a one-year query works for leap years"):
response = self.app.get('/events/?start=2020-01-01&end=2021-01-01')
self.assertEqual(response._status_code, 200)

with self.subTest("a query that doesn't expand recurrent events works"):
response = self.app.get('/events/?start=2017-06-01&end=2017-06-10&expand=false')
self.assertEqual(response._status_code, 200)
self.assertEqual(len(flask.json.loads(response.data)), 2)