summaryrefslogtreecommitdiffstats
path: root/askbot/tests/cache_tests.py
blob: a8416e99d7231ab5c0e331df032860c961998d54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.db import connection
from django.core.urlresolvers import reverse
from django.conf import settings
from askbot.tests.utils import AskbotTestCase


class CacheTests(AskbotTestCase):
    def setUp(self):
        user = self.create_user('other_user')
        self.question = self.post_question(user=user)
        self.post_answer(user=user, question=self.question)
        settings.DEBUG = True  # because it's forsed to False

    def visit_question(self):
        self.client.get(self.question.get_absolute_url(), follow=True)
        
    def test_anonymous_question_cache(self):

        self.visit_question()
        counter = len(connection.queries)
        print 'we have %d queries' % counter
        self.visit_question()

        #second hit to the same question should give fewer queries
        self.assertTrue(counter > len(connection.queries))
        settings.DEBUG = False

    def test_authentificated_no_question_cache(self):
        url = reverse('question', kwargs={'id': self.question.id})

        password = '123'
        self.other_user.set_password(password)
        self.client.login(username=self.other_user.username, password=password)

        self.visit_question()
        counter = len(connection.queries)
        self.visit_question()

        #expect the same number of queries both times
        self.assertEqual(counter, len(connection.queries))
        settings.DEBUG = False