Skip to content

Commit

Permalink
add test with incorrect date string format
Browse files Browse the repository at this point in the history
  • Loading branch information
nstoik committed May 24, 2018
1 parent d01d129 commit ffc01b2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,28 @@ def test_occurrences_api_works_with_different_date_string_formats(self):
resp_list = json.loads(response.content.decode('utf-8'))
self.assertIn(event.title, [d['title'] for d in resp_list])

def test_occurrences_api_fails_with_incorrect_date_string_formats(self):
# create a calendar and event
calendar = Calendar.objects.create(name="MyCal", slug='MyCalSlug')
event = Event.objects.create(
title='Recent Event',
start=datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
end=datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
end_recurring_period=datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
calendar=calendar,
)

# test fails with date string time format not '%Y-%m-%d' or '%Y-%m-%dT%H:%M:%S'
response = self.client.get(reverse("api_occurrences"),
{'start': '2008-01-05T00:00',
'end': '2008-02-05T00:00',
'calendar_slug': event.calendar.slug
})
self.assertEqual(response.status_code, 400)
resp = response.content.decode('utf-8')
expected_error = "does not match format '%Y-%m-%dT%H:%M:%S'"
self.assertIn(expected_error, resp)

def test_check_next_url_valid_case(self):
expected = '/calendar/1'
res = check_next_url('/calendar/1')
Expand Down

0 comments on commit ffc01b2

Please sign in to comment.