test_group_list.py 2.13 KB
Newer Older
1
# -*- coding: utf-8 -*-
Nicolas Joyard's avatar
Nicolas Joyard committed
2
3
4

from django.test import TestCase

Nicolas Joyard's avatar
Nicolas Joyard committed
5
from .base import ResponseDiffMixin
Nicolas Joyard's avatar
Nicolas Joyard committed
6
7


Nicolas Joyard's avatar
Nicolas Joyard committed
8
class GroupListTest(ResponseDiffMixin, TestCase):
Nicolas Joyard's avatar
Nicolas Joyard committed
9
10
    fixtures = ['smaller_sample.json']

11
12
13
14
15
16
17
    def group_test(self, kind, active_only, numQueries):
        url = '/legislature/group/%s/' % kind

        # setup session variables
        self.client.get('%s?active_only=%s' % (url, active_only))

        self.responsediff_test(url, numQueries)
Nicolas Joyard's avatar
Nicolas Joyard committed
18
19
20

    def test_chambers(self):
        # 1 query for chambers
21
22
        # 1 query for pagination
        self.group_test('chamber', 1, 2)
Nicolas Joyard's avatar
Nicolas Joyard committed
23
24
25

    def test_country(self):
        # 1 query for countries
26
27
28
29
30
31
32
        # 1 query for pagination
        self.group_test('country', 1, 2)

    def test_active_parties(self):
        # 1 query for political groups
        # 1 query for pagination
        self.group_test('group', 1, 2)
Nicolas Joyard's avatar
Nicolas Joyard committed
33

34
    def test_all_parties(self):
Nicolas Joyard's avatar
Nicolas Joyard committed
35
        # 1 query for political groups
36
37
        # 1 query for pagination
        self.group_test('group', 0, 2)
Nicolas Joyard's avatar
Nicolas Joyard committed
38

39
    def test_active_delegations(self):
Nicolas Joyard's avatar
Nicolas Joyard committed
40
        # 1 query for delegations
41
42
43
44
45
46
47
48
49
50
51
52
        # 1 query for pagination
        self.group_test('delegation', 1, 2)

    def test_all_delegations(self):
        # 1 query for delegations
        # 1 query for pagination
        self.group_test('delegation', 0, 2)

    def test_active_committees(self):
        # 1 query for committees
        # 1 query for pagination
        self.group_test('committee', 1, 2)
Nicolas Joyard's avatar
Nicolas Joyard committed
53

54
    def test_all_committees(self):
Nicolas Joyard's avatar
Nicolas Joyard committed
55
        # 1 query for committees
56
57
        # 1 query for pagination
        self.group_test('committee', 0, 2)
58
59
60
61
62

    def group_ac_test(self, q, numQueries):
        if q:
            url = '/legislature/autocomplete/group/?q=%s' % q
        else:
63
            url = '/legislature/autocomplete/group/?'
64
65

        # setup session variables
66
        self.client.get('%s&active_only=0' % url)
67
68
69
70
71
72
73
74
75
76
77
78

        self.responsediff_test(url, numQueries)

    def test_autocomplete(self):
        # 1 query for count
        # 1 query for groups
        self.group_ac_test(None, 2)

    def test_autocomplete_query(self):
        # 1 query for count
        # 1 query for groups
        self.group_ac_test('development', 2)