Skip to content
Snippets Groups Projects
Commit 44a56fe1 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Implement minor improvement for testing framework & add two more tests

parent 3246148c
No related branches found
No related tags found
No related merge requests found
import traceback
from typing import List from typing import List
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -59,8 +60,11 @@ class BasicViewTests: ...@@ -59,8 +60,11 @@ class BasicViewTests:
def test_views_for_200(self): def test_views_for_200(self):
for view_name in self.VIEWS: for view_name in self.VIEWS:
view_name_with_prefix, url = self._name_and_url(view_name) view_name_with_prefix, url = self._name_and_url(view_name)
try:
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.status_code, 200, msg=f"{view_name_with_prefix} ({url}) broken") self.assertEqual(response.status_code, 200, msg=f"{view_name_with_prefix} ({url}) broken")
except Exception as e:
self.fail(f"An error occurred during rendering of {view_name_with_prefix} ({url}):\n\n{traceback.format_exc()}")
def test_access_control_staff_only(self): def test_access_control_staff_only(self):
self.client.logout() self.client.logout()
...@@ -94,9 +98,12 @@ class ModelViewTests(BasicViewTests, TestCase): ...@@ -94,9 +98,12 @@ class ModelViewTests(BasicViewTests, TestCase):
(DefaultSlot, 'defaultslot') (DefaultSlot, 'defaultslot')
] ]
VIEWS_STAFF_ONLY = [
('admin:index', {})
]
def test_admin(self): def test_admin(self):
self.client.force_login(self.admin_user) self.client.force_login(self.admin_user)
for model in self.ADMIN_MODELS: for model in self.ADMIN_MODELS:
if model[1] == "event": if model[1] == "event":
continue continue
......
...@@ -26,3 +26,11 @@ class PlanViewTests(BasicViewTests, TestCase): ...@@ -26,3 +26,11 @@ class PlanViewTests(BasicViewTests, TestCase):
response = self.client.get(url) response = self.client.get(url)
self.assertNotContains(response, "Plan is not visible (yet).", self.assertNotContains(response, "Plan is not visible (yet).",
msg_prefix="Plan is not visible for staff user") msg_prefix="Plan is not visible for staff user")
def test_wall_redirect(self):
view_name_with_prefix, url_wall = self._name_and_url(('plan_wall', {'event_slug': 'kif23'}))
view_name_with_prefix, url_plan = self._name_and_url(('plan_overview', {'event_slug': 'kif23'}))
response = self.client.get(url_wall)
self.assertRedirects(response, url_plan,
msg_prefix=f"Redirect away from wall not working ({url_wall} -> {url_plan})")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment