<commit_before># Smoke tests for viewing a candidate's page

from datetime import date
import re

from mock import patch

from django.conf import settings
from django.test.utils import override_settings
from django_webtest import WebTest

from .fake_popit import FakePersonCollection


election_date_before = lambda r: {'DATE_TODAY': date(2015, 5, 1)}
election_date_after = lambda r: {'DATE_TODAY': date(2015, 6, 1)}
processors = settings.TEMPLATE_CONTEXT_PROCESSORS
processors_before = processors + ("candidates.tests.test_person_view.election_date_before",)
processors_after = processors + ("candidates.tests.test_person_view.election_date_after",)


@patch('candidates.popit.PopIt')
class TestPersonView(WebTest):

    def test_get_tessa_jowell(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertTrue(
            re.search(
                r'''(?msx)
  <h1>Tessa\s+Jowell</h1>\s*
  <p>Candidate\s+for\s+
  <a\s+href="/election/2015/post/65808/dulwich-and-west-norwood">Dulwich\s+
  and\s+West\s+Norwood</a>\s+in\ 2015\s*</p>''',
                unicode(response)
            )
        )

    @override_settings(TEMPLATE_CONTEXT_PROCESSORS=processors_before)
    def test_get_tessa_jowell_before_election(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertContains(response, 'Contesting in the 2015 General Election')

    @override_settings(TEMPLATE_CONTEXT_PROCESSORS=processors_after)
    def test_get_tessa_jowell_after_election(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertContains(response, 'Contested in the 2015 General Election')

    def test_get_non_existent(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get(
            '/person/987654/imaginary-person',
            expect_errors=True
        )
        self.assertEqual(response.status_code, 404)<commit_msg>Fix a test for viewing a person's page (should have gone in b61a127322)<commit_after># Smoke tests for viewing a candidate's page

from datetime import date
import re

from mock import patch

from django.conf import settings
from django.test.utils import override_settings
from django_webtest import WebTest

from .fake_popit import FakePersonCollection


election_date_before = lambda r: {'DATE_TODAY': date(2015, 5, 1)}
election_date_after = lambda r: {'DATE_TODAY': date(2015, 6, 1)}
processors = settings.TEMPLATE_CONTEXT_PROCESSORS
processors_before = processors + ("candidates.tests.test_person_view.election_date_before",)
processors_after = processors + ("candidates.tests.test_person_view.election_date_after",)


@patch('candidates.popit.PopIt')
class TestPersonView(WebTest):

    def test_get_tessa_jowell(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertTrue(
            re.search(
                r'''(?msx)
  <h1>Tessa\s+Jowell</h1>\s*
  <p>Candidate\s+for\s+
  <a\s+href="/election/2015/post/65808/dulwich-and-west-norwood">Dulwich\s+
  and\s+West\s+Norwood</a>\s+in\ 2015\s+General\s+Election\s*</p>''',
                unicode(response)
            )
        )

    @override_settings(TEMPLATE_CONTEXT_PROCESSORS=processors_before)
    def test_get_tessa_jowell_before_election(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertContains(response, 'Contesting in the 2015 General Election')

    @override_settings(TEMPLATE_CONTEXT_PROCESSORS=processors_after)
    def test_get_tessa_jowell_after_election(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get('/person/2009/tessa-jowell')
        self.assertContains(response, 'Contested in the 2015 General Election')

    def test_get_non_existent(self, mock_popit):
        mock_popit.return_value.persons = FakePersonCollection
        response = self.app.get(
            '/person/987654/imaginary-person',
            expect_errors=True
        )
        self.assertEqual(response.status_code, 404)
{'fraction_non_alphanumeric': 0.10394588500563698, 'fraction_numerical': 0.02705749718151071, 'mean_word_length': 3.9343715239154617, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7540376', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1412, 'n_words': 243}