##// END OF EJS Templates
Fixed page 404 and some tests
neko259 -
r1988:5bf4a97e default
parent child Browse files
Show More
@@ -1,46 +1,46 b''
1 import logging
1 import logging
2 from django.core.urlresolvers import reverse, NoReverseMatch
2 from django.urls import reverse, NoReverseMatch
3 from django.test import TestCase, Client
3 from django.test import TestCase, Client
4 from boards import urls
4 from boards import urls
5
5
6
6
7 logger = logging.getLogger(__name__)
7 logger = logging.getLogger(__name__)
8
8
9 HTTP_CODE_OK = 200
9 HTTP_CODE_OK = 200
10
10
11 EXCLUDED_VIEWS = {
11 EXCLUDED_VIEWS = {
12 'banned',
12 'banned',
13 'get_thread_diff',
13 'get_thread_diff',
14 'api_sync_pull',
14 'api_sync_pull',
15 }
15 }
16
16
17
17
18 class ViewTest(TestCase):
18 class ViewTest(TestCase):
19
19
20 def test_all_views(self):
20 def test_all_views(self):
21 """
21 """
22 Try opening all views defined in ulrs.py that don't need additional
22 Try opening all views defined in ulrs.py that don't need additional
23 parameters
23 parameters
24 """
24 """
25
25
26 client = Client()
26 client = Client()
27 for url in urls.urlpatterns:
27 for url in urls.urlpatterns:
28 try:
28 try:
29 view_name = url.name
29 view_name = url.name
30 if view_name in EXCLUDED_VIEWS:
30 if view_name in EXCLUDED_VIEWS:
31 logger.debug('View {} is excluded.'.format(view_name))
31 logger.debug('View {} is excluded.'.format(view_name))
32 continue
32 continue
33
33
34 logger.debug('Testing view %s' % view_name)
34 logger.debug('Testing view %s' % view_name)
35
35
36 try:
36 try:
37 response = client.get(reverse(view_name))
37 response = client.get(reverse(view_name))
38
38
39 self.assertEqual(HTTP_CODE_OK, response.status_code,
39 self.assertEqual(HTTP_CODE_OK, response.status_code,
40 'View not opened: {}'.format(view_name))
40 'View not opened: {}'.format(view_name))
41 except NoReverseMatch:
41 except NoReverseMatch:
42 # This view just needs additional arguments
42 # This view just needs additional arguments
43 pass
43 pass
44 except AttributeError:
44 except AttributeError:
45 # This is normal, some views do not have names
45 # This is normal, some views do not have names
46 pass
46 pass
@@ -1,17 +1,17 b''
1 from django.shortcuts import render
1 from django.shortcuts import render
2
2
3 from boards.views.base import BaseBoardView
3 from boards.views.base import BaseBoardView
4
4
5
5
6 class NotFoundView(BaseBoardView):
6 class NotFoundView(BaseBoardView):
7 """
7 """
8 Page 404 (not found)
8 Page 404 (not found)
9 """
9 """
10
10
11 def get(self, request):
11 def get(self, request, *args, **kwargs):
12 params = self.get_context_data()
12 params = self.get_context_data()
13
13
14 response = render(request, 'boards/404.html', params)
14 response = render(request, 'boards/404.html', params)
15 response.status_code = 404
15 response.status_code = 404
16
16
17 return response
17 return response
General Comments 0
You need to be logged in to leave comments. Login now