test_dossiers.py 2.3 KB
Newer Older
1
# -*- coding: utf-8 -*-
Nicolas Joyard's avatar
Nicolas Joyard committed
2
3
4
5
6
7
8
9
10
11
12
13

from django.test import TestCase

from representatives_votes.models import Dossier

from .base import ResponseDiffMixin


class DossiersTest(ResponseDiffMixin, TestCase):
    fixtures = ['smaller_sample.json']

    def test_dossier_list(self):
14
15
16
        # session setup
        self.client.get('/votes/dossier/')

Nicolas Joyard's avatar
Nicolas Joyard committed
17
        # 1 query for chamber list (search form)
Nicolas Joyard's avatar
Nicolas Joyard committed
18
19
20
21
        # 1 query for dossier count
        # 1 query for dossiers
        # 1 query for proposals
        # 1 query for recommendations
Nicolas Joyard's avatar
Nicolas Joyard committed
22
23
24
        # 1 query for documents
        # 1 query for document chambers
        self.responsediff_test('/votes/dossier/', 7)
Nicolas Joyard's avatar
Nicolas Joyard committed
25

Nicolas Joyard's avatar
Nicolas Joyard committed
26
27
28
29
    def test_dossier_search(self):
        # session setup
        self.client.get('/votes/dossier/')

Nicolas Joyard's avatar
Nicolas Joyard committed
30
        # 1 query for chamber list (search form)
Nicolas Joyard's avatar
Nicolas Joyard committed
31
32
33
34
        # 1 query for dossier count
        # 1 query for dossiers
        # 1 query for proposals
        # 1 query for recommendations
Nicolas Joyard's avatar
Nicolas Joyard committed
35
36
        # 1 query for documents
        # 1 query for document chambers
Nicolas Joyard's avatar
Nicolas Joyard committed
37
        q = 'acta'
Nicolas Joyard's avatar
Nicolas Joyard committed
38
        self.responsediff_test('/votes/dossier/?search=%s' % q, 7)
Nicolas Joyard's avatar
Nicolas Joyard committed
39
40
41
42
43

    def test_dossier_search_noresults(self):
        # session setup
        self.client.get('/votes/dossier/')

Nicolas Joyard's avatar
Nicolas Joyard committed
44
        # 1 query for chamber list (search form)
Nicolas Joyard's avatar
Nicolas Joyard committed
45
46
47
        # 1 query for dossier count
        # nothing else since count = 0
        q = 'no-dossier-will-have-that-title-ever'
Nicolas Joyard's avatar
Nicolas Joyard committed
48
        self.responsediff_test('/votes/dossier/?search=%s' % q, 2)
Nicolas Joyard's avatar
Nicolas Joyard committed
49

Nicolas Joyard's avatar
Nicolas Joyard committed
50
51
52
53
54
55
56
57
58
59
60
61
62
    def test_dossier_sorting(self):
        # session setup
        self.client.get('/votes/dossier/?sort_by=title&sort_dir=desc')

        # 1 query for chamber list (search form)
        # 1 query for dossier count
        # 1 query for dossiers
        # 1 query for proposals
        # 1 query for recommendations
        # 1 query for documents
        # 1 query for document chambers
        self.responsediff_test('/votes/dossier/', 7)

Nicolas Joyard's avatar
Nicolas Joyard committed
63
64
65
66
    def test_dossier_detail(self):
        # Get 1st dossier in dataset
        dossier = Dossier.objects.order_by('pk')[0]

67
68
69
        # session setup
        self.client.get('/votes/dossier/%s/' % dossier.pk)

Nicolas Joyard's avatar
Nicolas Joyard committed
70
71
72
        # 1 query for the dossier
        # 1 query for proposals
        # 1 query for recommendations
Nicolas Joyard's avatar
Nicolas Joyard committed
73
74
75
        # 1 query for documents
        # 1 query for document chambers
        self.responsediff_test('/votes/dossier/%s/' % dossier.pk, 5)