##// END OF EJS Templates
Include poster IP in thead loading because it is shown for moderator
Include poster IP in thead loading because it is shown for moderator

File last commit:

r933:ce97c754 merge decentral
r1671:f5ce8715 default
Show More
test_forms.py
56 lines | 2.1 KiB | text/x-python | PythonLexer
from django.test import TestCase, Client
import time
from boards import settings
from boards.models import Post, Tag
import neboard
TEST_TAG = 'test_tag'
PAGE_404 = 'boards/404.html'
TEST_TEXT = 'test text'
NEW_THREAD_PAGE = '/'
THREAD_PAGE_ONE = '/thread/1/'
HTTP_CODE_REDIRECT = 302
class FormTest(TestCase):
def test_post_validation(self):
client = Client()
valid_tags = 'tag1 tag_2 тег_3'
invalid_tags = '$%_356 ---'
Tag.objects.create(name='tag1', required=True)
response = client.post(NEW_THREAD_PAGE, {'title': 'test title',
'text': TEST_TEXT,
'tags': valid_tags})
self.assertEqual(response.status_code, HTTP_CODE_REDIRECT,
msg='Posting new message failed: got code ' +
str(response.status_code))
self.assertEqual(1, Post.objects.count(),
msg='No posts were created')
client.post(NEW_THREAD_PAGE, {'text': TEST_TEXT,
'tags': invalid_tags})
self.assertEqual(1, Post.objects.count(), msg='The validation passed '
'where it should fail')
# Change posting delay so we don't have to wait for 30 seconds or more
old_posting_delay = neboard.settings.POSTING_DELAY
# Wait fot the posting delay or we won't be able to post
neboard.settings.POSTING_DELAY = 1
time.sleep(neboard.settings.POSTING_DELAY + 1)
response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
'tags': valid_tags})
self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
msg='Posting new message failed: got code ' +
str(response.status_code))
# Restore posting delay
settings.POSTING_DELAY = old_posting_delay
self.assertEqual(2, Post.objects.count(),
msg='No posts were created')