test_representatives_detail.py 2.35 KB
Newer Older
robin Tissot's avatar
robin Tissot committed
1
# -*- coding: utf-8 -*-
Jamesie Pic's avatar
Jamesie Pic committed
2
3
4
5
6
7
8
from django.test import TestCase

from .base import UrlGetTestMixin


class RepresentativeDetailTest(UrlGetTestMixin, TestCase):
    fixtures = ['one_representative']
Nicolas Joyard's avatar
Nicolas Joyard committed
9
    url = '/legislature/representative/mary-honeyball-1952-11-12/'
Jamesie Pic's avatar
Jamesie Pic committed
10
11
12
13
14

    def test_num_queries(self):
        # Ensure one-time cached queries occur before the actual test
        self.client.get(self.url)

15
        with self.assertNumQueries(11):
Jamesie Pic's avatar
Jamesie Pic committed
16
            """
17
            - One query for chambers
Jamesie Pic's avatar
Jamesie Pic committed
18
            - One query for the rep details and foreign key (profile)
19
20
21
            - One query for reverse relation on phones
            - One query for reverse relation on addresses
            - One query for reverse relation on emails
22
23
            - Three queries for reverse relation on websites (parliament,
              social and other)
Jamesie Pic's avatar
Jamesie Pic committed
24
25
26
27
28
29
30
31
            - One query for reverse relation on votes
            - One query for reverse relation on mandates
            - One query for reverse relation positions
            """
            self.client.get(self.url)

    def test_name_display(self):
        # When HAMLPY_ATTR_WRAPPER works, use double quotes in HTML attrs !
32
        self.assertHtmlInResult("<h1 class='text-left'>Mary HONEYBALL</h1>")
Jamesie Pic's avatar
Jamesie Pic committed
33
34
35
36
37
38
39
40
41
42

    def test_score_display(self):
        self.assertExpectedHtmlInResult()

    def test_country_display(self):
        self.assertHtmlInResult(
            '<span class="flag-icon flag-icon-gb"></span> United Kingdom')

    def test_current_mandate_display(self):
        expected = ''.join((
43
            "<a href='/legislature/representative/group/European%20Parliament/Group%20of%20the%20Progressive%20Alliance%20of%20Socialists%20and%20Democrats%20in%20the%20European%20Parliament/'>",  # noqa
Nicolas Joyard's avatar
Nicolas Joyard committed
44
            "<span class='group-icon' style='background-image: url(/static/collected/images/group-ep-sd.png)'></span>",  # noqa
Jamesie Pic's avatar
Jamesie Pic committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
            "Member of Group of the Progressive Alliance of Socialists and Democrats in the European Parliament",  # noqa
            "</a>",
        ))
        self.assertHtmlInResult(expected)

    def test_biography_display(self):
        self.assertHtmlInResult('Born in Weymouth the 12/11/1952 (F)')

    def test_votes_display(self):
        self.assertExpectedHtmlInResult()

    def test_mandates_display(self):
        self.assertExpectedHtmlInResult()

    def test_positions_display(self):
        self.assertExpectedHtmlInResult()