Update some forum tests to be simpler thanks to new test-utils.

This commit is contained in:
James Socol 2010-10-01 17:33:34 -04:00
Родитель 927614d46c
Коммит cdb9c7a1df
4 изменённых файлов: 10 добавлений и 38 удалений

Просмотреть файл

@ -4,7 +4,8 @@
"model": "forums.forum",
"fields": {
"name": "Test forum",
"slug": "test-forum"
"slug": "test-forum",
"last_post": 25
}
},
{

Просмотреть файл

@ -2,37 +2,11 @@ from django.contrib.auth.models import User
from nose.tools import eq_
from forums.models import Forum, Thread, Post, ThreadLockedError
from forums.models import Thread, Post, ThreadLockedError
from forums.views import sort_threads
from sumo.tests import get, LocalizingClient, TestCase
def fixtures_setup():
f1 = Forum.objects.filter()[0]
f1.last_post = Post.objects.get(pk=25)
f1.save()
t1 = Thread.objects.get(pk=1)
t1.last_post = Post.objects.get(pk=24)
t1.save()
t2 = Thread.objects.get(pk=2)
t2.last_post = Post.objects.get(pk=3)
t2.save()
t3 = Thread.objects.get(pk=3)
t3.last_post = Post.objects.get(pk=5)
t3.save()
t4 = Thread.objects.get(pk=4)
t4.last_post = Post.objects.get(pk=25)
t4.save()
t5 = Thread.objects.get(pk=5)
t5.last_post = Post.objects.get(pk=27)
t5.save()
class ForumTestCase(TestCase):
fixtures = ['users.json', 'posts.json', 'forums_permissions.json']
@ -40,7 +14,6 @@ class ForumTestCase(TestCase):
"""Our fixtures have nulled foreign keys to allow them to be
installed. This will set them to the correct values."""
fixtures_setup()
self.client = LocalizingClient()

Просмотреть файл

@ -55,12 +55,11 @@ class ForumModelTestCase(ForumTestCase):
"""Adding/Deleting the last post in a thread and forum should
update the last_post field
"""
forum = Forum.objects.get(pk=1)
last_post = forum.last_post
thread = last_post.thread
thread = Thread.objects.get(pk=4)
user = User.objects.get(pk=118533)
# add a new post, then check that last_post is updated
new_post = Post(thread=thread, content="test", author=last_post.author)
new_post = Post(thread=thread, content="test", author=user)
new_post.save()
forum = Forum.objects.get(pk=1)
thread = Thread.objects.get(pk=thread.id)
@ -71,8 +70,8 @@ class ForumModelTestCase(ForumTestCase):
new_post.delete()
forum = Forum.objects.get(pk=1)
thread = Thread.objects.get(pk=thread.id)
eq_(forum.last_post.id, last_post.id)
eq_(thread.last_post.id, last_post.id)
eq_(forum.last_post.id, 25)
eq_(thread.last_post.id, 25)
def test_public_access(self):
"""Assert Forums think they're publicly viewable and postable at

Просмотреть файл

@ -133,12 +133,11 @@ class ThreadsTemplateTestCase(ForumTestCase):
def test_last_thread_post_link_has_post_id(self):
"""Make sure the last post url links to the last post (#post-<id>)."""
forum = Forum.objects.filter()[0]
response = get(self.client, 'forums.threads', args=[forum.slug])
response = get(self.client, 'forums.threads', args=['test-forum'])
doc = pq(response.content)
last_post_link = doc('ol.threads div.last-post a:not(.username)')[0]
href = last_post_link.attrib['href']
eq_(href.split('#')[1], 'post-3')
eq_(href.split('#')[1], 'post-4')
def test_empty_thread_errors(self):
"""Posting an empty thread shows errors."""