test_pages.py
52 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
neko259
|
r821 | from django.test import TestCase, Client | ||
from boards.models import Tag, Post | ||||
TEST_TEXT = 'test' | ||||
NEW_THREAD_PAGE = '/' | ||||
THREAD_PAGE_ONE = '/thread/1/' | ||||
THREAD_PAGE = '/thread/' | ||||
TAG_PAGE = '/tag/' | ||||
neko259
|
r1088 | HTTP_CODE_REDIRECT = 302 | ||
neko259
|
r821 | HTTP_CODE_OK = 200 | ||
HTTP_CODE_NOT_FOUND = 404 | ||||
class PagesTest(TestCase): | ||||
def test_404(self): | ||||
"""Test receiving error 404 when opening a non-existent page""" | ||||
tag_name = 'test_tag' | ||||
tag = Tag.objects.create(name=tag_name) | ||||
client = Client() | ||||
Post.objects.create_post('title', TEST_TEXT, tags=[tag]) | ||||
existing_post_id = Post.objects.all()[0].id | ||||
response_existing = client.get(THREAD_PAGE + str(existing_post_id) + | ||||
'/') | ||||
self.assertEqual(HTTP_CODE_OK, response_existing.status_code, | ||||
'Cannot open existing thread') | ||||
response_not_existing = client.get(THREAD_PAGE + str( | ||||
existing_post_id + 1) + '/') | ||||
neko259
|
r890 | self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, | ||
neko259
|
r821 | 'Not existing thread is opened') | ||
response_existing = client.get(TAG_PAGE + tag_name + '/') | ||||
self.assertEqual(HTTP_CODE_OK, | ||||
response_existing.status_code, | ||||
'Cannot open existing tag') | ||||
response_not_existing = client.get(TAG_PAGE + 'not_tag' + '/') | ||||
neko259
|
r890 | self.assertEqual(HTTP_CODE_NOT_FOUND, response_not_existing.status_code, | ||
neko259
|
r821 | 'Not existing tag is opened') | ||
reply_id = Post.objects.create_post('', TEST_TEXT, | ||||
thread=Post.objects.all()[0] | ||||
neko259
|
r1088 | .get_thread()).id | ||
neko259
|
r821 | response_not_existing = client.get(THREAD_PAGE + str( | ||
reply_id) + '/') | ||||
neko259
|
r890 | self.assertEqual(HTTP_CODE_REDIRECT, response_not_existing.status_code, | ||
neko259
|
r821 | 'Reply is opened as a thread') | ||