test_views.py
46 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
|
r821 | import logging | ||
|
r1988 | from django.urls import reverse, NoReverseMatch | ||
|
r821 | from django.test import TestCase, Client | ||
from boards import urls | ||||
logger = logging.getLogger(__name__) | ||||
HTTP_CODE_OK = 200 | ||||
|
r890 | EXCLUDED_VIEWS = { | ||
|
r1175 | 'banned', | ||
'get_thread_diff', | ||||
'api_sync_pull', | ||||
|
r890 | } | ||
|
r821 | |||
class ViewTest(TestCase): | ||||
def test_all_views(self): | ||||
""" | ||||
Try opening all views defined in ulrs.py that don't need additional | ||||
parameters | ||||
""" | ||||
client = Client() | ||||
for url in urls.urlpatterns: | ||||
try: | ||||
view_name = url.name | ||||
|
r890 | if view_name in EXCLUDED_VIEWS: | ||
logger.debug('View {} is excluded.'.format(view_name)) | ||||
continue | ||||
|
r821 | logger.debug('Testing view %s' % view_name) | ||
try: | ||||
response = client.get(reverse(view_name)) | ||||
self.assertEqual(HTTP_CODE_OK, response.status_code, | ||||
|
r890 | 'View not opened: {}'.format(view_name)) | ||
|
r821 | except NoReverseMatch: | ||
# This view just needs additional arguments | ||||
pass | ||||
except AttributeError: | ||||
# This is normal, some views do not have names | ||||
pass | ||||