base.py 2.71 KB
Newer Older
1 2
from django import test
from responsediff.test import ResponseDiffTestMixin
3
from memopol_scores.models import RepresentativeScore
4 5 6


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

    """
    Common queries
11
    - 1 for settings
Nicolas Joyard's avatar
Nicolas Joyard committed
12 13 14 15 16 17
    - 5 for search forms
        - 1 for chambers
        - 1 for countries
        - 1 for parties
        - 1 for committees
        - 1 for delegations
18
    """
Nicolas Joyard's avatar
Nicolas Joyard committed
19
    left_pane_queries = 6
20

21 22 23
    def setUp(self):
        RepresentativeScore.refresh()

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

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


class RepresentativeBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
34
    base_url = '/representatives/olivier-dussopt-1978-08-16/%s/'
35 36 37

    """
    Common queries plus:
38
    - 1 for session key
39 40 41 42 43 44 45 46
    - 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
47
    - 2 for phone numbers related to addresses
48
    - 1 for other phone numbers
49
    - 2 for themes and theme scores
Nicolas Joyard's avatar
Nicolas Joyard committed
50
    - 1 for DAL to fetch its initial value in the position form
51
    """
Nicolas Joyard's avatar
Nicolas Joyard committed
52
    queries = BaseTest.left_pane_queries + 15
53 54 55 56 57 58 59 60 61 62 63

    @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
64 65 66 67


class ThemeBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
68
    base_url = '/themes/etat-durgence/%s/'
Nicolas Joyard's avatar
Nicolas Joyard committed
69 70 71 72

    """
    Common queries plus:
    - 1 for the theme
Nicolas Joyard's avatar
Nicolas Joyard committed
73
    - 1 for DAL to fetch its initial value in the position form
Nicolas Joyard's avatar
Nicolas Joyard committed
74
    """
Nicolas Joyard's avatar
Nicolas Joyard committed
75
    queries = BaseTest.left_pane_queries + 2
Nicolas Joyard's avatar
Nicolas Joyard committed
76 77 78 79 80 81 82 83 84 85 86

    @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
87 88 89 90


class DossierBaseTest(BaseTest):
    tab = 'none'
Nicolas Joyard's avatar
Nicolas Joyard committed
91
    base_url = '/dossiers/15409/%s/'
Nicolas Joyard's avatar
Nicolas Joyard committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

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