Show More
@@ -7,12 +7,10 b" NEW_THREAD_PAGE = '/'" | |||||
7 | THREAD_PAGE_ONE = '/thread/1/' |
|
7 | THREAD_PAGE_ONE = '/thread/1/' | |
8 | THREAD_PAGE = '/thread/' |
|
8 | THREAD_PAGE = '/thread/' | |
9 | TAG_PAGE = '/tag/' |
|
9 | TAG_PAGE = '/tag/' | |
10 |
HTTP_CODE_REDIRECT = 30 |
|
10 | HTTP_CODE_REDIRECT = 301 | |
11 | HTTP_CODE_OK = 200 |
|
11 | HTTP_CODE_OK = 200 | |
12 | HTTP_CODE_NOT_FOUND = 404 |
|
12 | HTTP_CODE_NOT_FOUND = 404 | |
13 |
|
13 | |||
14 | PAGE_404 = 'boards/404.html' |
|
|||
15 |
|
||||
16 |
|
14 | |||
17 | class PagesTest(TestCase): |
|
15 | class PagesTest(TestCase): | |
18 |
|
16 | |||
@@ -33,7 +31,7 b' class PagesTest(TestCase):' | |||||
33 |
|
31 | |||
34 | response_not_existing = client.get(THREAD_PAGE + str( |
|
32 | response_not_existing = client.get(THREAD_PAGE + str( | |
35 | existing_post_id + 1) + '/') |
|
33 | existing_post_id + 1) + '/') | |
36 |
self.assertEqual( |
|
34 | self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, | |
37 | 'Not existing thread is opened') |
|
35 | 'Not existing thread is opened') | |
38 |
|
36 | |||
39 | response_existing = client.get(TAG_PAGE + tag_name + '/') |
|
37 | response_existing = client.get(TAG_PAGE + tag_name + '/') | |
@@ -42,8 +40,7 b' class PagesTest(TestCase):' | |||||
42 | 'Cannot open existing tag') |
|
40 | 'Cannot open existing tag') | |
43 |
|
41 | |||
44 | response_not_existing = client.get(TAG_PAGE + 'not_tag' + '/') |
|
42 | response_not_existing = client.get(TAG_PAGE + 'not_tag' + '/') | |
45 | self.assertEqual(PAGE_404, |
|
43 | self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, | |
46 | response_not_existing.templates[0].name, |
|
|||
47 | 'Not existing tag is opened') |
|
44 | 'Not existing tag is opened') | |
48 |
|
45 | |||
49 | reply_id = Post.objects.create_post('', TEST_TEXT, |
|
46 | reply_id = Post.objects.create_post('', TEST_TEXT, | |
@@ -51,6 +48,5 b' class PagesTest(TestCase):' | |||||
51 | .get_thread()) |
|
48 | .get_thread()) | |
52 | response_not_existing = client.get(THREAD_PAGE + str( |
|
49 | response_not_existing = client.get(THREAD_PAGE + str( | |
53 | reply_id) + '/') |
|
50 | reply_id) + '/') | |
54 | self.assertEqual(PAGE_404, |
|
51 | self.assertEqual(HTTP_CODE_REDIRECT, response_not_existing.status_code, | |
55 | response_not_existing.templates[0].name, |
|
|||
56 | 'Reply is opened as a thread') |
|
52 | 'Reply is opened as a thread') |
@@ -8,6 +8,10 b' logger = logging.getLogger(__name__)' | |||||
8 |
|
8 | |||
9 | HTTP_CODE_OK = 200 |
|
9 | HTTP_CODE_OK = 200 | |
10 |
|
10 | |||
|
11 | EXCLUDED_VIEWS = { | |||
|
12 | 'banned', | |||
|
13 | } | |||
|
14 | ||||
11 |
|
15 | |||
12 | class ViewTest(TestCase): |
|
16 | class ViewTest(TestCase): | |
13 |
|
17 | |||
@@ -21,13 +25,17 b' class ViewTest(TestCase):' | |||||
21 | for url in urls.urlpatterns: |
|
25 | for url in urls.urlpatterns: | |
22 | try: |
|
26 | try: | |
23 | view_name = url.name |
|
27 | view_name = url.name | |
|
28 | if view_name in EXCLUDED_VIEWS: | |||
|
29 | logger.debug('View {} is excluded.'.format(view_name)) | |||
|
30 | continue | |||
|
31 | ||||
24 | logger.debug('Testing view %s' % view_name) |
|
32 | logger.debug('Testing view %s' % view_name) | |
25 |
|
33 | |||
26 | try: |
|
34 | try: | |
27 | response = client.get(reverse(view_name)) |
|
35 | response = client.get(reverse(view_name)) | |
28 |
|
36 | |||
29 | self.assertEqual(HTTP_CODE_OK, response.status_code, |
|
37 | self.assertEqual(HTTP_CODE_OK, response.status_code, | |
30 |
|
|
38 | 'View not opened: {}'.format(view_name)) | |
31 | except NoReverseMatch: |
|
39 | except NoReverseMatch: | |
32 | # This view just needs additional arguments |
|
40 | # This view just needs additional arguments | |
33 | pass |
|
41 | pass |
@@ -12,4 +12,7 b' class NotFoundView(BaseBoardView):' | |||||
12 | context = self.get_context_data(request=request) |
|
12 | context = self.get_context_data(request=request) | |
13 |
|
13 | |||
14 | # TODO Use dict here |
|
14 | # TODO Use dict here | |
15 |
re |
|
15 | response = render(request, 'boards/404.html', context_instance=context) | |
|
16 | response.status_code = 404 | |||
|
17 | ||||
|
18 | return response |
General Comments 0
You need to be logged in to leave comments.
Login now