summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-26 13:49:07 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-26 13:50:45 +0100
commit92451a78e2fb5009e088beea6b741966619075ff (patch)
tree867ccc1d571e70983837e0e5e14a82c75444a012
parent203fa05371c32bac09020fd4903addbaa8de8526 (diff)
downloadaskbot-92451a78e2fb5009e088beea6b741966619075ff.tar.gz
askbot-92451a78e2fb5009e088beea6b741966619075ff.tar.bz2
askbot-92451a78e2fb5009e088beea6b741966619075ff.zip
Adjusted code to make unit tests pass
-rwxr-xr-x.gitignore1
-rw-r--r--askbot/skins/default/templates/widgets/question_summary.html3
-rw-r--r--askbot/tests/page_load_tests.py34
-rw-r--r--askbot/tests/post_model_tests.py7
4 files changed, 32 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index dc9e2f72..586c4c8a 100755
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@ tmp/*
/manage.py
/urls.py
/log
+/prof
load
askbot/skins/default/media/js/flot
askbot/skins/common/media/js/closure/google-closure
diff --git a/askbot/skins/default/templates/widgets/question_summary.html b/askbot/skins/default/templates/widgets/question_summary.html
index 6ab59de5..56154847 100644
--- a/askbot/skins/default/templates/widgets/question_summary.html
+++ b/askbot/skins/default/templates/widgets/question_summary.html
@@ -42,7 +42,8 @@
</div>
<div style="clear:both"></div>
<div class="userinfo">
- <span class="relativetime" title="{{thread.last_activity_at}}">{{ thread.last_activity_at|diff_date }}</span>
+ {# We have to kill microseconds below because InnoDB doesn't support them and all kinds of funny things happen in unit tests #}
+ <span class="relativetime" title="{{thread.last_activity_at.replace(microsecond=0)}}">{{ thread.last_activity_at|diff_date }}</span>
{% if question.is_anonymous %}
<span class="anonymous">{{ thread.last_activity_by.get_anonymous_name() }}</span>
{% else %}
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index 18d8d69c..10bded11 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -3,6 +3,8 @@ from django.test import signals
from django.conf import settings
from django.core.urlresolvers import reverse
from django.core import management
+from django.core.cache.backends.dummy import DummyCache
+from django.core import cache
import coffin
import coffin.template
@@ -63,6 +65,13 @@ class PageLoadTestCase(AskbotTestCase):
#############################################
+ def setUp(self):
+ self.old_cache = cache.cache
+ cache.cache = DummyCache('', {}) # Disable caching (to not interfere with production cache, not sure if that's possible but let's not risk it)
+
+ def tearDown(self):
+ cache.cache = self.old_cache # Restore caching
+
def try_url(
self,
url_name, status_code=200, template=None,
@@ -99,16 +108,18 @@ class PageLoadTestCase(AskbotTestCase):
#asuming that there is more than one template
template_names = ','.join([t.name for t in r.template])
print 'templates are %s' % template_names
- if follow == False:
- self.fail(
- ('Have issue accessing %s. '
- 'This should not have happened, '
- 'since you are not expecting a redirect '
- 'i.e. follow == False, there should be only '
- 'one template') % url
- )
-
- #self.assertEqual(r.template[0].name, template)
+ # The following code is no longer relevant because we're using
+ # additional templates for cached fragments [e.g. thread.get_summary_html()]
+# if follow == False:
+# self.fail(
+# ('Have issue accessing %s. '
+# 'This should not have happened, '
+# 'since you are not expecting a redirect '
+# 'i.e. follow == False, there should be only '
+# 'one template') % url
+# )
+#
+# self.assertEqual(r.template[0].name, template)
self.assertIn(template, [t.name for t in r.template])
else:
raise Exception('unexpected error while runnig test')
@@ -120,7 +131,8 @@ class PageLoadTestCase(AskbotTestCase):
self.assertEqual(response.status_code, 200)
self.failUnless(len(response.redirect_chain) == 1)
self.failUnless(response.redirect_chain[0][0].endswith('/questions/'))
- self.assertEquals(response.template.name, 'main_page.html')
+ self.assertTrue(isinstance(response.template, list))
+ self.assertIn('main_page.html', [t.name for t in response.template])
def proto_test_ask_page(self, allow_anonymous, status_code):
prev_setting = askbot_settings.ALLOW_POSTING_BEFORE_LOGGING_IN
diff --git a/askbot/tests/post_model_tests.py b/askbot/tests/post_model_tests.py
index 1cac808e..06bceca1 100644
--- a/askbot/tests/post_model_tests.py
+++ b/askbot/tests/post_model_tests.py
@@ -528,7 +528,10 @@ class ThreadRenderCacheUpdateTests(AskbotTestCase):
question = self.post_question()
self.assertEqual(1, Post.objects.count())
- thread = question.thread
+ #thread = question.thread
+ # get fresh Thread instance so that on MySQL it has timestamps without microseconds
+ thread = Thread.objects.get(id=question.thread.id)
+
self.assertEqual(0, thread.answer_count)
self.assertEqual(thread.last_activity_at, question.added_at)
self.assertEqual(thread.last_activity_by, question.author)
@@ -558,6 +561,8 @@ class ThreadRenderCacheUpdateTests(AskbotTestCase):
def test_edit_answer(self):
self.assertEqual(0, Post.objects.count())
question = self.post_question()
+ # get fresh question Post instance so that on MySQL it has timestamps without microseconds
+ question = Post.objects.get(id=question.id)
self.assertEqual(question.thread.last_activity_at, question.added_at)
self.assertEqual(question.thread.last_activity_by, question.author)