add the ability to disable the web display of some apps

This commit is contained in:
2023-03-27 15:56:15 -05:00
parent a214d8acfd
commit 420a7b1472
7 changed files with 76 additions and 15 deletions

View File

@@ -1,8 +1,5 @@
"""Test the race views."""
from unittest import mock
from django.test import TestCase
from django.utils.timezone import now
from races.models import Race, Racer, RaceUpdate

View File

@@ -0,0 +1,46 @@
"""Test views and templates' adherence to WEB_ENABLED_APPS."""
from django.conf import settings
from django.test import TestCase
class WebEnabledAppsAPITest(TestCase):
"""Test that certain display elements and views can be enabled/disabled via settings."""
def setUp(self):
"""Store the old setting so that we can restore it later."""
self.old_sites_list = settings.WEB_ENABLED_APPS
print("butt")
def tearDown(self):
"""Restore the old setting stored earlier."""
settings.WEB_ENABLED_APPS = self.old_sites_list
print("butt")
def test_default_enabled(self):
"""Test that the expected sites can be reached and displayed by default."""
resp = self.client.get('/karma/')
self.assertEqual(resp.status_code, 200)
self.assertIn(b'<a href="/karma/">', resp.content)
resp = self.client.get('/races/')
self.assertEqual(resp.status_code, 200)
self.assertIn(b'<a href="/races/">', resp.content)
def test_one_disabled(self):
"""Test that we can disable one site but not all sites using this setting."""
settings.WEB_ENABLED_APPS = ['karma']
resp = self.client.get('/karma/')
self.assertEqual(resp.status_code, 200)
self.assertIn(b'<a href="/karma/">', resp.content)
resp = self.client.get('/races/')
self.assertEqual(resp.status_code, 403)
self.assertNotIn(b'<a href="/races/">', resp.content)
def test_all_disabled(self):
"""Test that we can disable all sites using this setting."""
settings.WEB_ENABLED_APPS = []
resp = self.client.get('/karma/')
self.assertEqual(resp.status_code, 403)
self.assertNotIn(b'<a href="/karma/">', resp.content)
resp = self.client.get('/races/')
self.assertEqual(resp.status_code, 403)
self.assertNotIn(b'<a href="/races/">', resp.content)