Ejemplo n.º 1
0
    def setUp(self):
        cache.clear()

        self.election = ElectionFactory(
            name="2017 General Election",
            election_date="2017-06-08",
            slug="parl.2017-06-08",
            any_non_by_elections=True,
        )
        self.post = PostFactory(ynr_id="WMC:E14000639",
                                label="Cities of London and Westminster")
        self.post_election = PostElectionFactory(
            ballot_paper_id="parl.cities-of-london-and-westminster.2017-06-08",
            post=self.post,
            election=self.election,
        )
        PersonFactory.reset_sequence()
        person = PersonFactory()
        pe = PostElectionFactory(election=self.election, post=self.post)
        PersonPostFactory(
            post_election=pe,
            election=self.election,
            person=person,
            post=self.post,
            party=PartyFactory(),
        )
        self.expected_response = [{
            "ballot_paper_id":
            "parl.cities-of-london-and-westminster.2017-06-08",
            "absolute_url":
            "http://testserver/elections/parl.cities-of-london-and-westminster.2017-06-08/cities-of-london-and-westminster/",
            "election_date":
            "2017-06-08",
            "election_id":
            "parl.2017-06-08",
            "election_name":
            "2017 General Election",
            "post": {
                "post_name": "Cities of London and Westminster",
                "post_slug": "WMC:E14000639",
            },
            "cancelled":
            False,
            "replaced_by":
            None,
            "ballot_locked":
            False,
            "candidates": [{
                "list_position": None,
                "party": {
                    "party_id": "PP01",
                    "party_name": "Test Party",
                },
                "person": {
                    "absolute_url": "http://testserver/person/0/candidate-0",
                    "ynr_id": 0,
                    "name": "Candidate 0",
                },
            }],
        }]
Ejemplo n.º 2
0
 def setUp(self):
     self.election = ElectionFactory(
         name="City of London Corporation local election",
         election_date="2017-03-23",
         slug="local.city-of-london.2017-03-23",
     )
     self.post = PostFactory(ynr_id="LBW:E05009288", label="Aldersgate")
Ejemplo n.º 3
0
    def test_division_suffix(self, mocker):
        description = mocker.PropertyMock(return_value="Foo Bar Division")
        mocker.patch.object(Post, "division_description", new=description)
        post = PostFactory.build()

        assert post.division_suffix == "division"
        description.assert_called_once()
Ejemplo n.º 4
0
    def test_division_description(self, division_type, description):
        """
        Test that for each division type choice, the correct description is
        returned
        """
        post = PostFactory.build(division_type=division_type)

        assert post.division_description == description
Ejemplo n.º 5
0
    def test_ical_view(self):
        election = ElectionFactory(slug="local.cambridgeshire.2017-05-04")
        post = PostFactory(ynr_id="CED:romsey",
                           label="Romsey",
                           elections=election)

        PostElectionFactory(post=post, election=election)
        response = self.client.get("/elections/CB13HU.ics", follow=True)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 6
0
 def setUp(self):
     self.election = ElectionFactory(
         name="Adur local election",
         election_date="2021-05-06",
         slug="local.adur.churchill.2021-05-06",
     )
     self.post = PostFactory(label="Adur local election")
     self.post_election = PostElectionFactory(election=self.election,
                                              post=self.post)
Ejemplo n.º 7
0
 def setUp(self):
     self.party = PartyFactory()
     self.election = ElectionFactory()
     self.post = PostFactory()
     PersonPostFactory(
         party=self.party,
         election=self.election,
         post=self.post,
     )
Ejemplo n.º 8
0
 def setUp(self):
     self.election = ElectionFactory()
     self.post = PostFactory()
     people = [PersonFactory() for p in range(5)]
     for person in people:
         PersonPostFactory(
             election=self.election,
             post=self.post,
             person=person,
         )
Ejemplo n.º 9
0
 def setUp(self):
     self.election = ElectionFactory(
         name="2017 General Election",
         election_date="2017-06-08",
         slug="parl.2017-06-08",
     )
     self.post = PostFactory(ynr_id="WMC:E14000639",
                             label="Cities of London and Westminster")
     self.post_election = PostElectionFactory(post=self.post,
                                              election=self.election)
Ejemplo n.º 10
0
    def test_mayor_election_postcode_lookup(self):
        election = ElectionFactory(slug="mayor.tower-hamlets.2018-05-03")
        post = PostFactory(ynr_id="tower-hamlets",
                           label="Tower Hamlets",
                           elections=election)

        PostElectionFactory(post=post, election=election)
        response = self.client.get("/elections/e32nx/", follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context["postelections"].count(), 1)
        self.assertContains(response, "Tower Hamlets")
Ejemplo n.º 11
0
 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_more_than_one_election(self):
        person = PersonFactory()
        election1 = ElectionFactory()
        election2 = ElectionFactory(slug="parl.2010")
        post1 = PostFactory(elections=election2)
        post2 = PostFactory(
            ynr_id="WMC:E14000645", label="Southwark", elections=election2
        )

        pe1 = PostElectionFactory(election=election1, post=post1)
        pe2 = PostElectionFactory(election=election2, post=post2)

        PersonPostFactory(
            person=person, post_election=pe1, post=post1, election=election1
        )

        PersonPostFactory(
            post_election=pe2, person=person, election=election2, post=post2
        )

        assert person.personpost_set.all().count() == 2
Ejemplo n.º 13
0
 def setUp(self):
     self.election = ElectionFactory(
         name="City of London Corporation local election",
         election_date="2017-03-23",
         slug="local.city-of-london.2017-03-23",
     )
     self.post = PostFactory(ynr_id="LBW:E05009288",
                             label="Aldersgate",
                             elections=self.election)
     PostElection.objects.get_or_create(
         election=self.election,
         post=self.post,
         ballot_paper_id="local.city-of-london.aldersgate.2017-03-23",
     )
Ejemplo n.º 14
0
    def setUp(self):
        self.election = ElectionFactory(
            name="2017 General Election",
            election_date="2017-06-08",
            slug="parl.2017-06-08",
        )
        winners = [
            {
                'person_id': 2809,
                'post_id': 'WMC:E14000803',
                'post_label': 'Maidenhead',
            },
            {
                'person_id': 357,
                'post_id': 'WMC:E14000608',
                'post_label': 'Buckingham',
            },
            {
                'person_id': 2811,
                'post_id': 'WMC:E14000803',
                'post_label': 'Maidenhead',
            },
            {
                'person_id': 34291,
                'post_id': 'WMC:E14000673',
                'post_label': 'Dulwich and West Norwood',
            },
        ]

        for person_info in winners:
            person = PersonFactory(pk=person_info['person_id'])
            post = PostFactory(
                ynr_id=person_info['post_id'],
                label=person_info['post_label']
            )
            PostElectionFactory(
                post=post,
                election=self.election
            )

            PersonPostFactory(
                person=person,
                election=self.election,
                post=post
            )
Ejemplo n.º 15
0
 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>")
Ejemplo n.º 16
0
    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
Ejemplo n.º 17
0
 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>.")
Ejemplo n.º 18
0
    def setUp(self):
        self.election = ElectionFactory(slug="mayor.tower-hamlets.2018-05-03")
        self.post = PostFactory(
            ynr_id="tower-hamlets",
            label="Tower Hamlets",
        )
        self.ballot = PostElectionFactory(
            post=self.post,
            election=self.election,
            ballot_paper_id="mayor.tower-hamlets.2018-05-03",
        )

        self.hust = Husting.objects.create(
            post_election=self.ballot,
            title="Local Election Hustings",
            url="https://example.com/hustings",
            starts=datetime(2017, 3, 23, 19, 00, tzinfo=utc),
            ends=datetime(2017, 3, 23, 21, 00, tzinfo=utc),
            location="St George's Church",
            postcode="BN2 1DW",
        )
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
    def setUp(self):
        self.election = ElectionFactory(
            name="2017 General Election",
            election_date="2017-06-08",
            slug="parl.2017-06-08",
        )
        winners = [
            {
                "person_id": 2809,
                "post_id": "WMC:E14000803",
                "post_label": "Maidenhead",
            },
            {
                "person_id": 357,
                "post_id": "WMC:E14000608",
                "post_label": "Buckingham",
            },
            {
                "person_id": 2811,
                "post_id": "WMC:E14000803",
                "post_label": "Maidenhead",
            },
            {
                "person_id": 34291,
                "post_id": "WMC:E14000673",
                "post_label": "Dulwich and West Norwood",
            },
        ]

        for person_info in winners:
            person = PersonFactory(pk=person_info["person_id"])
            post = PostFactory(ynr_id=person_info["post_id"],
                               label=person_info["post_label"])
            PostElectionFactory(post=post, election=self.election)

            PersonPostFactory(person=person, election=self.election, post=post)
Ejemplo n.º 21
0
    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>.",
        )
Ejemplo n.º 22
0
    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
Ejemplo n.º 23
0
 def post_obj(self, request):
     """
     Fixture to create a Post object with each division choice
     """
     return PostFactory(division_type=request.param[0])
Ejemplo n.º 24
0
 def test_full_label(self, mocker):
     suffix = mocker.PropertyMock(return_value="ward")
     mocker.patch.object(Post, "division_suffix", new=suffix)
     post = PostFactory.build(label="Ecclesall")
     assert post.full_label == "Ecclesall ward"
     suffix.assert_called_once()