def test_constituency_unlock(self):
     MembershipFactory(
         ballot=self.dulwich_post_ballot,
         person=PersonFactory(),
         party=PartyFactory(),
     )
     ballot = self.dulwich_post_ballot
     ballot.candidates_locked = True
     ballot.save()
     response = self.app.get(
         self.dulwich_post_ballot.get_absolute_url(),
         user=self.user_who_can_lock,
     )
     csrftoken = self.app.cookies["csrftoken"]
     self.assertContains(response, "Unlock candidate list")
     response = self.app.post(
         reverse(
             "constituency-lock",
             kwargs={"ballot_id": ballot.ballot_paper_id},
         ),
         params={"csrfmiddlewaretoken": csrftoken},
         user=self.user_who_can_lock,
     )
     ballot.refresh_from_db()
     self.assertFalse(ballot.candidates_locked)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.location,
                      self.dulwich_post_ballot.get_absolute_url())
Exemplo n.º 2
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",
                },
            }],
        }]
Exemplo n.º 3
0
 def test_candidates_for_postcode_view(self):
     person = PersonFactory()  # Make a person
     PersonPostFactory(election=self.election,
                       person=person,
                       post=self.post,
                       party=PartyFactory())
     url = reverse('api:candidates-for-postcode-list')
     with self.assertNumQueries(2):
         req = self.client.get("{}?postcode=EC1A4EU".format(url))
     assert req.status_code == 200
     assert req.data == [{
         'election_date':
         datetime.date(2017, 6, 8),
         'election_id':
         'parl.2017-06-08',
         'election_name':
         '2017 General Election',
         'post': {
             'post_name': 'Cities of London and Westminster',
             'post_slug': 'WMC:E14000639'
         },
         'candidates': [{
             'list_position': None,
             'party': {
                 'party_id': 'PP01',
                 'party_name': 'Test Party'
             },
             'person': {
                 'ynr_id': '0',
                 'name': 'Candidate 0'
             }
         }],
     }]
Exemplo n.º 4
0
 def test_display_deceased(self):
     self.party = PartyFactory()
     self.election = ElectionFactory()
     self.personpost = PersonPostFactory(person=self.person,
                                         party=self.party,
                                         election=self.election)
     self.person.death_date = "01/01/2021"
     assert self.person.display_deceased is True
Exemplo n.º 5
0
 def setUp(self):
     self.party = PartyFactory()
     self.election = ElectionFactory()
     self.post = PostFactory()
     PersonPostFactory(
         party=self.party,
         election=self.election,
         post=self.post,
     )
Exemplo n.º 6
0
 def test_one_candidacy_intro(self):
     election = ElectionFactory()
     party = PartyFactory(party_name="Conservative and Unionist Party",
                          party_id="ConUnion")
     person_post = PersonPostFactory(person=self.person,
                                     election=election,
                                     party=party)
     response = self.client.get(self.person_url, follow=True)
     self.assertContains(
         response,
         f"{self.person.name} is a {party.party_name} candidate in {person_post.post.label} in the {election.name}.",
     )
Exemplo n.º 7
0
 def test_local_party_for_non_local_election(self):
     party = PartyFactory(party_name="Labour Party", party_id="party:53")
     local_party = LocalPartyFactory(name="Welsh Labour | Llafur Cymru",
                                     is_local=False,
                                     parent=party)
     PersonPostFactory(
         person=self.person,
         election=ElectionFactory(),
         party=party,
     )
     response = self.client.get(self.person_url, follow=True)
     expected = f"{self.person.name} is a {local_party.label} candidate."
     self.assertContains(response, expected)
Exemplo n.º 8
0
 def test_local_party_for_local_election(self):
     party = PartyFactory(party_name="Labour Party", party_id="party:53")
     local_party = LocalPartyFactory(name="Derbyshire Labour",
                                     is_local=True,
                                     parent=party)
     PersonPostFactory(
         person=self.person,
         election=ElectionFactory(),
         party=party,
     )
     response = self.client.get(self.person_url, follow=True)
     expected = f"{self.person.name}'s local party is {local_party.label}."
     self.assertContains(response, expected)
Exemplo n.º 9
0
 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")
Exemplo n.º 10
0
 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:")
Exemplo n.º 11
0
 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:",
     )
Exemplo n.º 12
0
 def setUp(self):
     self.party = PartyFactory()
     self.person = PersonFactory()
     self.person_url = self.person.get_absolute_url()
Exemplo n.º 13
0
    def setUpTestData(cls):
        super(UK2015ExamplesMixin, cls).setUpTestData()
        cls.gb_parties = factories.PartySetFactory.create(slug="gb",
                                                          name="Great Britain")
        cls.ni_parties = factories.PartySetFactory.create(
            slug="ni", name="Northern Ireland")
        cls.commons = factories.ParliamentaryChamberFactory.create()
        # Create the 2010 and 2015 general elections:
        cls.election = factories.ElectionFactory.create(
            slug="parl.2015-05-07",
            name="2015 General Election",
            for_post_role="Member of Parliament",
            organization=cls.commons,
        )
        cls.earlier_election = factories.EarlierElectionFactory.create(
            slug="parl.2010-05-06",
            name="2010 General Election",
            for_post_role="Member of Parliament",
            current=False,
            organization=cls.commons,
        )
        # Create some example parties:
        PartyFactory.reset_sequence()

        for party in EXAMPLE_PARTIES:
            p = PartyFactory(
                ec_id=party["ec_id"],
                name=party["name"],
                legacy_slug=party["legacy_slug"],
                register=party["register"],
            )
            setattr(cls, party["attr"], p)

        # Create some example posts as well:
        EXAMPLE_CONSTITUENCIES = [
            {
                "id": "14419",
                "name": "Edinburgh East",
                "country": "Scotland",
                "attr": "edinburgh_east_post",
            },
            {
                "id": "14420",
                "name": "Edinburgh North and Leith",
                "country": "Scotland",
                "attr": "edinburgh_north_post",
            },
            {
                "id": "65808",
                "name": "Dulwich and West Norwood",
                "country": "England",
                "attr": "dulwich_post",
            },
            {
                "id": "65913",
                "name": "Camberwell and Peckham",
                "country": "England",
                "attr": "camberwell_post",
            },
        ]
        for cons in EXAMPLE_CONSTITUENCIES:
            label = "Member of Parliament for {}".format(cons["name"])
            post = factories.PostFactory.create(
                elections=(cls.election, cls.earlier_election),
                organization=cls.commons,
                slug=cons["id"],
                label=label,
                party_set=cls.gb_parties,
                group=cons["country"],
            )

            setattr(cls, cons["attr"], post)

            pee_attr_name = "{}_pee".format(cons["attr"])
            pee = post.postextraelection_set.get(election=cls.election)
            setattr(cls, pee_attr_name, pee)

            pee_attr_name = "{}_pee_earlier".format(cons["attr"])
            pee = post.postextraelection_set.get(election=cls.earlier_election)
            setattr(cls, pee_attr_name, pee)

        # Also create a local election and post:
        cls.local_council = factories.OrganizationFactory.create(
            name="Maidstone", slug="local-authority:maidstone")
        cls.local_election = factories.ElectionFactory.create(
            slug="local.maidstone.2016-05-05",
            organization=cls.local_council,
            name="Maidstone local election",
            for_post_role="Local Councillor",
            election_date=date(2016, 5, 5),
        )
        cls.local_post = factories.PostFactory.create(
            elections=(cls.local_election, ),
            slug="DIW:E05005004",
            label="Shepway South Ward",
            party_set=cls.gb_parties,
            organization=cls.local_council,
        )

        cls.local_pee = cls.local_post.postextraelection_set.get()
 def create_party(self):
     return PartyFactory()
Exemplo n.º 15
0
 def setUp(self):
     PartyFactory(ec_id="PP85", name="UK Independence Party (UKIP)")