base.py 1.36 KB
Newer Older
1
2
3
4
5
from django import test
from responsediff.test import ResponseDiffTestMixin


class BaseTest(ResponseDiffTestMixin, test.TestCase):
6
    fixtures = ['data_sample.json']
7
8
9

    """
    Common queries
10
11
12
13
14
    - 1 for chambers
    - 1 for countries
    - 1 for parties
    - 1 for committees
    - 1 for delegations
15
16
17
    """
    left_pane_queries = 5

Nicolas Joyard's avatar
Nicolas Joyard committed
18
19
20
    def request_test(self, url=None):
        self.assertResponseDiffEmpty(self.client.get(url or self.url))

Nicolas Joyard's avatar
Nicolas Joyard committed
21
22
23
    def selector_test(self, selector, url=None):
        self.assertResponseDiffEmpty(self.client.get(url or self.url),
                                     selector)
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


class RepresentativeBaseTest(BaseTest):
    tab = 'none'
    base_url = '/legislature/representative/olivier-dussopt-1978-08-16/%s/'

    """
    Common queries plus:
    - 1 for chamber abbreviations (helper for chamber websites)
    - 1 for the representative
    - 1 for the main mandate
    - 1 for emails
    - 1 for social websites
    - 1 for chamber websites
    - 1 for other websites
    - 1 for addresses
    - 1 for phone numbers
    """
    queries = BaseTest.left_pane_queries + 9

    @property
    def url(self):
        return self.base_url % self.tab

    def do_query_test(self):
        # First query to set session variables
        self.client.get(self.url)

        with self.assertNumQueries(self.queries):
            self.client.get(self.url)