##// END OF EJS Templates
Fixed getting posts for a thread. Implemented thread getting test.
Fixed getting posts for a thread. Implemented thread getting test.

File last commit:

r17:e40b2431 default
r17:e40b2431 default
Show More
tests.py
99 lines | 2.5 KiB | text/x-python | PythonLexer
from django.utils.unittest import TestCase
from django.test.client import Client
import boards
from boards.models import Post, Admin
class BoardTests(TestCase):
def _create_post(self):
return Post.objects.create_post(title = 'title',
text = 'text')
def test_post_add(self):
post = self._create_post()
self.assertIsNotNone(post)
self.assertEqual(boards.models.NO_PARENT, post.parent)
def test_delete_post(self):
post = self._create_post()
post_id = post.id
Post.objects.delete_post(post)
self.assertFalse(Post.objects.exists(post_id))
def test_delete_posts_by_ip(self):
post = self._create_post()
post_id = post.id
Post.objects.delete_posts_by_ip('0.0.0.0')
self.assertFalse(Post.objects.exists(post_id))
# Authentication tests
def _create_test_user(self):
admin = Admin(name = 'test_username12313584353165',
password = 'test_userpassword135135512')
admin.save()
return admin
def test_admin_login(self):
client = Client()
self.assertFalse('admin' in client.session)
admin = self._create_test_user()
response = client.post('/boards/login',
{'name': admin.name, 'password': admin.password})
# 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'
client.post('/boards/login', {'name': wrong_name, 'password': wrong_password})
self.assertFalse(client.session['admin'])
def test_admin_logout(self):
client = Client()
self.assertFalse('admin' in client.session)
admin = self._create_test_user()
client.post('/boards/login',
{'name': admin.name, 'password': admin.password})
self.assertTrue(client.session['admin'])
client.get('/boards/logout')
self.assertFalse(client.session['admin'])
admin.delete()
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',
parent_id = op_id)
thread = Post.objects.get_thread(op_id)
self.assertEqual(3, thread.__len__())