diff --git a/schedule/tests/test_perms.py b/schedule/tests/test_perms.py index 4741a174..dd43e4b1 100644 --- a/schedule/tests/test_perms.py +++ b/schedule/tests/test_perms.py @@ -8,10 +8,6 @@ from schedule import utils -def default_check_perms(ob, user): - return user.is_authenticated() - - def check_event_perms(ob, user): return user.username == 'ann' @@ -54,8 +50,8 @@ def _check_protected_urls(self, should_allow): def test_event_perms(self): # ann has event rights, bob don't + default_event_check = utils.CHECK_EVENT_PERM_FUNC utils.CHECK_EVENT_PERM_FUNC = check_event_perms - utils.CHECK_CALENDAR_PERM_FUNC = default_check_perms self.client.login(username='ann', password='ann') self._check_protected_urls(should_allow=True) @@ -63,9 +59,11 @@ def test_event_perms(self): self.client.login(username='bob', password='bob') self._check_protected_urls(should_allow=False) + utils.CHECK_EVENT_PERM_FUNC = default_event_check + def test_calendar_perms(self): # bob has calendar rights, ann don't - utils.CHECK_EVENT_PERM_FUNC = default_check_perms + default_cal_check = utils.CHECK_CALENDAR_PERM_FUNC utils.CHECK_CALENDAR_PERM_FUNC = check_calendar_perms self.client.login(username='ann', password='ann') @@ -73,9 +71,12 @@ def test_calendar_perms(self): self.client.login(username='bob', password='bob') self._check_protected_urls(should_allow=True) + utils.CHECK_CALENDAR_PERM_FUNC = default_cal_check def test_calendar_and_event_perms(self): # two mutually exclusive functions, nor ann or bob has rights to access protected views + default_event_check = utils.CHECK_EVENT_PERM_FUNC + default_cal_check = utils.CHECK_CALENDAR_PERM_FUNC utils.CHECK_EVENT_PERM_FUNC = check_event_perms utils.CHECK_CALENDAR_PERM_FUNC = check_calendar_perms @@ -84,3 +85,6 @@ def test_calendar_and_event_perms(self): self.client.login(username='bob', password='bob') self._check_protected_urls(should_allow=False) + + utils.CHECK_EVENT_PERM_FUNC = default_event_check + utils.CHECK_CALENDAR_PERM_FUNC = default_cal_check diff --git a/schedule/tests/test_views.py b/schedule/tests/test_views.py index 86997622..efac9a53 100644 --- a/schedule/tests/test_views.py +++ b/schedule/tests/test_views.py @@ -15,10 +15,6 @@ from schedule.views import check_next_url, coerce_date_dict -def check_perms(ob, user): - return user.username == 'ann' - - class TestViews(TestCase): fixtures = ['schedule.json'] @@ -105,10 +101,7 @@ def test_event_creation_anonymous_user(self): self.assertEqual(self.response.status_code, 302) def test_event_creation_authenticated_user(self): - User.objects.create_user(username='ann', password='ann') - utils.CHECK_EVENT_PERM_FUNC = check_perms - utils.CHECK_CALENDAR_PERM_FUNC = check_perms - self.client.login(username="ann", password="ann") + self.client.login(username="admin", password="admin") self.response = self.client.get(reverse("calendar_create_event", kwargs={"calendar_slug": 'example'}), {}) print self.response @@ -142,10 +135,7 @@ def test_delete_event_anonymous_user(self): self.assertEqual(self.response.status_code, 302) def test_delete_event_authenticated_user(self): - User.objects.create_user(username='ann', password='ann') - utils.CHECK_EVENT_PERM_FUNC = check_perms - utils.CHECK_CALENDAR_PERM_FUNC = check_perms - self.client.login(username="ann", password="ann") + self.client.login(username="admin", password="admin") # Load the deletion page self.response = self.client.get(reverse("delete_event", kwargs={"event_id": 1}), {}) self.assertEqual(self.response.status_code, 200)