##// END OF EJS Templates
Logo rebranding
Logo rebranding

File last commit:

r2004:d0cc4756 default
r2150:532ef623 tip default
Show More
test_post.py
178 lines | 6.1 KiB | text/x-python | PythonLexer
neko259
Split tests module into separate modules
r821 from django.core.paginator import Paginator
from django.test import TestCase
neko259
Fixed thread bumping
r1221
neko259
Split tests module into separate modules
r821 from boards import settings
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 from boards.models import Tag, Post, Thread, KeyPair
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 from boards.models.thread import STATUS_ARCHIVE
neko259
Continue to extract section strings
r2004 from boards.settings import SECTION_VIEW
neko259
Split tests module into separate modules
r821
class PostTests(TestCase):
def _create_post(self):
neko259
Fixed tag sync and tests
r1895 tag, created = Tag.objects.get_or_create_with_alias(name='test_tag')
neko259
Split tests module into separate modules
r821 return Post.objects.create_post(title='title', text='text',
tags=[tag])
def test_post_add(self):
"""Test adding post"""
post = self._create_post()
self.assertIsNotNone(post, 'No post was created.')
neko259
Fixed tag sync and tests
r1895 self.assertEqual('test_tag', post.get_thread().tags.all()[0].get_name(),
neko259
Split tests module into separate modules
r821 'No tags were added to the post.')
def test_delete_post(self):
"""Test post deletion"""
post = self._create_post()
post_id = post.id
neko259
Delete thread when the OP is deleted. Removed old post deleter
r880 post.delete()
neko259
Split tests module into separate modules
r821
self.assertFalse(Post.objects.filter(id=post_id).exists())
def test_delete_thread(self):
"""Test thread deletion"""
opening_post = self._create_post()
thread = opening_post.get_thread()
reply = Post.objects.create_post("", "", thread=thread)
neko259
Delete replies properly when deleting a thread. Delete thread directly, not by...
r950 thread.delete()
neko259
Split tests module into separate modules
r821
neko259
Actually delete the opening post when deleting the thread
r884 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
'Reply was not deleted with the thread.')
self.assertFalse(Post.objects.filter(id=opening_post.id).exists(),
'Opening post was not deleted with the thread.')
neko259
Split tests module into separate modules
r821
def test_post_to_thread(self):
"""Test adding post to a thread"""
op = self._create_post()
post = Post.objects.create_post("", "", thread=op.get_thread())
self.assertIsNotNone(post, 'Reply to thread wasn\'t created')
self.assertEqual(op.get_thread().last_edit_time, post.pub_time,
'Post\'s create time doesn\'t match thread last edit'
' time')
def test_delete_posts_by_ip(self):
"""Test deleting posts with the given ip"""
post = self._create_post()
post_id = post.id
Post.objects.delete_posts_by_ip('0.0.0.0')
self.assertFalse(Post.objects.filter(id=post_id).exists())
def test_get_thread(self):
"""Test getting all posts of a thread"""
opening_post = self._create_post()
for i in range(2):
Post.objects.create_post('title', 'text',
thread=opening_post.get_thread())
thread = opening_post.get_thread()
neko259
Fixed creating new thread that was broken after messing up dependencies in...
r959 self.assertEqual(3, thread.get_replies().count())
neko259
Split tests module into separate modules
r821
def test_create_post_with_tag(self):
"""Test adding tag to post"""
neko259
Fixed tag sync and tests
r1895 tag, created = Tag.objects.get_or_create_with_alias(name='test_tag')
neko259
Split tests module into separate modules
r821 post = Post.objects.create_post(title='title', text='text', tags=[tag])
thread = post.get_thread()
self.assertIsNotNone(post, 'Post not created')
self.assertTrue(tag in thread.tags.all(), 'Tag not added to thread')
def test_pages(self):
"""Test that the thread list is properly split into pages"""
neko259
Continue to extract section strings
r2004 threads_per_page = settings.get_int(SECTION_VIEW, 'ThreadsPerPage')
for i in range(threads_per_page * 2):
neko259
Split tests module into separate modules
r821 self._create_post()
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 all_threads = Thread.objects.exclude(status=STATUS_ARCHIVE)
neko259
Split tests module into separate modules
r821
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 paginator = Paginator(Thread.objects.exclude(status=STATUS_ARCHIVE),
neko259
Continue to extract section strings
r2004 threads_per_page)
neko259
Split tests module into separate modules
r821 posts_in_second_page = paginator.page(2).object_list
first_post = posts_in_second_page[0]
neko259
Continue to extract section strings
r2004 self.assertEqual(all_threads[threads_per_page].id,
neko259
Fixed thread gallery view
r889 first_post.id)
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 def test_reflinks(self):
"""
Tests that reflinks are parsed within post and connecting replies
to the replied posts.
Local reflink example: [post]123[/post]
Global reflink example: [post]key_type::key::123[/post]
"""
key = KeyPair.objects.generate_key(primary=True)
neko259
Fixed tag sync and tests
r1895 tag, created = Tag.objects.get_or_create_with_alias(name='test_tag')
neko259
Added test for reflinks. Added management command to get posts from other node...
r841
post = Post.objects.create_post(title='', text='', tags=[tag])
post_local_reflink = Post.objects.create_post(title='',
text='[post]%d[/post]' % post.id, thread=post.get_thread())
self.assertTrue(post_local_reflink in post.referenced_posts.all(),
'Local reflink not connecting posts.')
neko259
Fixed thread gallery view
r889 def test_thread_replies(self):
"""
Tests that the replies can be queried from a thread in all possible
ways.
"""
neko259
Fixed tag sync and tests
r1895 tag, created = Tag.objects.get_or_create_with_alias(name='test_tag')
neko259
Fixed thread gallery view
r889 opening_post = Post.objects.create_post(title='title', text='text',
tags=[tag])
thread = opening_post.get_thread()
neko259
Fixed thread bumping
r1221 Post.objects.create_post(title='title', text='text', thread=thread)
Post.objects.create_post(title='title', text='text', thread=thread)
neko259
Fixed thread gallery view
r889
replies = thread.get_replies()
self.assertTrue(len(replies) > 0, 'No replies found for thread.')
replies = thread.get_replies(view_fields_only=True)
self.assertTrue(len(replies) > 0,
'No replies found for thread with view fields only.')
neko259
Fixed thread bumping
r1221
def test_bumplimit(self):
"""
Tests that the thread bumpable status is changed and post uids and
last update times are updated across all post threads.
"""
op1 = Post.objects.create_post(title='title', text='text')
thread1 = op1.get_thread()
thread1.max_posts = 5
thread1.save()
uid_1 = op1.uid
# Create multi reply
Post.objects.create_post(
neko259
Removed multi replies from tests
r1711 title='title', text='text', thread=thread1)
neko259
Fixed thread bumping
r1221 for i in range(6):
Post.objects.create_post(title='title', text='text',
thread=thread1)
self.assertFalse(op1.get_thread().can_bump(),
'Thread is bumpable when it should not be.')
self.assertNotEqual(
uid_1, Post.objects.get(id=op1.id).uid,
'UID of the first OP should be changed but it is not.')