diff options
Diffstat (limited to 'askbot/tests')
-rw-r--r-- | askbot/tests/db_api_tests.py | 35 | ||||
-rw-r--r-- | askbot/tests/permission_assertion_tests.py | 38 |
2 files changed, 65 insertions, 8 deletions
diff --git a/askbot/tests/db_api_tests.py b/askbot/tests/db_api_tests.py index 00091934..e1268d9f 100644 --- a/askbot/tests/db_api_tests.py +++ b/askbot/tests/db_api_tests.py @@ -4,6 +4,10 @@ functions that happen on behalf of users e.g. ``some_user.do_something(...)`` """ from django.core import exceptions +from django.core.urlresolvers import reverse +from django.db import connection +from django.test.client import Client +from django.conf import settings from askbot.tests.utils import AskbotTestCase from askbot import models from askbot import const @@ -39,6 +43,37 @@ class DBApiTests(AskbotTestCase): self.assertTrue(post.deleted_by == None) self.assertTrue(post.deleted_at == None) + def test_anonymous_question_cache(self): + question = self.post_question() + settings.DEBUG = True # because it's forsed to False + url = reverse('question', kwargs={'id': question.id}) + + client = Client() + client.get(url, follow=True) + counter = len(connection.queries) + client.get(url, follow=True) + + self.assertTrue(counter > len(connection.queries)) + self.assertEqual(3, len(connection.queries)) # session-related only + settings.DEBUG = False + + def test_authentificated_no_question_cache(self): + question = self.post_question() + settings.DEBUG = True # because it's forsed to False + url = reverse('question', kwargs={'id': question.id}) + + password = '123' + client = Client() + self.other_user.set_password(password) + client.login(username=self.other_user.username, password=password) + + client.get(url, follow=True) + counter = len(connection.queries) + client.get(url, follow=True) + + self.assertEqual(counter, len(connection.queries)) + settings.DEBUG = False + def test_flag_question(self): self.user.set_status('m') self.user.flag_post(self.question) diff --git a/askbot/tests/permission_assertion_tests.py b/askbot/tests/permission_assertion_tests.py index 83476c79..fc1fbcb7 100644 --- a/askbot/tests/permission_assertion_tests.py +++ b/askbot/tests/permission_assertion_tests.py @@ -1368,23 +1368,27 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): self.third_user.reputation = 1000000 self.assert_user_cannot(user = self.third_user) - def test_moderator_cannot_accept_others_answer(self): - self.other_post_answer() - self.create_user(username = 'third_user') - self.third_user.set_status('m') - self.assert_user_cannot(user = self.third_user) - def test_moderator_cannot_accept_own_answer(self): self.other_post_answer() self.other_user.set_status('m') self.assert_user_cannot(user = self.other_user) - def test_admin_cannot_accept_others_answer(self): + def test_moderator_cannot_accept_others_answer_today(self): + self.other_post_answer() + self.create_user(username = 'third_user') + self.third_user.set_status('m') + self.assert_user_cannot(user = self.third_user) + + def test_moderator_can_accept_others_old_answer(self): self.other_post_answer() + self.answer.added_at -= datetime.timedelta( + days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1 + ) + self.answer.save() self.create_user(username = 'third_user') self.third_user.set_admin_status() self.third_user.save() - self.assert_user_cannot(user = self.third_user) + self.assert_user_can(user = self.third_user) def test_admin_cannot_accept_own_answer(self): self.other_post_answer() @@ -1392,6 +1396,24 @@ class AcceptBestAnswerPermissionAssertionTests(utils.AskbotTestCase): self.other_user.save() self.assert_user_cannot(user = self.other_user) + def test_admin_cannot_accept_others_answer_today(self): + self.other_post_answer() + self.create_user(username = 'third_user') + self.third_user.set_admin_status() + self.third_user.save() + self.assert_user_cannot(user = self.third_user) + + def test_admin_can_accept_others_old_answer(self): + self.other_post_answer() + self.answer.added_at -= datetime.timedelta( + days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1 + ) + self.answer.save() + self.create_user(username = 'third_user') + self.third_user.set_admin_status() + self.third_user.save() + self.assert_user_can(user = self.third_user) + class VotePermissionAssertionTests(PermissionAssertionTestCase): """Tests permission for voting """ |