From 924cb415cf9b2efa9d5343f31cf1132d69384c5e Mon Sep 17 00:00:00 2001 From: Darren Worrall Date: Mon, 3 Nov 2014 11:41:10 +0000 Subject: [PATCH] Fix broken schedule detail view with query args Small fix for a small bug but decided to put a test in for it and start that process --- .gitignore | 1 + openduty/schedules.py | 2 +- openduty/tests/__init__.py | 0 openduty/tests/shared.py | 30 ++++++++++++++++++++++++++++++ openduty/tests/test_schedules.py | 27 +++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 openduty/tests/__init__.py create mode 100644 openduty/tests/shared.py create mode 100644 openduty/tests/test_schedules.py diff --git a/.gitignore b/.gitignore index dce37bf..b890bfc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ env/* database.sql .DS_Store openduty/settings_dev.py +*.swp diff --git a/openduty/schedules.py b/openduty/schedules.py index a4838a5..46d4405 100644 --- a/openduty/schedules.py +++ b/openduty/schedules.py @@ -45,7 +45,7 @@ def details(request, id, periods=None): date = coerce_date_dict(request.GET) if date: try: - date = datetime.datetime(**date) + date = datetime(**date) except ValueError: raise Http404 else: diff --git a/openduty/tests/__init__.py b/openduty/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openduty/tests/shared.py b/openduty/tests/shared.py new file mode 100644 index 0000000..9095997 --- /dev/null +++ b/openduty/tests/shared.py @@ -0,0 +1,30 @@ +import unittest +from django.test import Client +import string +import random +from django.contrib.auth import models as auth_models + +def string_generator(size=6, chars=string.ascii_uppercase + string.digits): + return ''.join(random.choice(chars) for _ in range(size)) + +class LoggedInTestCase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.client = Client() + cls.username = string_generator() + cls.password = string_generator() + cls.user = auth_models.User.objects.create_superuser( + cls.username, + 'test@localhost', + cls.password, + ) + cls.client.login(username=cls.username, password=cls.password) + + @classmethod + def tearDownClass(cls): + try: + cls.user.delete() + except: + pass + diff --git a/openduty/tests/test_schedules.py b/openduty/tests/test_schedules.py new file mode 100644 index 0000000..4fea60c --- /dev/null +++ b/openduty/tests/test_schedules.py @@ -0,0 +1,27 @@ +from django.core.urlresolvers import reverse +from schedule.models import Calendar +from .shared import LoggedInTestCase, string_generator + +class TestSchedulesViews(LoggedInTestCase): + + def setUp(self): + super(TestSchedulesViews, self).setUp() + self.cal = Calendar( + name=string_generator(), + slug=string_generator(), + ) + self.cal.save() + + def tearDown(self): + super(TestSchedulesViews, self).tearDown() + try: + self.cal.delete() + except: + pass + + def test_schedule_detail_view_works_with_query_args(self): + response = self.client.get( + reverse('openduty.schedules.details', args=[self.cal.id]), + {'month': '11', 'year': '2014'}, + ) + self.assertEqual(response.status_code, 200)