def setUp(self): super().setUp() update_lock(self.camberwell_post, self.election, True) post_locked = self.camberwell_post self.post_id = self.dulwich_post.id person = PersonFactory.create(id=4170, name="Naomi Newstead") MembershipFactory.create( person=person, post=post_locked, party=self.green_party, post_election=post_locked.postextraelection_set.get( election=self.election ), ) person = PersonFactory.create(id=4322, name="Helen Hayes") MembershipFactory.create( person=person, post=self.dulwich_post, party=self.green_party, post_election=self.dulwich_post.postextraelection_set.get( election=self.election ), )
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, ballot=self.dulwich_post_ballot, ) MembershipFactory.create( person=person_2007, post=self.dulwich_post, party=self.labour_party, ballot=self.dulwich_post_ballot, ) 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() group, _ = Group.objects.get_or_create(name=PHOTO_REVIEWERS_GROUP_NAME) self.test_reviewer.groups.add(group) 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): super().setUp() self.person = PersonFactory.create(id=2009, name="Tessa Jowell") MembershipFactory.create( person=self.person, post=self.dulwich_post, party=self.labour_party, ballot=self.dulwich_post_ballot, )
def setUp(self): super().setUp() person = PersonFactory.create(id=2009, name="Tessa Jowell") dulwich_not_stand = PersonFactory.create(id=4322, name="Helen Hayes") MembershipFactory.create( person=person, post=self.dulwich_post, party=self.labour_party, post_election=self.dulwich_post_pee, ) winner_post = self.edinburgh_east_post 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=dulwich_not_stand, post=self.dulwich_post, party=self.labour_party, post_election=self.dulwich_post_pee_earlier, ) dulwich_not_stand.not_standing.add(self.election) MembershipFactory.create( person=edinburgh_winner, post=winner_post, party=self.labour_party, elected=True, post_election=self.election.postextraelection_set.get( post=winner_post ), ) MembershipFactory.create( person=edinburgh_candidate, post=winner_post, party=self.labour_party, post_election=self.dulwich_post_pee, ) MembershipFactory.create( person=edinburgh_may_stand, post=winner_post, party=self.labour_party, post_election=self.earlier_election.postextraelection_set.get( post=winner_post ), )
def test_party_select_non_current_party(self): self.person = PersonFactory.create(id=2009, name="Tessa Jowell") MembershipFactory.create( person=self.person, post=self.dulwich_post, party=self.labour_party, post_election=self.dulwich_post_pee, ) form = self.app.get( "/bulk_adding/party/parl.2015-05-07/", user=self.user_who_can_upload_documents, ).forms[1] form["party_GB"].force_value("PP63") response = form.submit() self.assertEqual(response.status_code, 302)
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())
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, )
def test_delete_elections_with_related_membership(self, mock_requests): # import some data mock_requests.get.side_effect = create_mock_with_fixtures({ urljoin(EE_BASE_URL, "/api/elections/?current=True"): local_highland, urljoin(EE_BASE_URL, "/api/elections/?current=1&deleted=1"): no_results, }) call_command("uk_create_elections_from_every_election") self.assertEqual( every_election.PostExtraElection.objects.all().count(), 1) self.assertEqual(every_election.YNRElection.objects.all().count(), 1) # create a membership which references the PEE we just imported MembershipFactory( person=PersonFactory.create(id=2009, name="Tessa Jowell"), post_election=every_election.PostExtraElection.objects.all()[0], ) # now we've switched the fixtures round # so the records we just imported are deleted in EE mock_requests.get.side_effect = create_mock_with_fixtures({ urljoin(EE_BASE_URL, "/api/elections/?current=True"): no_results, urljoin(EE_BASE_URL, "/api/elections/?current=1&deleted=1"): local_highland, }) # make sure we throw an exception with self.assertRaises(Exception): call_command("uk_create_elections_from_every_election") # we should also roll back the whole transaction so nothing is deleted self.assertEqual( every_election.PostExtraElection.objects.all().count(), 1) self.assertEqual(every_election.YNRElection.objects.all().count(), 1)
def setUp(self): super().setUp() person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') MembershipFactory.create(person=person_extra.base, post=self.dulwich_post_extra.base, on_behalf_of=self.green_party_extra.base, post_election=self.dulwich_post_extra_pee) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Andrew Smith', base__email='*****@*****.**', ) MembershipFactory.create(person=person_extra.base, post=self.dulwich_post_extra.base, on_behalf_of=self.green_party_extra.base, post_election=self.dulwich_post_extra_pee)
def setUp(self): super().setUp() person = PersonFactory.create(id=2009, name="Tessa Jowell") MembershipFactory.create( person=person, post=self.dulwich_post, party=self.green_party, post_election=self.dulwich_post_pee, ) person = PersonFactory.create(id="2010", name="Andrew Smith", email="*****@*****.**") MembershipFactory.create( person=person, post=self.dulwich_post, party=self.green_party, post_election=self.dulwich_post_pee, )
def setUp(self): super().setUp() person_2009 = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) person_2007 = PersonExtraFactory.create( base__id='2007', base__name='Tessa Jowell' ) MembershipFactory.create( person=person_2009.base, post=self.dulwich_post_extra.base, on_behalf_of=self.labour_party_extra.base, post_election=self.dulwich_post_extra_pee, ) MembershipFactory.create( person=person_2007.base, post=self.dulwich_post_extra.base, on_behalf_of=self.labour_party_extra.base, post_election=self.dulwich_post_extra_pee, )
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 = PersonFactory.create(id="1234567", name="Bart Simpson") existing_membership = 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( 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/parl.2015-05-07/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)
def test_remove_other_ballots_in_election(self): """ If someone is adding this person to a ballot, we remove that person from other ballots in that election """ existing_person = PersonFactory.create(id="1234567", name="Bart Simpson") existing_membership = 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), ) OfficialDocument.objects.create( source_url="http://example.com", document_type=OfficialDocument.NOMINATION_PAPER, post_election=self.camberwell_post_pee, uploaded_file="sopn.pdf", ) response = self.app.get( "/bulk_adding/sopn/parl.2015-05-07/{}/".format( self.camberwell_post.slug), 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() response = response.follow() form = response.forms[1] form["form-0-select_person"].select("1234567") response = form.submit() self.assertEqual(response.context["formset"].is_valid(), False) self.assertEqual( response.context["formset"].non_form_errors(), [ "'Bart Simpson' is marked as standing in another ballot for " "this election. Check you're entering the correct information " "for Member of Parliament for Camberwell and Peckham" ], ) self.assertContains(response, "is marked as standing in another ballot for")
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_valid_with_memberships_and_no_raw_people(self): existing_person = PersonFactory.create(id="1234567", name="Bart Simpson") existing_membership = MembershipFactory.create( person=existing_person, # !!! This is the line that differs from the previous test: post=self.dulwich_post, party=self.labour_party, ballot=self.election.ballot_set.get(post=self.dulwich_post), ) OfficialDocument.objects.create( source_url="http://example.com", document_type=OfficialDocument.NOMINATION_PAPER, ballot=self.dulwich_post_ballot, uploaded_file="sopn.pdf", ) response = self.app.get( "/bulk_adding/sopn/parl.65808.2015-05-07/?edit=1", user=self.user) form = response.forms[1] response = form.submit() self.assertEqual(response.status_code, 302)
def setUp(self): super().setUp() constituencies = {} for slug, cons_name, country in [ ("66090", "Cardiff Central", "Wales"), ("65672", "Doncaster North", "England"), ("65719", "South Shields", "England"), ]: constituencies[cons_name] = PostFactory.create( elections=(self.election, self.earlier_election), organization=self.commons, slug=slug, label="Member of Parliament for {}".format(cons_name), group=country, ) person = PersonFactory.create(id=3056, name="Ed Miliband") MembershipFactory.create( person=person, post=constituencies["Doncaster North"], party=self.labour_party, ballot=self.election.ballot_set.get( post=constituencies["Doncaster North"] ), ) person = PersonFactory.create(id=3814, name="David Miliband") MembershipFactory.create( person=person, post=constituencies["South Shields"], party=self.labour_party, ballot=self.earlier_election.ballot_set.get( post=constituencies["South Shields"] ), ) conservative_opponent = PersonFactory.create( id="6648", name="Mark Fletcher" ) MembershipFactory.create( person=conservative_opponent, post=constituencies["South Shields"], party=self.conservative_party, ballot=self.election.ballot_set.get( post=constituencies["South Shields"] ), )
def test_results_for_candidates_for_postcode(self, mock_requests): self._setup_data() person_extra = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) MembershipFactory.create( person=person_extra.base, post=self.post_extra.base, on_behalf_of=self.labour_party_extra.base, post_election=self.election_gla.postextraelection_set.get( postextra=self.post_extra ) ) membership_pk = person_extra.base.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': [], '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://localhost:80/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', 'url': 'http://localhost:80/api/v0.9/organizations/party:53/' }, 'organization': None, 'party_list_position': None, 'person': { 'id': 2009, 'name': 'Tessa Jowell', 'url': 'http://localhost:80/api/v0.9/persons/2009/' }, 'post': { 'id': 'london', 'label': 'Assembly Member', 'slug': 'london', 'url': 'http://localhost:80/api/v0.9/posts/london/' }, 'role': 'Candidate', 'start_date': None, 'url': 'http://localhost:80/api/v0.9/memberships/{}/'.format(membership_pk) }], 'name': 'Tessa Jowell', 'other_names': [], 'sort_name': '', 'thumbnail': None, 'url': 'http://localhost:80/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() 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_extra = [ PersonExtraFactory.create(base__id='13', base__name='Alice'), PersonExtraFactory.create(base__id='14', base__name='Bob'), PersonExtraFactory.create(base__id='15', base__name='Carol'), ] parties_extra = [ self.labour_party_extra, self.conservative_party_extra, self.ld_party_extra ] # Create their candidacies: candidacies = [ MembershipFactory.create( post_election=pee, person=person_extra.base, post=self.local_post.base, on_behalf_of=party_extra.base, ) for person_extra, party_extra in zip(self.persons_extra, parties_extra) ] # 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': '******' }
def create_memberships(self, ballot, parties): for i in range(3): for party in parties: person = PersonFactory() MembershipFactory(ballot=ballot, person=person, party=party)
def test_results_for_candidates_for_postcode(self, mock_requests): one_day = timedelta(days=1) self.future_date = date.today() + one_day london_assembly = ParliamentaryChamberFactory.create( slug="london-assembly", name="London Assembly" ) election_lac = ElectionFactory.create( slug="gla.c.2016-05-05", organization=london_assembly, name="2016 London Assembly Election (Constituencies)", election_date=self.future_date.isoformat(), ) self.election_gla = ElectionFactory.create( slug="gla.a.2016-05-05", organization=london_assembly, name="2016 London Assembly Election (Additional)", election_date=self.future_date.isoformat(), ) PostFactory.create( elections=(election_lac,), organization=london_assembly, slug="lambeth-and-southwark", label="Assembly Member for Lambeth and Southwark", ) self.post = PostFactory.create( elections=(self.election_gla,), organization=london_assembly, slug="london", label="Assembly Member", ) self.person.memberships.all().delete() MembershipFactory.create( person=self.person, post=self.post, party=self.labour_party, post_election=self.election_gla.postextraelection_set.get( post=self.post ), ) membership_pk = self.person.memberships.first().pk self.maxDiff = None mock_requests.get.side_effect = fake_requests_for_every_election response = self.app.get( "/api/next/candidates_for_postcode/?postcode=SE24+0AG" ) output = response.json self.assertEqual(len(output), 2) expected = [ { "candidates": [], "election_date": 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": "", "death_date": "", "email": None, "gender": "", "honorific_prefix": "", "honorific_suffix": "", "id": 2009, "images": [ { "copyright": "example-license", "id": self.person_image.pk, "image_url": "/media/images/images/imported.jpg", "is_primary": True, "md5sum": "md5sum", "notes": "", "source": "Found on the candidate's Flickr feed", "uploading_user": "******", "user_copyright": "", "user_notes": "Here's an image...", } ], "memberships": [ { "elected": None, "election": { "id": "gla.a.2016-05-05", "name": "2016 London Assembly Election (Additional)", "url": "http://testserver/api/next/elections/gla.a.2016-05-05/", }, "end_date": None, "id": membership_pk, "label": "", "party": { "ec_id": "PP53", "legacy_slug": "party:53", "name": "Labour Party", }, "party_list_position": None, "person": { "id": 2009, "name": "Tessa Jowell", "url": "http://testserver/api/next/persons/2009/", }, "post": { "id": "london", "label": "Assembly Member", "slug": "london", "url": "http://testserver/api/next/posts/london/", }, "role": "Candidate", "start_date": None, "url": "http://testserver/api/next/memberships/{}/".format( membership_pk ), } ], "name": "Tessa Jowell", "other_names": [], "sort_name": "", "thumbnail": "http://testserver/media/cache/69/5d/695d95b49b6a6ab3aebe728d2ec5162b.jpg", "url": "http://testserver/api/next/persons/2009/", } ], "election_date": 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() 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": "******", }
def setUp(self): super().setUp() person_2009 = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) person_2007 = PersonExtraFactory.create( base__id='2007', base__name='Tessa Jowell' ) MembershipFactory.create( person=person_2009.base, post=self.dulwich_post_extra.base, on_behalf_of=self.labour_party_extra.base, post_election=self.dulwich_post_extra_pee, ) MembershipFactory.create( person=person_2007.base, post=self.dulwich_post_extra.base, on_behalf_of=self.labour_party_extra.base, post_election=self.dulwich_post_extra_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.base, 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.base, 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.base, 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.base, user=None )
def setUp(self): super().setUp() self.storage = DefaultStorage() self.person = PersonFactory.create(id=2009, name="Tessa Jowell") self.person_image = PersonImage.objects.update_or_create_from_file( EXAMPLE_IMAGE_FILENAME, "images/imported.jpg", self.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=self.person, post=self.dulwich_post, party=self.labour_party, post_election=self.dulwich_post_pee, ) MembershipFactory.create( person=self.person, post_election=self.edinburgh_east_post_pee ) MembershipFactory.create( person=dulwich_not_stand, post=self.dulwich_post, party=self.labour_party, post_election=self.dulwich_post_pee_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, post_election=self.edinburgh_east_post_pee, ) MembershipFactory.create( person=edinburgh_candidate, post=self.edinburgh_east_post, party=self.labour_party, post_election=self.edinburgh_east_post_pee, ) MembershipFactory.create( person=edinburgh_may_stand, post=self.edinburgh_east_post, party=self.labour_party, post_election=self.edinburgh_east_post_pee_earlier, ) PartyEmblemFactory(party=self.labour_party) PartyDescriptionFactory( party=self.labour_party, description="Labour Party Candidate", pk=1 )
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)