test_views.py 1.46 KB
Newer Older
1 2 3
from django import test

from responsediff.response import Response
Jamesie Pic's avatar
Jamesie Pic committed
4 5


6
class RepresentativeManagerTest(test.TestCase):
Jamesie Pic's avatar
Jamesie Pic committed
7 8
    fixtures = ['representatives_test.json']

9
    def functional_test(self, queries, url):
Nicolas Joyard's avatar
Nicolas Joyard committed
10 11 12 13 14
        client = test.client.Client()

        # First query to setup session
        client.get(url)

15
        with self.assertNumQueries(queries):
Nicolas Joyard's avatar
Nicolas Joyard committed
16
            result = client.get(url)
17 18 19 20 21 22 23 24 25 26 27
        Response.for_test(self).assertNoDiff(result)

    def test_constituencies_api(self):
        self.functional_test(1, '/api/constituencies/?format=json')

    def test_groups_api(self):
        self.functional_test(1, '/api/groups/?format=json')

    def test_mandates_api(self):
        self.functional_test(1, '/api/mandates/?format=json')

Nicolas Joyard's avatar
Nicolas Joyard committed
28 29 30
    def test_chambers_api(self):
        self.functional_test(1, '/api/chambers/?format=json')

31 32 33 34 35 36 37 38 39 40 41 42
    def test_representatives_api(self):
        """
        Queries:

        - representatives,
        - emails,
        - websites,
        - addresses,
        - phones,
        - mandates.
        """
        self.functional_test(6, '/api/representatives/?format=json')
okhin's avatar
okhin committed
43 44 45
        # Test the filters

    def test_representatives_api_mandates(self):
okhin's avatar
okhin committed
46 47
        self.functional_test(1, '/api/representatives/' +
                '?active_mandates=INTA' + '&format=json')
okhin's avatar
okhin committed
48 49

    def test_representatives_api_constituency(self):
okhin's avatar
okhin committed
50 51
        self.functional_test(6, '/api/representatives/' +
                '?active_constituency=European%20Parliament' + '&format=json')