Skip to content

Commit

Permalink
Display correct polls open msg in PostcodeView
Browse files Browse the repository at this point in the history
- Update template to display polls open/close times for specific
election object
- Does not account for edge case where an there is a local and other
election within the City of London
  • Loading branch information
michaeljcollinsuk committed Feb 2, 2021
1 parent e0b200a commit bdd1594
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ <h3>{{ voter_id_required.0.1.title }}</h3>
You don't need to take your poll card with you{% if not postcode|ni_postcode %}, or any identification{% endif %}.
{% endif %}


{% if polling_station.polling_station_known %}
<p>
Your polling station is <strong>{{ polling_station.polling_station.properties.address }}</strong>.
Expand All @@ -46,7 +45,9 @@ <h3>{{ voter_id_required.0.1.title }}</h3>
{% else %}
{% now "j F Y" as current_day %}
{% if elections_by_date and elections_by_date.0.grouper|date:"j F Y" == current_day %}
<strong>Polling stations are open from 7am till 10pm today.</strong>
{% with today_election=elections_by_date.0.list.0.election %}
<strong>Polling stations are open from {{ today_election.polls_open|time:"ga" }} till {{ today_election.polls_close|time:"ga" }} today.</strong>
{% endwith %}
{% endif %}
{% if polling_station.addresses %}
<p>Your polling station in {{ postcode }} depends on your address. <a href="https://wheredoivote.co.uk/postcode/{{ postcode }}/">Check the correct polling station for your address &raquo;</a></p>
Expand Down
62 changes: 62 additions & 0 deletions wcivf/apps/elections/tests/test_postcode_views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import pytest
import vcr

from django.urls import reverse
from django.test import TestCase, override_settings
from pytest_django import asserts
from elections.models import PostElection

from elections.tests.factories import (
ElectionFactory,
PostFactory,
PostElectionFactory,
)
from core.models import LoggedPostcode, write_logged_postcodes
from elections.views.postcode_view import PostcodeView


@override_settings(
Expand Down Expand Up @@ -67,3 +72,60 @@ def test_mayor_election_postcode_lookup(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["postelections"].count(), 1)
self.assertContains(response, "Tower Hamlets")


@pytest.mark.freeze_time("2021-05-06")
@pytest.mark.django_db
class TestPostcodeViewPolls:
"""
Tests to check that the PostcodeView response contains correct polling
station opening timnes
"""

@pytest.fixture(autouse=True)
def mock_ballots(self, mocker):
"""
Patchs the postcode_to_ballots method to simply return a QS with the
object created for the test
"""
mocker.patch.object(
PostcodeView,
"postcode_to_ballots",
return_value=PostElection.objects.all(),
)

def test_city_of_london_today(self, client):
PostElectionFactory(
election__slug="local.city-of-london.2021-05-06",
election__election_date="2021-05-06",
)
response = client.get(
reverse("postcode_view", kwargs={"postcode": "TE11ST"}), follow=True
)
asserts.assertContains(
response, "Polling stations are open from 8a.m. till 8p.m. today"
)

def test_not_city_of_london_today(self, client):
PostElectionFactory(
election__slug="local.sheffield.2021-05-06",
election__election_date="2021-05-06",
)
response = client.get(
reverse("postcode_view", kwargs={"postcode": "TE11ST"}), follow=True
)
asserts.assertContains(
response, "Polling stations are open from 7a.m. till 10p.m. today"
)

def test_not_today(self, client):
PostElectionFactory(
election__slug="local.sheffield.2021-05-06",
election__election_date="2021-05-07",
)
response = client.get(
reverse("postcode_view", kwargs={"postcode": "TE11ST"}), follow=True
)
asserts.assertNotContains(
response, "Polling stations are open from 7a.m. till 10p.m. today"
)

0 comments on commit bdd1594

Please sign in to comment.