##// END OF EJS Templates
Added test for all views get requests. Fixed banned view failing this test
neko259 -
r545:9c27ae2e 1.7-dev
parent child Browse files
Show More
@@ -1,9 +1,13 b''
1 # coding=utf-8
1 # coding=utf-8
2 import time
3 import logging
4
2 from django.test import TestCase
5 from django.test import TestCase
3 from django.test.client import Client
6 from django.test.client import Client
4 import time
7 from django.core.urlresolvers import reverse, NoReverseMatch
5
8
6 from boards.models import Post, Tag
9 from boards.models import Post, Tag
10 from boards import urls
7 from neboard import settings
11 from neboard import settings
8
12
9 PAGE_404 = 'boards/404.html'
13 PAGE_404 = 'boards/404.html'
@@ -18,6 +22,8 b' HTTP_CODE_REDIRECT = 302'
18 HTTP_CODE_OK = 200
22 HTTP_CODE_OK = 200
19 HTTP_CODE_NOT_FOUND = 404
23 HTTP_CODE_NOT_FOUND = 404
20
24
25 logger = logging.getLogger(__name__)
26
21
27
22 class PostTests(TestCase):
28 class PostTests(TestCase):
23
29
@@ -223,11 +229,29 b' class FormTest(TestCase):'
223
229
224
230
225 class ViewTest(TestCase):
231 class ViewTest(TestCase):
226 def test_index(self):
232
233 def test_all_views(self):
234 '''
235 Try opening all views defined in ulrs.py that don't need additional
236 parameters
237 '''
238
227 client = Client()
239 client = Client()
240 for url in urls.urlpatterns:
241 try:
242 view_name = url.name
243 logger.debug('Testing view %s' % view_name)
228
244
229 response = client.get('/')
245 try:
230 self.assertEqual(HTTP_CODE_OK, response.status_code, 'Index page not '
246 response = client.get(reverse(view_name))
231 'opened')
247
232 self.assertEqual('boards/posting_general.html', response.templates[0]
248 self.assertEqual(HTTP_CODE_OK, response.status_code,
233 .name, 'Index page should open posting_general template')
249 '%s view not opened' % view_name)
250 except NoReverseMatch:
251 # This view just needs additional arguments
252 pass
253 except Exception, e:
254 self.fail('Got exception %s at %s view' % (e, view_name))
255 except AttributeError:
256 # This is normal, some views do not have names
257 pass
@@ -49,7 +49,7 b" urlpatterns = patterns('',"
49 url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'),
49 url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'),
50 url(r'^ban/(?P<post_id>\w+)/$', views.ban, name='ban'),
50 url(r'^ban/(?P<post_id>\w+)/$', views.ban, name='ban'),
51
51
52 url(r'^banned/$', views.banned.BannedView.as_view, name='banned'),
52 url(r'^banned/$', views.banned.BannedView.as_view(), name='banned'),
53 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
53 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
54
54
55 # RSS feeds
55 # RSS feeds
@@ -9,7 +9,7 b' class BannedView(BaseBoardView):'
9 def get(self, request):
9 def get(self, request):
10 """Show the page that notifies that user is banned"""
10 """Show the page that notifies that user is banned"""
11
11
12 context = self.get_context_data(request)
12 context = self.get_context_data(request=request)
13
13
14 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
14 ban = get_object_or_404(Ban, ip=utils.get_client_ip(request))
15 context['ban_reason'] = ban.reason
15 context['ban_reason'] = ban.reason
General Comments 0
You need to be logged in to leave comments. Login now