def test_election_lazy_slug(self): """ Test generated slug can be used to reverse url """ election = ElectionFactoryLazySlug.build() slug = election.slug name = slugify(election.name) assert election.get_absolute_url() == f"/elections/{slug}/{name}/"
def test_next_election_not_displayed_in_past(self, client): post = PostFactory() past = PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2019-5-2", current=False, ), ) # create an election that just passed PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2021-5-6", current=True, ), ) response = client.get(past.get_absolute_url(), follow=True) assertNotContains(response, "<h3>Next election</h3>")
def test_past_registration_deadline(self, post_election): post = PostFactory(territory="ENG") oldest = PostElectionFactory( ballot_paper_id="parl.cities-of-london-and-westminster.2019-05-06", post=post, election=ElectionFactoryLazySlug(election_date="2019-5-6", current=False, election_type="parl"), ) future = PostElectionFactory( ballot_paper_id="parl.cities-of-london-and-westminster.2021-05-06", post=post, election=ElectionFactoryLazySlug(election_date="2021-5-6", current=True, election_type="parl"), ) assert oldest.past_registration_deadline is True assert future.past_registration_deadline is False
def setUp(self): # create some Election objects with different dates future_current_election = ElectionFactoryLazySlug( election_date=timezone.datetime(2021, 5, 6), current=True) future_not_current_election = ElectionFactoryLazySlug( election_date=timezone.datetime(2021, 5, 6), current=False) past_current_election = ElectionFactoryLazySlug( current=True, election_date=timezone.datetime(2021, 1, 1)) past_not_current = ElectionFactoryLazySlug( current=False, election_date=timezone.datetime(2017, 6, 8)) # create the 'candidacy' like objects self.in_future_current = PersonPostFactory( election=future_current_election, ) self.in_future_not_current = PersonPostFactory( election=future_not_current_election, ) self.in_past_current = PersonPostFactory( election=past_current_election) self.in_past_not_current = PersonPostFactory(election=past_not_current)
def test_next_election_is_today(self, client): post = PostFactory() past = PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2019-5-2", current=False, ), ) # create an election taking place today PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2021-5-6", current=True, ), ) response = client.get(past.get_absolute_url(), follow=True) assertContains(response, "<h3>Next election</h3>") assertContains(response, "<strong>being held today</strong>.")
def test_next_election_not_displayed_for_current_election(self, client): post = PostFactory() current = PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2021-5-6", current=True, ), ) response = client.get(current.get_absolute_url(), follow=True) assertNotContains(response, "<h3>Next election</h3>")
def test_past(self): """ Asset that non-current elections with a past election date are returned """ current_future = ElectionFactoryLazySlug(current=True, election_date="2021-5-6") not_current_future = ElectionFactoryLazySlug( current=False, election_date="2021-5-6", ) current_past = ElectionFactoryLazySlug(current=True, election_date="2021-1-1") not_current_past = ElectionFactoryLazySlug(current=False, election_date="2021-1-1") qs = Election.objects.past() assert qs.count() == 1 self.assertNotIn(current_future, qs) self.assertNotIn(not_current_future, qs) self.assertNotIn(current_past, qs) self.assertIn(not_current_past, qs)
def test_previous_elections(self): past_election = ElectionFactoryLazySlug(election_date="2019-05-02", current=False) party = PartyFactory(party_name="Liberal Democrat", party_id="foo") PersonPostFactory( person=self.person, post_election__election=past_election, election=past_election, party=party, votes_cast=1000, ) response = self.client.get(self.person_url, follow=True) self.assertContains(response, "Previous Elections")
def test_next_ballot_different_election_type(self): post = PostFactory() local = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2019-5-6", current=False, election_type="local"), ) mayoral = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2020-5-6", current=False, election_type="mayor"), ) next_local = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2021-5-6", current=True, election_type="local"), ) assert local.next_ballot == next_local assert mayoral.next_ballot is None
def test_multiple_independent_candidacies_intro(self): election_one = ElectionFactory() election_two = ElectionFactoryLazySlug() party = PartyFactory(party_name="Independent", party_id="ynmp-party:2") PersonPostFactory(person=self.person, election=election_one, party=party) PersonPostFactory(person=self.person, election=election_two, party=party) response = self.client.get(self.person_url, follow=True) self.assertContains( response, "is an Independent candidate in the following elections:")
def test_multiple_candidacies_intro(self): election_one = ElectionFactory() election_two = ElectionFactoryLazySlug() party = PartyFactory(party_name="Liberal Democrat", party_id="foo") PersonPostFactory(person=self.person, election=election_one, party=party) PersonPostFactory(person=self.person, election=election_two, party=party) response = self.client.get(self.person_url, follow=True) self.assertContains( response, "is a Liberal Democrat candidate in the following elections:", )
def test_next_election_displayed(self, client): post = PostFactory() past = PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2019-5-2", current=False, ), ) # create a future election expected to be displayed PostElectionFactory( post=post, election=ElectionFactoryLazySlug( election_date="2021-5-6", current=True, ), ) response = client.get(past.get_absolute_url(), follow=True) assertContains(response, "<h3>Next election</h3>") assertContains( response, "due to take place <strong>on Thursday 6 May 2021</strong>.", )
def test_next_ballot(self): post = PostFactory() oldest = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2019-5-6", current=False, election_type="local"), ) old = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2020-5-6", current=False, election_type="local"), ) future = PostElectionFactory( post=post, election=ElectionFactoryLazySlug(election_date="2021-5-6", current=True, election_type="local"), ) assert oldest.next_ballot == future assert old.next_ballot == future assert future.next_ballot is None