base.py 2.51 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
Nicolas Joyard's avatar
Nicolas Joyard committed
10
11
12
13
14
15
16
17
18
    - 5 for search forms
        - 1 for chambers
        - 1 for countries
        - 1 for parties
        - 1 for committees
        - 1 for delegations
    - 2 for the position form
        - 1 for representatives
        - 1 for themes
19
    """
Nicolas Joyard's avatar
Nicolas Joyard committed
20
    left_pane_queries = 7
21

Nicolas Joyard's avatar
Nicolas Joyard committed
22
23
24
    def request_test(self, url=None):
        self.assertResponseDiffEmpty(self.client.get(url or self.url))

Nicolas Joyard's avatar
Nicolas Joyard committed
25
26
27
    def selector_test(self, selector, url=None):
        self.assertResponseDiffEmpty(self.client.get(url or self.url),
                                     selector)
28
29
30
31


class RepresentativeBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
32
    base_url = '/representatives/olivier-dussopt-1978-08-16/%s/'
33
34
35
36
37
38
39
40
41
42
43

    """
    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
44
45
46
    - 1 for address country
    - 1 for phone numbers related to addresses
    - 1 for other phone numbers
47
    """
48
    queries = BaseTest.left_pane_queries + 11
49
50
51
52
53
54
55
56
57
58
59

    @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)
Nicolas Joyard's avatar
Nicolas Joyard committed
60
61
62
63


class ThemeBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
64
    base_url = '/themes/etat-durgence/%s/'
Nicolas Joyard's avatar
Nicolas Joyard committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

    """
    Common queries plus:
    - 1 for the theme
    """
    queries = BaseTest.left_pane_queries + 1

    @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)
Nicolas Joyard's avatar
Nicolas Joyard committed
82
83
84
85


class DossierBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
86
    base_url = '/dossiers/15409/%s/'
Nicolas Joyard's avatar
Nicolas Joyard committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

    """
    Common queries plus:
    - 1 for the dossier
    - 1 for related themes
    """
    queries = BaseTest.left_pane_queries + 2

    @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)