Ejemplo n.º 1
0
    def test_adding_to_existing_person_same_election(self):
        # This could happen if someone's missed that there was the
        # same person already listed on the first page, but then
        # spotted them on the review page and said to merge them then.
        existing_person = people.tests.factories.PersonFactory.create(
            id="1234567", name="Bart Simpson")
        existing_membership = factories.MembershipFactory.create(
            person=existing_person,
            # !!! This is the line that differs from the previous test:
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.election.postextraelection_set.get(
                post=self.dulwich_post),
        )
        memberships_before = membership_id_set(existing_person)
        # Now try adding that person via bulk add:
        OfficialDocument.objects.create(
            election=self.election,
            post=self.dulwich_post,
            source_url="http://example.com",
            document_type=OfficialDocument.NOMINATION_PAPER,
            post_election=self.dulwich_post_pee,
            uploaded_file="sopn.pdf",
        )

        response = self.app.get("/bulk_adding/sopn/2015/65808/",
                                user=self.user)

        form = response.forms["bulk_add_form"]
        form["form-0-name"] = "Bart Simpson"
        form["form-0-party"] = self.green_party.ec_id

        response = form.submit()
        self.assertEqual(response.status_code, 302)

        # This takes us to a page with a radio button for adding them
        # as a new person or alternative radio buttons if any
        # candidates with similar names were found.
        response = response.follow()
        form = response.forms[1]
        form["form-0-select_person"].select("1234567")
        response = form.submit()

        person = Person.objects.get(name="Bart Simpson")
        memberships_after = membership_id_set(person)
        new_memberships = memberships_after - memberships_before
        self.assertEqual(len(new_memberships), 0)
        same_memberships = memberships_before & memberships_after
        self.assertEqual(len(same_memberships), 1)
        same_membership = Membership.objects.get(pk=list(same_memberships)[0])
        self.assertEqual(same_membership.post, self.dulwich_post)
        self.assertEqual(same_membership.party, self.green_party)
        self.assertEqual(same_membership.id, existing_membership.id)
Ejemplo n.º 2
0
    def test_adding_to_existing_person(self):
        existing_person = factories.PersonExtraFactory.create(
            base__id='1234567', base__name='Bart Simpson').base
        existing_membership = factories.CandidacyExtraFactory.create(
            election=self.local_election,
            base__person=existing_person,
            base__post=self.local_post.base,
            base__on_behalf_of=self.labour_party_extra.base).base
        memberships_before = membership_id_set(existing_person)
        # Now try adding that person via bulk add:
        OfficialDocument.objects.create(
            election=self.election,
            post=self.dulwich_post_extra.base,
            source_url='http://example.com',
            document_type=OfficialDocument.NOMINATION_PAPER,
            uploaded_file="sopn.pdf")

        response = self.app.get('/bulk_adding/2015/65808/', user=self.user)

        form = response.forms['bulk_add_form']
        form['form-0-name'] = 'Bart Simpson'
        form['form-0-party'] = self.green_party_extra.base.id

        response = form.submit()
        self.assertEqual(response.status_code, 302)

        # This takes us to a page with a radio button for adding them
        # as a new person or alternative radio buttons if any
        # candidates with similar names were found.
        response = response.follow()
        form = response.forms[1]
        form['form-0-select_person'].select('1234567')
        response = form.submit()

        person = Person.objects.get(name='Bart Simpson')
        memberships_after = membership_id_set(person)
        new_memberships = memberships_after - memberships_before
        self.assertEqual(len(new_memberships), 1)
        new_membership = Membership.objects.get(pk=list(new_memberships)[0])
        self.assertEqual(new_membership.post, self.dulwich_post_extra.base)
        self.assertEqual(new_membership.on_behalf_of,
                         self.green_party_extra.base)
        same_memberships = memberships_before & memberships_after
        self.assertEqual(len(same_memberships), 1)
        same_membership = Membership.objects.get(pk=list(same_memberships)[0])
        self.assertEqual(same_membership.post, self.local_post.base)
        self.assertEqual(same_membership.on_behalf_of,
                         self.labour_party_extra.base)
        self.assertEqual(same_membership.id, existing_membership.id)
    def _run_wizard_to_end(self):
        existing_person = PersonFactory.create(id="1234567",
                                               name="Bart Simpson")
        existing_membership = MembershipFactory.create(
            person=existing_person,
            post=self.local_post,
            party=self.labour_party,
            post_election=self.local_election.postextraelection_set.get(
                post=self.local_post),
        )
        memberships_before = membership_id_set(existing_person)
        # Now try adding that person via bulk add:
        response = self.app.get(
            "/bulk_adding/sopn/parl.2015-05-07/65808/?edit=1", user=self.user)

        form = response.forms["bulk_add_form"]
        form["form-0-name"] = "Bart Simpson"
        form["form-0-party"] = self.green_party.ec_id

        response = form.submit()
        self.assertEqual(RawPeople.objects.count(), 1)
        self.assertEqual(RawPeople.objects.get().source_type,
                         RawPeople.SOURCE_BULK_ADD_FORM)
        self.assertEqual(response.status_code, 302)
        # This takes us to a page with a radio button for adding them
        # as a new person or alternative radio buttons if any
        # candidates with similar names were found.
        response = response.follow()
        form = response.forms[1]
        form["form-0-select_person"].select("1234567")
        response = form.submit()

        self.assertFalse(RawPeople.objects.exists())
        person = Person.objects.get(name="Bart Simpson")
        memberships_after = membership_id_set(person)
        new_memberships = memberships_after - memberships_before
        self.assertEqual(len(new_memberships), 1)
        new_membership = Membership.objects.get(pk=list(new_memberships)[0])
        self.assertEqual(new_membership.post, self.dulwich_post)
        self.assertEqual(new_membership.party, self.green_party)
        same_memberships = memberships_before & memberships_after
        self.assertEqual(len(same_memberships), 1)
        same_membership = Membership.objects.get(pk=list(same_memberships)[0])
        self.assertEqual(same_membership.post, self.local_post)
        self.assertEqual(same_membership.party, self.labour_party)
        self.assertEqual(same_membership.id, existing_membership.id)

        return response
    def test_adding_to_existing_person_same_election(self):
        # This could happen if someone's missed that there was the
        # same person already listed on the first page, but then
        # spotted them on the review page and said to merge them then.
        existing_person = factories.PersonExtraFactory.create(
            base__id='1234567',
            base__name='Bart Simpson'
        ).base
        existing_membership = factories.CandidacyExtraFactory.create(
            election=self.election,
            base__person=existing_person,
            # !!! This is the line that differs from the previous test:
            base__post=self.dulwich_post_extra.base,
            base__on_behalf_of=self.labour_party_extra.base,
            post_election=self.election.postextraelection_set.get(
                postextra=self.dulwich_post_extra
            )
        ).base
        memberships_before = membership_id_set(existing_person)
        # Now try adding that person via bulk add:
        OfficialDocument.objects.create(
            election=self.election,
            post=self.dulwich_post_extra.base,
            source_url='http://example.com',
            document_type=OfficialDocument.NOMINATION_PAPER,
            post_election=self.dulwich_post_extra_pee,
            uploaded_file="sopn.pdf"
        )

        response = self.app.get(
            '/bulk_adding/sopn/2015/65808/',
            user=self.user
        )

        form = response.forms['bulk_add_form']
        form['form-0-name'] = 'Bart Simpson'
        form['form-0-party'] = self.green_party_extra.base.id

        response = form.submit()
        self.assertEqual(response.status_code, 302)

        # This takes us to a page with a radio button for adding them
        # as a new person or alternative radio buttons if any
        # candidates with similar names were found.
        response = response.follow()
        form = response.forms[1]
        form['form-0-select_person'].select('1234567')
        response = form.submit()

        person = Person.objects.get(name='Bart Simpson')
        memberships_after = membership_id_set(person)
        new_memberships = memberships_after - memberships_before
        self.assertEqual(len(new_memberships), 0)
        same_memberships = memberships_before & memberships_after
        self.assertEqual(len(same_memberships), 1)
        same_membership = Membership.objects.get(pk=list(same_memberships)[0])
        self.assertEqual(same_membership.post, self.dulwich_post_extra.base)
        self.assertEqual(
            same_membership.on_behalf_of,
            self.green_party_extra.base
        )
        self.assertEqual(same_membership.id, existing_membership.id)