def setUp(self): super(TestFieldView, self).setUp() person_extra = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base ) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Andrew Smith', base__email='*****@*****.**', ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base )
def setUp(self): super(TestFieldView, self).setUp() person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, 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='*****@*****.**', ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base, post_election=self.dulwich_post_extra_pee)
def setUp(self): super(PhotoReviewTests, self).setUp() person_2009 = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') person_2007 = PersonExtraFactory.create(base__id='2007', base__name='Tessa Jowell') CandidacyExtraFactory.create( election=self.election, base__person=person_2009.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base) CandidacyExtraFactory.create( election=self.election, base__person=person_2007.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base) self.site = Site.objects.create(domain='example.com', name='YNR') 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)
def setUp(self): super(SuggestedLockReviewTests, self).setUp() person_2009 = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') person_2007 = PersonExtraFactory.create(base__id='2007', base__name='Tessa Jowell') CandidacyExtraFactory.create( election=self.election, base__person=person_2009.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base) CandidacyExtraFactory.create( election=self.election, base__person=person_2007.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base)
def setUp(self): wmc_area_type = AreaTypeFactory.create() self.election = ElectionFactory.create( slug='2015', name='2015 General Election', area_types=(wmc_area_type,) ) commons = ParliamentaryChamberFactory.create() self.post_extra = PostExtraFactory.create( elections=(self.election,), base__organization=commons, slug='65808', base__label='Member of Parliament for Dulwich and West Norwood' ) PartyExtraFactory.reset_sequence() PartyFactory.reset_sequence() self.parties = {} for i in xrange(0, 4): party_extra = PartyExtraFactory.create() self.parties[party_extra.slug] = party_extra person_extra = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.post_extra.base, base__on_behalf_of=self.parties['party:63'].base ) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Andrew Smith', base__email='*****@*****.**', ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.post_extra.base, base__on_behalf_of=self.parties['party:63'].base )
def setUp(self): super(TestUKResults, self).setUp() # Create a PostElectionResult, initially not confirmed. pee = self.local_post.postextraelection_set.get() per = PostElectionResult.objects.create( post_election=pee, confirmed=False, ) # Now create a ResultSet self.result_set = ResultSet.objects.create( post_election_result=per, num_turnout_reported=10000, num_spoilt_ballots=30, user=self.user, ip_address='127.0.0.1', source='Example ResultSet for testing', reviewed_by=self.user_who_can_record_results, ) # 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 = [ CandidacyExtraFactory.create( election=self.local_election, base__person=person_extra.base, base__post=self.local_post.base, base__on_behalf_of=party_extra.base, ).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_reported=v, is_winner=w) for c, v, w in zip(candidacies, votes, winner) ] # Now make that the confirmed ResultSet for that # PostElectionResult. per.confirmed = True per.confirmed_resultset = self.result_set per.save()
def setUp(self): wmc_area_type = AreaTypeFactory.create() self.election = ElectionFactory.create(slug='2015', name='2015 General Election', area_types=(wmc_area_type, )) commons = ParliamentaryChamberFactory.create() self.post_extra = PostExtraFactory.create( elections=(self.election, ), base__organization=commons, slug='65808', base__label='Member of Parliament for Dulwich and West Norwood') PartyExtraFactory.reset_sequence() PartyFactory.reset_sequence() self.parties = {} for i in range(0, 4): party_extra = PartyExtraFactory.create() self.parties[party_extra.slug] = party_extra person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.post_extra.base, base__on_behalf_of=self.parties['party:63'].base) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Andrew Smith', base__email='*****@*****.**', ) CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.post_extra.base, base__on_behalf_of=self.parties['party:63'].base)
def setUp(self): super(PhotoReviewTests, self).setUp() person_2009 = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) person_2007 = PersonExtraFactory.create( base__id='2007', base__name='Tessa Jowell' ) CandidacyExtraFactory.create( election=self.election, base__person=person_2009.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base ) CandidacyExtraFactory.create( election=self.election, base__person=person_2007.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.labour_party_extra.base ) self.site = Site.objects.create(domain='example.com', name='YNR') 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 )
def setUp(self): super(AlertsTest, self).setUp() person_extra = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) self.person = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base ) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Angela Smith' ) self.person2 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base ) content_type = ContentType.objects.get_for_model(person_extra.base) last_sent = datetime.now(pytz.utc) - timedelta(days=2) self.alert = Alert.objects.create( user=self.user, target_content_type=content_type, target_object_id=self.person.id, last_sent=last_sent, frequency='hourly' ) self.alert2 = Alert.objects.create( user=self.user_who_can_lock, target_content_type=content_type, target_object_id=self.person2.id, last_sent=last_sent, frequency='daily' ) person_extra = PersonExtraFactory.create( base__id='2011', base__name='Martin Jones' ) self.person2 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.camberwell_post_extra.base, base__on_behalf_of=self.green_party_extra.base ) content_type = ContentType.objects.get_for_model( self.camberwell_post_extra.base.area ) self.alert3 = Alert.objects.create( user=self.user_who_can_merge, target_content_type=content_type, target_object_id=self.camberwell_post_extra.base.area.id, last_sent=last_sent, frequency='daily' ) aldershot_area_extra = AreaExtraFactory.create( base__identifier='65730', type=self.wmc_area_type, ) aldershot_post = PostExtraFactory.create( elections=(self.election,), base__area=aldershot_area_extra.base, base__organization=self.commons, slug='65730', base__label='Member of Parliament for Aldershot', party_set=self.gb_parties, ) person_extra = PersonExtraFactory.create( base__id='2012', base__name='Gillian Collins' ) self.person3 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=aldershot_post.base, base__on_behalf_of=self.green_party_extra.base ) content_type = ContentType.objects.get_for_model( self.ld_party_extra.base ) self.alert4 = Alert.objects.create( user=self.user_who_can_rename, target_content_type=content_type, target_object_id=self.ld_party_extra.base.id, last_sent=last_sent, frequency='daily' ) content_type = ContentType.objects.get_for_model( self.camberwell_post_extra.base.area ) self.alert5 = Alert.objects.create( user=self.user, target_content_type=content_type, target_object_id=66101, last_sent=last_sent, frequency='hourly' )
def setUp(self): wmc_area_type = AreaTypeFactory.create() gb_parties = PartySetFactory.create(slug='gb', name='Great Britain') commons = ParliamentaryChamberFactory.create() area = AreaFactory.create(name="Dulwich and West Norwood", ) election = ElectionFactory.create(slug='2015', name='2015 General Election', area_types=(wmc_area_type, ), organization=commons) post_extra = PostExtraFactory.create( elections=(election, ), base__organization=commons, base__id='65808', base__label='Member of Parliament for Dulwich and West Norwood', party_set=gb_parties, base__area=area, ) person_2009 = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') person_2007 = PersonExtraFactory.create(base__id='2007', base__name='Tessa Jowell') PartyFactory.reset_sequence() party_extra = PartyExtraFactory.create() CandidacyExtraFactory.create(election=election, base__person=person_2009.base, base__post=post_extra.base, base__on_behalf_of=party_extra.base) CandidacyExtraFactory.create(election=election, base__person=person_2007.base, base__post=post_extra.base, base__on_behalf_of=party_extra.base) self.site = Site.objects.create(domain='example.com', name='YNR') 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)
def setUp(self): super(AlertsTest, self).setUp() person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') self.person = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base) person_extra = PersonExtraFactory.create(base__id='2010', base__name='Angela Smith') self.person2 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.dulwich_post_extra.base, base__on_behalf_of=self.green_party_extra.base) content_type = ContentType.objects.get_for_model(person_extra.base) last_sent = datetime.now(pytz.utc) - timedelta(days=2) self.alert = Alert.objects.create(user=self.user, target_content_type=content_type, target_object_id=self.person.id, last_sent=last_sent, frequency='hourly') self.alert2 = Alert.objects.create(user=self.user_who_can_lock, target_content_type=content_type, target_object_id=self.person2.id, last_sent=last_sent, frequency='daily') person_extra = PersonExtraFactory.create(base__id='2011', base__name='Martin Jones') self.person2 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=self.camberwell_post_extra.base, base__on_behalf_of=self.green_party_extra.base) content_type = ContentType.objects.get_for_model( self.camberwell_post_extra.base.area) self.alert3 = Alert.objects.create( user=self.user_who_can_merge, target_content_type=content_type, target_object_id=self.camberwell_post_extra.base.area.id, last_sent=last_sent, frequency='daily') aldershot_area_extra = AreaExtraFactory.create( base__identifier='65730', type=self.wmc_area_type, ) aldershot_post = PostExtraFactory.create( elections=(self.election, ), base__area=aldershot_area_extra.base, base__organization=self.commons, slug='65730', base__label='Member of Parliament for Aldershot', party_set=self.gb_parties, ) person_extra = PersonExtraFactory.create(base__id='2012', base__name='Gillian Collins') self.person3 = person_extra.base CandidacyExtraFactory.create( election=self.election, base__person=person_extra.base, base__post=aldershot_post.base, base__on_behalf_of=self.green_party_extra.base) content_type = ContentType.objects.get_for_model( self.ld_party_extra.base) self.alert4 = Alert.objects.create( user=self.user_who_can_rename, target_content_type=content_type, target_object_id=self.ld_party_extra.base.id, last_sent=last_sent, frequency='daily') content_type = ContentType.objects.get_for_model( self.camberwell_post_extra.base.area) self.alert5 = Alert.objects.create(user=self.user, target_content_type=content_type, target_object_id=66101, last_sent=last_sent, frequency='hourly')
def test_results_for_candidates_for_postcode(self, mock_requests): self._setup_data() person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') CandidacyExtraFactory.create( election=self.election_gla, base__person=person_extra.base, base__post=self.post_extra.base, 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 = [{ u'candidates': [], u'election_date': text_type(self.future_date.isoformat()), u'election_id': u'gla.c.2016-05-05', u'election_name': u'2016 London Assembly Election (Constituencies)', u'organization': u'London Assembly', u'post': { u'post_candidates': None, u'post_name': u'Assembly Member for Lambeth and Southwark', u'post_slug': u'lambeth-and-southwark' } }, { u'candidates': [{ u'birth_date': u'', u'contact_details': [], u'death_date': u'', u'email': None, u'extra_fields': [], u'gender': u'', u'honorific_prefix': u'', u'honorific_suffix': u'', u'id': 2009, u'identifiers': [], u'images': [], u'links': [], u'memberships': [{ u'elected': None, u'election': { u'id': u'gla.a.2016-05-05', u'name': u'2016 London Assembly Election (Additional)', u'url': u'http://localhost:80/api/v0.9/elections/gla.a.2016-05-05/' }, u'end_date': None, u'id': membership_pk, u'label': u'', u'on_behalf_of': { u'id': u'party:53', u'name': u'Labour Party', u'url': u'http://localhost:80/api/v0.9/organizations/party:53/' }, u'organization': None, u'party_list_position': None, u'person': { u'id': 2009, u'name': u'Tessa Jowell', u'url': u'http://localhost:80/api/v0.9/persons/2009/' }, u'post': { u'id': u'london', u'label': u'Assembly Member', u'slug': u'london', u'url': u'http://localhost:80/api/v0.9/posts/london/' }, u'role': u'Candidate', u'start_date': None, u'url': u'http://localhost:80/api/v0.9/memberships/{}/'.format( membership_pk) }], u'name': u'Tessa Jowell', u'other_names': [], u'sort_name': u'', u'thumbnail': None, u'url': u'http://localhost:80/api/v0.9/persons/2009/', }], u'election_date': text_type(self.future_date.isoformat()), u'election_id': u'gla.a.2016-05-05', u'election_name': u'2016 London Assembly Election (Additional)', u'organization': u'London Assembly', u'post': { u'post_candidates': None, u'post_name': u'Assembly Member', u'post_slug': u'london' } }] self.assertEqual(expected, output)
def setUp(self): super(TestUKResults, self).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 = [ CandidacyExtraFactory.create( election=self.local_election, post_election=pee, base__person=person_extra.base, base__post=self.local_post.base, base__on_behalf_of=party_extra.base, ).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 setUp(self): wmc_area_type = AreaTypeFactory.create() gb_parties = PartySetFactory.create(slug='gb', name='Great Britain') commons = ParliamentaryChamberFactory.create() area = AreaFactory.create( name="Dulwich and West Norwood", ) election = ElectionFactory.create( slug='2015', name='2015 General Election', area_types=(wmc_area_type,), organization=commons ) post_extra = PostExtraFactory.create( elections=(election,), base__organization=commons, base__id='65808', base__label='Member of Parliament for Dulwich and West Norwood', party_set=gb_parties, base__area=area, ) person_2009 = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) person_2007 = PersonExtraFactory.create( base__id='2007', base__name='Tessa Jowell' ) PartyFactory.reset_sequence() party_extra = PartyExtraFactory.create() CandidacyExtraFactory.create( election=election, base__person=person_2009.base, base__post=post_extra.base, base__on_behalf_of=party_extra.base ) CandidacyExtraFactory.create( election=election, base__person=person_2007.base, base__post=post_extra.base, base__on_behalf_of=party_extra.base ) self.site = Site.objects.create(domain='example.com', name='YNR') 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='pilot.jpg', 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='pilot.jpg', 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='pilot.jpg', person=person_2007.base, user=self.test_reviewer )
def setUp(self): wmc_area_type = AreaTypeFactory.create() gb_parties = PartySetFactory.create(slug='gb', name='Great Britain') election = ElectionFactory.create(slug='2015', name='2015 General Election', area_types=(wmc_area_type, )) area_extra = AreaExtraFactory.create( base__name="Dulwich and West Norwood", type=wmc_area_type, ) commons = ParliamentaryChamberFactory.create() post_extra = PostExtraFactory.create( elections=(election, ), base__area=area_extra.base, base__organization=commons, slug='65808', party_set=gb_parties, base__label='Member of Parliament for Dulwich and West Norwood') camberwell_area_extra = AreaExtraFactory.create( base__identifier='65913', type=wmc_area_type, ) camberwell_post = PostExtraFactory.create( elections=(election, ), base__area=camberwell_area_extra.base, base__organization=commons, slug='65913', candidates_locked=True, base__label='Member of Parliament for Camberwell and Peckham', party_set=gb_parties, ) person_extra = PersonExtraFactory.create(base__id='2009', base__name='Tessa Jowell') self.person = person_extra.base PartyExtraFactory.reset_sequence() PartyFactory.reset_sequence() self.parties = {} for i in range(0, 4): party_extra = PartyExtraFactory.create() gb_parties.parties.add(party_extra.base) self.parties[party_extra.slug] = party_extra CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=post_extra.base, base__on_behalf_of=self.parties['party:63'].base) person_extra = PersonExtraFactory.create(base__id='2010', base__name='Angela Smith') self.person2 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=post_extra.base, base__on_behalf_of=self.parties['party:63'].base) content_type = ContentType.objects.get_for_model(person_extra.base) last_sent = datetime.now(pytz.utc) - timedelta(days=2) self.alert = Alert.objects.create(user=self.user, target_content_type=content_type, target_object_id=self.person.id, last_sent=last_sent, frequency='hourly') self.alert2 = Alert.objects.create(user=self.user_who_can_lock, target_content_type=content_type, target_object_id=self.person2.id, last_sent=last_sent, frequency='daily') person_extra = PersonExtraFactory.create(base__id='2011', base__name='Martin Jones') self.person2 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=camberwell_post.base, base__on_behalf_of=self.parties['party:63'].base) content_type = ContentType.objects.get_for_model( camberwell_area_extra.base) self.alert3 = Alert.objects.create( user=self.user_who_can_merge, target_content_type=content_type, target_object_id=camberwell_area_extra.base.id, last_sent=last_sent, frequency='daily') aldershot_area_extra = AreaExtraFactory.create( base__identifier='65730', type=wmc_area_type, ) aldershot_post = PostExtraFactory.create( elections=(election, ), base__area=aldershot_area_extra.base, base__organization=commons, slug='65730', base__label='Member of Parliament for Aldershot', party_set=gb_parties, ) person_extra = PersonExtraFactory.create(base__id='2012', base__name='Gillian Collins') self.person3 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=aldershot_post.base, base__on_behalf_of=self.parties['party:63'].base) content_type = ContentType.objects.get_for_model( self.parties['party:90'].base) self.alert4 = Alert.objects.create( user=self.user_who_can_rename, target_content_type=content_type, target_object_id=self.parties['party:90'].base.id, last_sent=last_sent, frequency='daily') content_type = ContentType.objects.get_for_model( camberwell_area_extra.base) self.alert5 = Alert.objects.create(user=self.user, target_content_type=content_type, target_object_id=66101, last_sent=last_sent, frequency='hourly')
def setUp(self): wmc_area_type = AreaTypeFactory.create() gb_parties = PartySetFactory.create(slug='gb', name='Great Britain') election = ElectionFactory.create( slug='2015', name='2015 General Election', area_types=(wmc_area_type,) ) area_extra = AreaExtraFactory.create( base__name="Dulwich and West Norwood", type=wmc_area_type, ) commons = ParliamentaryChamberFactory.create() post_extra = PostExtraFactory.create( elections=(election,), base__area=area_extra.base, base__organization=commons, slug='65808', party_set=gb_parties, base__label='Member of Parliament for Dulwich and West Norwood' ) camberwell_area_extra = AreaExtraFactory.create( base__identifier='65913', type=wmc_area_type, ) camberwell_post = PostExtraFactory.create( elections=(election,), base__area=camberwell_area_extra.base, base__organization=commons, slug='65913', candidates_locked=True, base__label='Member of Parliament for Camberwell and Peckham', party_set=gb_parties, ) person_extra = PersonExtraFactory.create( base__id='2009', base__name='Tessa Jowell' ) self.person = person_extra.base PartyExtraFactory.reset_sequence() PartyFactory.reset_sequence() self.parties = {} for i in range(0, 4): party_extra = PartyExtraFactory.create() gb_parties.parties.add(party_extra.base) self.parties[party_extra.slug] = party_extra CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=post_extra.base, base__on_behalf_of=self.parties['party:63'].base ) person_extra = PersonExtraFactory.create( base__id='2010', base__name='Angela Smith' ) self.person2 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=post_extra.base, base__on_behalf_of=self.parties['party:63'].base ) content_type = ContentType.objects.get_for_model(person_extra.base) last_sent = datetime.now(pytz.utc) - timedelta(days=2) self.alert = Alert.objects.create( user=self.user, target_content_type=content_type, target_object_id=self.person.id, last_sent=last_sent, frequency='hourly' ) self.alert2 = Alert.objects.create( user=self.user_who_can_lock, target_content_type=content_type, target_object_id=self.person2.id, last_sent=last_sent, frequency='daily' ) person_extra = PersonExtraFactory.create( base__id='2011', base__name='Martin Jones' ) self.person2 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=camberwell_post.base, base__on_behalf_of=self.parties['party:63'].base ) content_type = ContentType.objects.get_for_model( camberwell_area_extra.base ) self.alert3 = Alert.objects.create( user=self.user_who_can_merge, target_content_type=content_type, target_object_id=camberwell_area_extra.base.id, last_sent=last_sent, frequency='daily' ) aldershot_area_extra = AreaExtraFactory.create( base__identifier='65730', type=wmc_area_type, ) aldershot_post = PostExtraFactory.create( elections=(election,), base__area=aldershot_area_extra.base, base__organization=commons, slug='65730', base__label='Member of Parliament for Aldershot', party_set=gb_parties, ) person_extra = PersonExtraFactory.create( base__id='2012', base__name='Gillian Collins' ) self.person3 = person_extra.base CandidacyExtraFactory.create( election=election, base__person=person_extra.base, base__post=aldershot_post.base, base__on_behalf_of=self.parties['party:63'].base ) content_type = ContentType.objects.get_for_model( self.parties['party:90'].base ) self.alert4 = Alert.objects.create( user=self.user_who_can_rename, target_content_type=content_type, target_object_id=self.parties['party:90'].base.id, last_sent=last_sent, frequency='daily' ) content_type = ContentType.objects.get_for_model( camberwell_area_extra.base ) self.alert5 = Alert.objects.create( user=self.user, target_content_type=content_type, target_object_id=66101, last_sent=last_sent, frequency='hourly' )