implement #29 add tests

This commit is contained in:
alafin 2010-11-28 09:56:40 +02:00
parent 7bdc07f42d
commit b5abd4694d
6 changed files with 137 additions and 6 deletions

View file

@ -29,7 +29,7 @@ def topic_saved(instance, **kwargs):
forum.topic_count = forum.topics.count()
forum.updated = topic.updated
forum.post_count = forum.posts.count()
forum.last_post = topic.last_post
forum.last_post_id = topic.last_post_id
forum.save(force_update=True)

View file

@ -1,4 +1,3 @@
"""
The root of forum tests.
"""
import unittest
from test_forum import TestForum
from test_reputation import TestReputation
from test_profile import TestProfile

View file

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, Client
from django.contrib.auth.models import User
from djangobb_forum.models import Category, Forum, Topic, Post
class TestForum(TestCase):
fixtures = ['test_forum.json']
def setUp(self):
self.category = Category.objects.get(pk=1)
self.forum = Forum.objects.get(pk=1)
self.topic = Topic.objects.get(pk=1)
self.post = Post.objects.get(pk=1)
self.user = User.objects.get(pk=1)
self.client = Client()
self.ip = '127.0.0.1'
def test_login(self):
self.assertTrue(self.client.login(username='djangobb', password='djangobb'))
def test_create_topic(self):
topic = Topic.objects.create(forum=self.forum, user=self.user, name="Test Title")
self.assert_(topic)
post = Post.objects.create(
topic=topic, user=self.user, user_ip=self.ip,
markup='bbcode', body='Test Body'
)
self.assert_(post)
def test_create_post(self):
post = Post.objects.create(
topic=self.topic, user=self.user, user_ip=self.ip,
markup='bbcode', body='Test Body'
)
self.assert_(post)
def test_edit_post(self):
self.post.body = 'Test Edit Body'
self.assertEqual(self.post.body, 'Test Edit Body')

View file

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, Client
from django.contrib.auth.models import User
from djangobb_forum.models import Profile
class TestProfile(TestCase):
fixtures = ['test_forum.json']
def setUp(self):
self.profile = Profile.objects.get(pk=1)
self.signature = 'Test Signature'
self.jabber = 'Test Jabber'
self.icq = 'Test ICQ'
self.msn = 'Test MSN'
self.aim = 'Test AIM'
self.yahoo = 'Test YAHOO'
self.status = 'Test Status'
self.location = 'Test Location'
self.site = 'http://djangobb.org/'
def test_personal_profile(self):
self.profile.status = self.status
self.assertEqual(self.profile.status, self.status)
self.profile.location = self.location
self.assertEqual(self.profile.location, self.location)
self.profile.site = self.site
self.assertEqual(self.profile.site, self.site)
def test_messaging_profile(self):
self.profile.jabber = self.jabber
self.assertEqual(self.profile.jabber, self.jabber)
self.profile.icq = self.icq
self.assertEqual(self.profile.icq, self.icq)
self.profile.msn = self.msn
self.assertEqual(self.profile.msn, self.msn)
self.profile.aim = self.aim
self.assertEqual(self.profile.aim, self.aim)
self.profile.yahoo = self.yahoo
self.assertEqual(self.profile.yahoo, self.yahoo)
def test_personality_profile(self):
self.profile.show_avatar = False
self.assertEqual(self.profile.show_avatar, False)
self.profile.signature = self.signature
self.assertEqual(self.profile.signature, self.signature)
def test_display_profile(self):
self.profile.show_smilies = False
self.assertEqual(self.profile.show_smilies, False)
def test_privacy_profile(self):
self.profile.privacy_permission = 0
self.assertEqual(self.profile.privacy_permission, 0)

View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, Client
from django.contrib.auth.models import User
from djangobb_forum.models import Post, Reputation
class TestReputation(TestCase):
fixtures = ['test_forum.json']
def setUp(self):
self.from_user = User.objects.get(pk=1)
self.to_user = User.objects.get(pk=2)
self.post = Post.objects.get(pk=1)
self.reason = 'Test Reason'
def test_reputation_plus(self):
reputation = Reputation.objects.create(
from_user=self.from_user, to_user=self.to_user, post=self.post,
sign=1, reason=self.reason
)
reputations = Reputation.objects.filter(to_user=self.to_user)
total_reputation = 0
for reputation in reputations:
total_reputation += reputation.sign
self.assertEqual(total_reputation, 1)
def test_reputation_minus(self):
reputation = Reputation.objects.create(
from_user=self.from_user, to_user=self.to_user, post=self.post,
sign=-1, reason=self.reason
)
reputations = Reputation.objects.filter(to_user=self.to_user)
total_reputation = 0
for reputation in reputations:
total_reputation += reputation.sign
self.assertEqual(total_reputation, -1)

View file

@ -505,7 +505,6 @@ def reputation(request, username):
sign = 0
post_id = request.GET['post_id']
form.fields['post'].initial = post_id
print form.fields['post']
if request.GET['action'] == 'plus':
form.fields['sign'].initial = 1
elif request.GET['action'] == 'minus':