예제 #1
0
    def setUp(self):
        super().setUp()

        person = PersonFactory.create(id=2009, name="Tessa Jowell")
        PersonImage.objects.update_or_create_from_file(
            EXAMPLE_IMAGE_FILENAME,
            "images/imported.jpg",
            person,
            defaults={
                "md5sum": "md5sum",
                "copyright": "example-license",
                "uploading_user": self.user,
                "user_notes": "Here's an image...",
                "is_primary": True,
                "source": "Found on the candidate's Flickr feed",
            },
        )
        dulwich_not_stand = PersonFactory.create(id=4322, name="Helen Hayes")
        edinburgh_candidate = PersonFactory.create(id="818",
                                                   name="Sheila Gilmore")
        edinburgh_winner = PersonFactory.create(id="5795",
                                                name="Tommy Sheppard")
        edinburgh_may_stand = PersonFactory.create(id="5163",
                                                   name="Peter McColl")
        MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot,
        )
        MembershipFactory.create(person=person,
                                 ballot=self.edinburgh_east_post_ballot)

        MembershipFactory.create(
            person=dulwich_not_stand,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot_earlier,
        )
        dulwich_not_stand.not_standing.add(self.election)

        MembershipFactory.create(
            person=edinburgh_winner,
            post=self.edinburgh_east_post,
            party=self.labour_party,
            elected=True,
            ballot=self.edinburgh_east_post_ballot,
        )

        MembershipFactory.create(
            person=edinburgh_candidate,
            post=self.edinburgh_east_post,
            party=self.labour_party,
            ballot=self.edinburgh_east_post_ballot,
        )

        MembershipFactory.create(
            person=edinburgh_may_stand,
            post=self.edinburgh_east_post,
            party=self.labour_party,
            ballot=self.edinburgh_east_post_ballot_earlier,
        )

        self.storage = DefaultStorage()
예제 #2
0
    def setUp(self):
        self.image_filename = EXAMPLE_IMAGE_FILENAME
        with open(self.image_filename, "rb") as f:
            self.example_image_binary_data = f.read()

        self.p_no_images = PersonFactory.create(
            id="1", name="Person With No Existing Images")
        self.p_no_images.tmp_person_identifiers.create(
            internal_identifier="1001", value_type="twitter_username")

        p_existing_image = PersonFactory.create(
            id=2, name="Person With An Existing Image")
        self.existing_undecided_image = p_existing_image.queuedimage_set.create(
            decision=QueuedImage.UNDECIDED, user=self.user)
        p_existing_image.tmp_person_identifiers.create(
            internal_identifier="1002", value_type="twitter_username")

        self.p_only_rejected_in_queue = PersonFactory.create(
            id=3, name="Person With Only Rejected Images In The Queue")
        self.existing_rejected_image = self.p_only_rejected_in_queue.queuedimage_set.create(
            decision=QueuedImage.REJECTED, user=self.user)
        self.p_only_rejected_in_queue.tmp_person_identifiers.create(
            internal_identifier="1003", value_type="twitter_username")

        PersonFactory.create(id=4, name="Person With No Twitter User ID")

        self.p_accepted_image_in_queue = PersonFactory.create(
            id=5, name="Person With An Accepted Image In The Queue")
        self.existing_accepted_image = self.p_accepted_image_in_queue.queuedimage_set.create(
            decision=QueuedImage.APPROVED, user=self.user)
        self.p_accepted_image_in_queue.tmp_person_identifiers.create(
            internal_identifier="1005", value_type="twitter_username")
        # If they've had an image accepted, they'll probably have an
        # Image too, so create that:
        self.image_create_from_queue = PersonImage.objects.create_from_file(
            self.image_filename,
            "images/person-accepted.jpg",
            defaults={
                "person": self.p_accepted_image_in_queue,
                "is_primary": True,
                "source": "From Flickr, used as an example image",
                "copyright": "example-license",
                "uploading_user": self.user,
                "user_notes": "Here is a photo for you!",
            },
        )

        self.p_existing_image_but_none_in_queue = PersonFactory.create(
            id=6, name="Person With An Existing Image But None In The Queue")
        self.p_existing_image_but_none_in_queue.tmp_person_identifiers.create(
            internal_identifier="1006", value_type="twitter_username")
        self.image_create_from_queue = PersonImage.objects.create_from_file(
            self.image_filename,
            "images/person-existing-image.jpg",
            defaults={
                "person": self.p_existing_image_but_none_in_queue,
                "is_primary": True,
                "source": "From Flickr, used as an example image",
                "copyright": "example-license",
                "uploading_user": self.user,
                "user_notes": "Photo from their party page, say",
            },
        )
        self.existing_queued_image_ids = list(
            QueuedImage.objects.values_list("pk", flat=True))
    def test_results_for_candidates_for_postcode(self, mock_requests):
        self._setup_data()

        person = PersonFactory.create(id=2009, name="Tessa Jowell")

        MembershipFactory.create(
            person=person,
            post=self.post,
            party=self.labour_party,
            ballot=self.election_gla.ballot_set.get(post=self.post),
        )
        membership_pk = person.memberships.first().pk

        self.maxDiff = None

        mock_requests.get.side_effect = fake_requests_for_every_election
        response = self.app.get(
            "/api/v0.9/candidates_for_postcode/?postcode=SE24+0AG")

        output = response.json
        self.assertEqual(len(output), 2)
        expected = [
            {
                "candidates": [],
                "election_date": text_type(self.future_date.isoformat()),
                "election_id": "gla.c.2016-05-05",
                "election_name":
                "2016 London Assembly Election (Constituencies)",
                "organization": "London Assembly",
                "post": {
                    "post_candidates": None,
                    "post_name": "Assembly Member for Lambeth and Southwark",
                    "post_slug": "lambeth-and-southwark",
                },
            },
            {
                "candidates": [{
                    "birth_date":
                    "",
                    "contact_details": [],
                    "death_date":
                    "",
                    "email":
                    None,
                    "extra_fields": [{
                        "favourite_biscuits": ""
                    }],
                    "gender":
                    "",
                    "honorific_prefix":
                    "",
                    "honorific_suffix":
                    "",
                    "id":
                    2009,
                    "identifiers": [],
                    "images": [],
                    "links": [],
                    "memberships": [{
                        "elected":
                        None,
                        "election": {
                            "id":
                            "gla.a.2016-05-05",
                            "name":
                            "2016 London Assembly Election (Additional)",
                            "url":
                            "http://testserver/api/v0.9/elections/gla.a.2016-05-05/",
                        },
                        "end_date":
                        None,
                        "id":
                        membership_pk,
                        "label":
                        "",
                        "on_behalf_of": {
                            "id": "party:53",
                            "name": "Labour Party",
                        },
                        "party_list_position":
                        None,
                        "person": {
                            "id": 2009,
                            "name": "Tessa Jowell",
                            "url": "http://testserver/api/v0.9/persons/2009/",
                        },
                        "post": {
                            "id": "assembly-member",
                            "label": "Assembly Member",
                            "slug": "london",
                            "url": "http://testserver/api/v0.9/posts/london/",
                        },
                        "role":
                        "Candidate",
                        "start_date":
                        None,
                        "url":
                        "http://testserver/api/v0.9/memberships/{}/".format(
                            membership_pk),
                    }],
                    "name":
                    "Tessa Jowell",
                    "other_names": [],
                    "sort_name":
                    "",
                    "thumbnail":
                    None,
                    "url":
                    "http://testserver/api/v0.9/persons/2009/",
                }],
                "election_date":
                text_type(self.future_date.isoformat()),
                "election_id":
                "gla.a.2016-05-05",
                "election_name":
                "2016 London Assembly Election (Additional)",
                "organization":
                "London Assembly",
                "post": {
                    "post_candidates": None,
                    "post_name": "Assembly Member",
                    "post_slug": "london",
                },
            },
        ]

        self.assertEqual(expected, output)
 def setUp(self):
     super().setUp()
     User.objects.create(username=settings.CANDIDATE_BOT_USERNAME)
     self.person = PersonFactory.create(id=2009, name="Tessa Jowell")
 def setUp(self):
     super().setUp()
     self.person = PersonFactory.create(name="John Doe")
 def setUp(self):
     person = PersonFactory.create(id=4322, name="Helen Hayes")
     person.tmp_person_identifiers.create(value="*****@*****.**",
                                          value_type="email")
예제 #7
0
    def setUp(self):
        super().setUp()
        pee = self.local_post.postextraelection_set.get()
        self.result_set = ResultSet.objects.create(
            post_election=pee,
            num_turnout_reported=10000,
            num_spoilt_ballots=30,
            user=self.user,
            ip_address="127.0.0.1",
            source="Example ResultSet for testing",
        )
        # Create three people:
        self.persons = [
            PersonFactory.create(id=13, name="Alice"),
            PersonFactory.create(id=14, name="Bob"),
            PersonFactory.create(id=15, name="Carol"),
        ]

        parties = [self.labour_party, self.conservative_party, self.ld_party]
        # Create their candidacies:
        candidacies = [
            MembershipFactory.create(
                post_election=pee,
                person=person,
                post=self.local_post,
                party=party,
            ) for person, party in zip(self.persons, parties)
        ]
        # Create their CandidateResult objects:
        votes = [2000, 5000, 3000]
        winner = [False, True, False]
        self.candidate_results = [
            CandidateResult.objects.create(
                result_set=self.result_set,
                membership=c,
                num_ballots=v,
                is_winner=w,
            ) for c, v, w in zip(candidacies, votes, winner)
        ]

        self.expected = {
            "ballot_paper_id":
            "local.maidstone.DIW:E05005004.2016-05-05",
            "created":
            self.result_set.created.isoformat(),
            "candidate_results": [
                {
                    "is_winner": True,
                    "num_ballots": 5000,
                    "person_id": 14,
                    "person_name": "Bob",
                },
                {
                    "is_winner": False,
                    "num_ballots": 3000,
                    "person_id": 15,
                    "person_name": "Carol",
                },
                {
                    "is_winner": False,
                    "num_ballots": 2000,
                    "person_id": 13,
                    "person_name": "Alice",
                },
            ],
            "source":
            "Example ResultSet for testing",
            "spoilt_ballots":
            30,
            "turnout":
            10000,
            "user":
            "******",
        }
예제 #8
0
    def setUp(self):
        super().setUp()
        person_2009 = PersonFactory.create(id=2009, name="Tessa Jowell")
        person_2007 = PersonFactory.create(id=2007, name="Tessa Jowell")
        MembershipFactory.create(
            person=person_2009,
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee,
        )
        MembershipFactory.create(
            person=person_2007,
            post=self.dulwich_post,
            party=self.labour_party,
            post_election=self.dulwich_post_pee,
        )

        self.test_upload_user = User.objects.create_user(
            "john", "*****@*****.**", "notagoodpassword"
        )
        self.test_upload_user.terms_agreement.assigned_to_dc = True
        self.test_upload_user.terms_agreement.save()
        self.test_reviewer = User.objects.create_superuser(
            "jane", "*****@*****.**", "alsonotagoodpassword"
        )
        self.test_reviewer.terms_agreement.assigned_to_dc = True
        self.test_reviewer.terms_agreement.save()
        self.test_reviewer.groups.add(
            Group.objects.get(name=PHOTO_REVIEWERS_GROUP_NAME)
        )
        self.q1 = QueuedImage.objects.create(
            why_allowed="public-domain",
            justification_for_use="It's their Twitter avatar",
            decision="undecided",
            image=self.storage_filename,
            person=person_2009,
            user=self.test_upload_user,
        )
        self.q2 = QueuedImage.objects.create(
            why_allowed="copyright-assigned",
            justification_for_use="I took this last week",
            decision="approved",
            image=self.storage_filename,
            person=person_2007,
            user=self.test_upload_user,
        )
        self.q3 = QueuedImage.objects.create(
            why_allowed="other",
            justification_for_use="I found it somewhere",
            decision="rejected",
            image=self.storage_filename,
            person=person_2007,
            user=self.test_reviewer,
        )
        self.q_no_uploading_user = QueuedImage.objects.create(
            why_allowed="profile-photo",
            justification_for_use="Auto imported from Twitter",
            decision="undecided",
            image=self.storage_filename,
            person=person_2009,
            user=None,
        )
 def setUp(self):
     PersonFactory.create(
         id=4322, name="Helen Hayes", email="*****@*****.**"
     )