summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2011-11-09 19:21:44 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2011-11-09 19:21:44 +0100
commitda93e5dde9b177bc361053c51caa20e15824d530 (patch)
tree743a32b81d3cab98286f62e70bd7fa39311b9021
parent92b0543ba011ea52829ec9aea837147b5cde8ab3 (diff)
downloadaskbot-da93e5dde9b177bc361053c51caa20e15824d530.tar.gz
askbot-da93e5dde9b177bc361053c51caa20e15824d530.tar.bz2
askbot-da93e5dde9b177bc361053c51caa20e15824d530.zip
Added misc tests; Fixed page load tests - still TODO: `./manage.py test askbot.PageLoadTestCase` works great, whereas `./manage.py test askbot` breaks inside PageLoadTestCase - on checking the template used - it looks on the surface like some Jinja2 monkey-patching problem
-rw-r--r--askbot/tests/__init__.py1
-rw-r--r--askbot/tests/misc_tests.py50
-rw-r--r--askbot/tests/page_load_tests.py28
3 files changed, 76 insertions, 3 deletions
diff --git a/askbot/tests/__init__.py b/askbot/tests/__init__.py
index b06c2b06..76e32e41 100644
--- a/askbot/tests/__init__.py
+++ b/askbot/tests/__init__.py
@@ -11,3 +11,4 @@ from askbot.tests.form_tests import *
from askbot.tests.follow_tests import *
from askbot.tests.templatefilter_tests import *
from askbot.tests.markup_test import *
+from askbot.tests.misc_tests import *
diff --git a/askbot/tests/misc_tests.py b/askbot/tests/misc_tests.py
new file mode 100644
index 00000000..ddf16360
--- /dev/null
+++ b/askbot/tests/misc_tests.py
@@ -0,0 +1,50 @@
+import datetime
+from django.contrib.contenttypes.models import ContentType
+from django.test.client import Client
+from askbot.tests.utils import AskbotTestCase
+from askbot.conf import settings
+from askbot import models
+from askbot.models.badges import award_badges_signal
+
+from askbot.views.users import get_related_object_type_name
+
+class MiscTests(AskbotTestCase):
+
+ def setUp(self):
+ self.u1 = self.create_user(username='user1')
+ self.u2 = self.create_user(username='user2')
+ self.u3 = self.create_user(username='user3')
+
+ def test_get_related_object_type_name_for_question(self):
+ question = self.post_question(user=self.u1)
+ ct = ContentType.objects.get_for_model(question)
+ self.assertEqual('question', get_related_object_type_name(ct.id, question.id))
+
+ def test_get_related_object_type_name_for_question_revision(self):
+ question = self.post_question(user=self.u1)
+ revision = question.revisions.all()[0]
+ ct = ContentType.objects.get_for_model(revision)
+ self.assertEqual('question', get_related_object_type_name(ct.id, revision.id))
+
+ def test_get_related_object_type_name_for_answer(self):
+ question = self.post_question(user=self.u1)
+ answer = self.post_answer(user=self.u1, question=question)
+ ct = ContentType.objects.get_for_model(answer)
+ self.assertEqual('answer', get_related_object_type_name(ct.id, answer.id))
+
+ def test_get_related_object_type_name_for_answer_revision(self):
+ question = self.post_question(user=self.u1)
+ answer = self.post_answer(user=self.u1, question=question)
+ revision = answer.revisions.all()[0]
+ ct = ContentType.objects.get_for_model(revision)
+ self.assertEqual('answer', get_related_object_type_name(ct.id, revision.id))
+
+ def test_get_related_object_type_name_for_anything_else_1(self):
+ ct = ContentType.objects.get_for_model(self.u2)
+ self.assertIsNone(get_related_object_type_name(ct.id, self.u2.id))
+
+ def test_get_related_object_type_name_for_anything_else_2(self):
+ question = self.post_question(user=self.u1)
+ comment = self.post_comment(user=self.u1, parent_post=question)
+ ct = ContentType.objects.get_for_model(comment)
+ self.assertIsNone(get_related_object_type_name(ct.id, comment.id))
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index 9c107112..442b1bd7 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -25,9 +25,10 @@ def patch_jinja2():
(CMAJOR, CMINOR, CMICRO) = package_utils.get_coffin_version()
if CMAJOR == 0 and CMINOR == 3 and CMICRO < 4:
+ import ipdb; ipdb.set_trace()
patch_jinja2()
-class PageLoadTestCase(TestCase):
+class PageLoadTestCase(AskbotTestCase):
def try_url(
self,
url_name, status_code=200, template=None,
@@ -66,8 +67,29 @@ class PageLoadTestCase(TestCase):
else:
raise Exception('unexpected error while runnig test')
-class PageLoadTests(PageLoadTestCase):
- fixtures = ['tmp/fixture2.json', ]
+ def setUp(self):
+ self.u1 = self.create_user(username='user1')
+ self.u2 = self.create_user(username='user2')
+ self.u3 = self.create_user(username='user3')
+
+ self.question = self.post_question(user=self.u1)
+
+ self.answer = self.post_answer(user=self.u1, question=self.question)
+ self.answer.id = 38 # one of the tests tries this id
+ self.answer.save()
+
+ self.question2 = self.post_question(user=self.u2)
+ self.question2.id = 2
+ self.question2.save()
+
+ self.question3 = self.post_question(user=self.u3)
+ self.question3.id = 3
+ self.question3.save()
+
+ self.question17 = self.post_question(user=self.u1)
+ self.question17.id = 17
+ self.question17.save()
+
def test_index(self):
#todo: merge this with all reader url tests