##// END OF EJS Templates
Merge
Merge

File last commit:

r102:2032ea58 default
r111:c1481586 merge default
Show More
tests.py
225 lines | 7.1 KiB | text/x-python | PythonLexer
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 # coding=utf-8
Ilyas
Completed login and logout functionality and covered by tests.
r13 from django.utils.unittest import TestCase
from django.test.client import Client
neko259
Partially fixed tests and model definition
r7 import boards
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24 from boards.models import Post, Admin, Tag
neko259
Added maximum threads count parameter to the settings. Delete the old posts to preserve the max count. Small design tweaks.
r28 from neboard import settings
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 TEST_TEXT = 'test text'
NEW_THREAD_PAGE = '/'
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 THREAD_PAGE_ONE = '/thread/1/'
THREAD_PAGE = '/thread/'
TAG_PAGE = '/tag/'
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 HTTP_CODE_REDIRECT = 302
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 HTTP_CODE_OK = 200
HTTP_CODE_NOT_FOUND = 404
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71
neko259
Fixed the tests. Added exists() method for the post.
r8
neko259
Initial commit. One test doesn't work, missing posting form.
r0 class BoardTests(TestCase):
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 def _create_post(self):
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 return Post.objects.create_post(title='title',
text='text')
neko259
Initial commit. One test doesn't work, missing posting form.
r0
def test_post_add(self):
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.
r1 self.assertIsNotNone(post)
neko259
Partially fixed tests and model definition
r7 self.assertEqual(boards.models.NO_PARENT, post.parent)
neko259
Initial commit. One test doesn't work, missing posting form.
r0
def test_delete_post(self):
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Fixed the tests. Added exists() method for the post.
r8 post_id = post.id
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22
neko259
Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.
r1 Post.objects.delete_post(post)
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 self.assertFalse(Post.objects.exists(post_id))
neko259
Initial commit. One test doesn't work, missing posting form.
r0
def test_delete_posts_by_ip(self):
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 post = self._create_post()
neko259
Fixed the tests. Added exists() method for the post.
r8 post_id = post.id
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.
r1 Post.objects.delete_posts_by_ip('0.0.0.0')
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16 self.assertFalse(Post.objects.exists(post_id))
Ilyas
Completed login and logout functionality and covered by tests.
r13
# Authentication tests
def _create_test_user(self):
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 admin = Admin(name='test_username12313584353165',
password='test_userpassword135135512')
Ilyas
Completed login and logout functionality and covered by tests.
r13
admin.save()
return admin
def test_admin_login(self):
client = Client()
self.assertFalse('admin' in client.session)
admin = self._create_test_user()
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 response = client.post('/login',
{'name': admin.name, 'password': admin.password})
Ilyas
Completed login and logout functionality and covered by tests.
r13
# it means that login passed and user are redirected to another page
self.assertEqual(302, response.status_code)
self.assertTrue('admin' in client.session)
self.assertTrue(client.session['admin'])
admin.delete()
wrong_name = 'sd2f1s3d21fs3d21f'
wrong_password = 'sd2f1s3d21fs3d21fsdfsd'
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 client.post('/login', {'name': wrong_name, 'password': wrong_password})
Ilyas
Completed login and logout functionality and covered by tests.
r13 self.assertFalse(client.session['admin'])
def test_admin_logout(self):
client = Client()
self.assertFalse('admin' in client.session)
admin = self._create_test_user()
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 client.post('/login',
{'name': admin.name, 'password': admin.password})
Ilyas
Completed login and logout functionality and covered by tests.
r13
self.assertTrue(client.session['admin'])
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 client.get('/logout')
Ilyas
Completed login and logout functionality and covered by tests.
r13
self.assertFalse(client.session['admin'])
admin.delete()
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17 def test_get_thread(self):
opening_post = self._create_post()
op_id = opening_post.id
for i in range(0, 2):
Post.objects.create_post('title', 'text',
neko259
Added images upload. Changed the design a bit. Reformatted some code by PEP 8. Changed the urls: not the main site is located at /, not /boards/.
r22 parent_id=op_id)
neko259
Fixed getting posts for a thread. Implemented thread getting test.
r17
thread = Post.objects.get_thread(op_id)
neko259
Removed call to en internal method in test.
r19 self.assertEqual(3, len(thread))
neko259
Added localization (not fully working). Added tags posting. Changed the design a bit.
r24
def test_create_post_with_tag(self):
tag = Tag.objects.create(name='test_tag')
post = Post.objects.create_post(title='title', text='text', tags=[tag])
neko259
Added maximum threads count parameter to the settings. Delete the old posts to preserve the max count. Small design tweaks.
r28 self.assertIsNotNone(post)
def test_thread_max_count(self):
for i in range(settings.MAX_THREAD_COUNT + 1):
self._create_post()
self.assertEqual(settings.MAX_THREAD_COUNT,
neko259
Compiling regexes for gets. #17 Added pagination. #28 Visually differing the dead (not bumpable) threads.
r46 len(Post.objects.get_threads()))
def test_get(self):
"""Test if the get computes properly"""
post = self._create_post()
self.assertTrue(post.is_get())
def test_pages(self):
"""Test that the thread list is properly split into pages"""
for i in range(settings.MAX_THREAD_COUNT):
self._create_post()
all_threads = Post.objects.get_threads()
posts_in_second_page = Post.objects.get_threads(page=1)
first_post = posts_in_second_page[0]
self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id,
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 first_post.id)
def test_post_validation(self):
"""Test the validation of the post form"""
neko259
Fixed validation test with enabled captcha.
r102 # Disable captcha for the test
captcha_enabled = settings.ENABLE_CAPTCHA
settings.ENABLE_CAPTCHA = False
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 Post.objects.all().delete()
client = Client()
valid_tags = u'tag1 tag_2 тег_3'
invalid_tags = u'$%_356 ---'
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')
neko259
Added form validation, added style for the tag panel. This fixes #13
r76 client.post(NEW_THREAD_PAGE, {'text': TEST_TEXT,
'tags': invalid_tags})
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 self.assertEqual(1, Post.objects.count(), msg='The validation passed '
neko259
Fixed validation of image without text. This refs #13
r77 'where it should fail')
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 response = client.post(THREAD_PAGE_ONE, {'text': TEST_TEXT,
neko259
Implemented RSS support. This fixes #11
r89 'tags': valid_tags})
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 self.assertEqual(HTTP_CODE_REDIRECT, response.status_code,
msg=u'Posting new message failed: got code ' +
neko259
Fixed validation of image without text. This refs #13
r77 str(response.status_code))
self.assertEqual(2, Post.objects.count(),
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 msg=u'No posts were created')
neko259
Fixed validation test with enabled captcha.
r102 # Restore captcha setting
settings.ENABLE_CAPTCHA = captcha_enabled
neko259
Added error 404 for opening not existing thread or tag. This fixes #8
r79 def test_404(self):
"""Test receiving error 404 when opening a non-existent page"""
Post.objects.all().delete()
Tag.objects.all().delete()
tag_name = u'test_tag'
tags, = [Tag.objects.get_or_create(name=tag_name)]
client = Client()
Post.objects.create_post('title', TEST_TEXT, tags=tags)
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,
u'Cannot open existing thread')
response_not_existing = client.get(THREAD_PAGE + str(
existing_post_id + 1) + '/')
self.assertEqual(HTTP_CODE_NOT_FOUND,
response_not_existing.status_code,
u'Not existing thread is opened')
response_existing = client.get(TAG_PAGE + tag_name + '/')
self.assertEqual(HTTP_CODE_OK,
response_existing.status_code,
u'Cannot open existing tag')
response_not_existing = client.get(TAG_PAGE + u'not_tag' + '/')
self.assertEqual(HTTP_CODE_NOT_FOUND,
response_not_existing.status_code,
neko259
Defined encoding in the HTML. Fixed error 404 page on opening reply as thread. This fixes #46, #47
r86 u'Not existing tag is opened')
reply_id = Post.objects.create_post('', TEST_TEXT,
parent_id=existing_post_id)
response_not_existing = client.get(THREAD_PAGE + str(
reply_id) + '/')
self.assertEqual(HTTP_CODE_NOT_FOUND,
response_not_existing.status_code,
u'Not existing thread is opened')