def setUp(self): wmc_area_type = AreaTypeFactory.create() lac_area_type = AreaTypeFactory.create(name='LAC') gb_parties = PartySetFactory.create(slug='gb', name='Great Britain') commons = ParliamentaryChamberExtraFactory.create() lac = ParliamentaryChamberExtraFactory.create(slug='lac') election = ElectionFactory.create( slug='2015', name='2015 General Election', area_types=(wmc_area_type,), organization=commons.base ) election2 = ElectionFactory.create( slug='2015-secondary', name='2015 Secondary Election', area_types=(lac_area_type,), organization=lac.base ) area_extra = AreaExtraFactory.create( base__name="Westminster", type=wmc_area_type, ) PostExtraFactory.create( elections=(election,), base__organization=commons.base, slug='65759', base__label='Member of Parliament for Westminster', party_set=gb_parties, base__area=area_extra.base, ) area_extra = AreaExtraFactory.create( base__name="Dulwich and West Norwood", type=wmc_area_type, ) PostExtraFactory.create( elections=(election,), base__organization=commons.base, slug='65808', base__label='Member of Parliament for Dulwich and West Norwood', party_set=gb_parties, base__area=area_extra.base, ) area_extra = AreaExtraFactory.create( base__name="Lambeth and Southwark", type=lac_area_type, ) PostExtraFactory.create( elections=(election2,), base__organization=commons.base, slug='11822', base__label='London Assembly Member for Lambeth and Southwark', party_set=gb_parties, base__area=area_extra.base, )
def _setup_extra_posts(self): # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') election_lac = ElectionFactory.create( slug='gla.c.2016-05-05', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', ) election_gla = ElectionFactory.create( slug='gla.a.2016-05-05', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', ) PostExtraFactory.create( elections=(election_lac, ), base__organization=london_assembly.base, slug='lambeth-and-southwark', base__label='Assembly Member for Lambeth and Southwark', ) PostExtraFactory.create( elections=(election_gla, ), base__organization=london_assembly.base, slug='london', base__label='2016 London Assembly Election (Additional)', )
def _setup_data(self): one_day = timedelta(days=1) self.future_date = date.today() + one_day london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') election_lac = ElectionFactory.create( slug='gla.c.2016-05-05', organization=london_assembly.base, 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.base, name='2016 London Assembly Election (Additional)', election_date=self.future_date.isoformat(), ) PostExtraFactory.create( elections=(election_lac, ), base__organization=london_assembly.base, slug='lambeth-and-southwark', base__label='Assembly Member for Lambeth and Southwark', ) self.post_extra = PostExtraFactory.create( elections=(self.election_gla, ), base__organization=london_assembly.base, slug='london', base__label='Assembly Member', )
def setUp(self): org = ParliamentaryChamberExtraFactory.create() self.election = ElectionFactory.create(slug='2015', name='2015 Election', election_date=date.today(), organization=org.base)
def setUp(self): area_type = AreaTypeFactory.create() org = ParliamentaryChamberExtraFactory.create() self.election = ElectionFactory.create(slug='cr-2015', name='2015 Election', area_types=(area_type, ), organization=org.base)
def test_valid_postcode_redirects_to_multiple_areas(self, mock_requests): mock_requests.get.side_effect = fake_requests_for_every_election # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_lac = AreaExtraFactory.create( base__identifier='gss:E32000010', base__name="Dulwich and West Norwood", type=lac_area_type, ) area_extra_gla = AreaExtraFactory.create( base__identifier='unit_id:41441', base__name='Greater London Authority', type=gla_area_type, ) election_lac = ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', area_types=(lac_area_type, ), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', area_types=(gla_area_type, ), ) PostExtraFactory.create( elections=(election_lac, ), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug='11822', base__label='Assembly Member for Lambeth and Southwark', ) PostExtraFactory.create( elections=(election_gla, ), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='2247', base__label='2016 London Assembly Election (Additional)', ) # ---------------------------- response = self.app.get('/') form = response.forms['form-postcode'] form['q'] = 'SE24 0AG' response = form.submit() self.assertEqual(response.status_code, 302) split_location = urlsplit(response.location) self.assertEqual(split_location.path, '/') self.assertEqual(split_location.query, 'q=SE24%200AG') response = self.app.get(response.location) split_location = urlsplit(response.location) self.assertEqual( split_location.path, '/areas/GLA--unit_id:41441,LAC--gss:E32000010,WMC--gss:E14000673', )
def setUp(self): area_type = AreaTypeFactory.create() org = ParliamentaryChamberExtraFactory.create() self.election = ElectionFactory.create( slug='cr-2015', name='2015 Election', area_types=(area_type,), organization=org.base )
def test_valid_postcode_redirects_to_multiple_areas(self, mock_requests): mock_requests.get.side_effect = fake_requests_for_mapit # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly' ) lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_lac = AreaExtraFactory.create( base__identifier='11822', base__name="Dulwich and West Norwood", type=lac_area_type, ) area_extra_gla = AreaExtraFactory.create( base__identifier='2247', base__name='Greater London Authority', type=gla_area_type, ) election_lac = ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', area_types=(lac_area_type,), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', area_types=(gla_area_type,), ) PostExtraFactory.create( elections=(election_lac,), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug='11822', base__label='Assembly Member for Lambeth and Southwark', ) PostExtraFactory.create( elections=(election_gla,), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='2247', base__label='2016 London Assembly Election (Additional)', ) # ---------------------------- response = self.app.get('/') form = response.forms['form-postcode'] form['postcode'] = 'SE24 0AG' response = form.submit() self.assertEqual(response.status_code, 302) split_location = urlsplit(response.location) self.assertEqual( split_location.path, '/areas/LAC-11822,GLA-2247,WMC-65808', )
def test_valid_postcode_redirects_to_multiple_areas(self, mock_requests): mock_requests.get.side_effect = fake_requests_for_mapit # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create(slug="london-assembly", base__name="London Assembly") lac_area_type = AreaTypeFactory.create(name="LAC") gla_area_type = AreaTypeFactory.create(name="GLA") area_extra_lac = AreaExtraFactory.create( base__identifier="gss:E32000010", base__name="Dulwich and West Norwood", type=lac_area_type ) area_extra_gla = AreaExtraFactory.create( base__identifier="unit_id:41441", base__name="Greater London Authority", type=gla_area_type ) election_lac = ElectionFactory.create( slug="gb-gla-2016-05-05-c", organization=london_assembly.base, name="2016 London Assembly Election (Constituencies)", area_types=(lac_area_type,), ) election_gla = ElectionFactory.create( slug="gb-gla-2016-05-05-a", organization=london_assembly.base, name="2016 London Assembly Election (Additional)", area_types=(gla_area_type,), ) PostExtraFactory.create( elections=(election_lac,), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug="11822", base__label="Assembly Member for Lambeth and Southwark", ) PostExtraFactory.create( elections=(election_gla,), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug="2247", base__label="2016 London Assembly Election (Additional)", ) # ---------------------------- response = self.app.get("/") form = response.forms["form-postcode"] form["postcode"] = "SE24 0AG" response = form.submit() self.assertEqual(response.status_code, 302) split_location = urlsplit(response.location) self.assertEqual(split_location.path, "/areas/GLA-unit_id:41441,LAC-gss:E32000010,WMC-gss:E14000673")
def _setup_data(self): one_day = timedelta(days=1) self.future_date = date.today() + one_day london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_lac = AreaExtraFactory.create( base__identifier='gss:E32000010', base__name="Dulwich and West Norwood", type=lac_area_type, ) area_extra_gla = AreaExtraFactory.create( base__identifier='unit_id:41441', base__name='Greater London Authority', type=gla_area_type, ) election_lac = ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', election_date=self.future_date.isoformat(), area_types=(lac_area_type, ), ) self.election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', election_date=self.future_date.isoformat(), area_types=(gla_area_type, ), ) PostExtraFactory.create( elections=(election_lac, ), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug='gss:E32000010', base__label='Assembly Member for Lambeth and Southwark', ) self.post_extra = PostExtraFactory.create( elections=(self.election_gla, ), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='unit_id:41441', base__label='Assembly Member', )
def test_valid_postcode_redirects_to_only_real_areas(self, mock_requests): mock_requests.get.side_effect = fake_requests_for_mapit # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly' ) lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_gla = AreaExtraFactory.create( base__identifier='unit_id:41441', base__name='Greater London Authority', type=gla_area_type, ) ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', area_types=(lac_area_type,), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', area_types=(gla_area_type,), ) PostExtraFactory.create( elections=(election_gla,), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='2247', base__label='2016 London Assembly Election (Additional)', ) # ---------------------------- response = self.app.get('/') form = response.forms['form-postcode'] form['postcode'] = 'SE24 0AG' response = form.submit() self.assertEqual(response.status_code, 302) split_location = urlsplit(response.location) self.assertEqual( split_location.path, '/areas/GLA-unit_id:41441,WMC-gss:E14000673', )
def test_valid_postcode_redirects_to_only_real_areas(self, mock_requests): mock_requests.get.side_effect = fake_requests_for_mapit # Create some extra posts and areas: london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_gla = AreaExtraFactory.create( base__identifier='unit_id:41441', base__name='Greater London Authority', type=gla_area_type, ) ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', area_types=(lac_area_type, ), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', area_types=(gla_area_type, ), ) PostExtraFactory.create( elections=(election_gla, ), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='2247', base__label='2016 London Assembly Election (Additional)', ) # ---------------------------- response = self.app.get('/') form = response.forms['form-postcode'] form['postcode'] = 'SE24 0AG' response = form.submit() self.assertEqual(response.status_code, 302) split_location = urlsplit(response.location) self.assertEqual( split_location.path, '/areas/GLA-unit_id:41441,WMC-gss:E14000673', )
def setUp(self): super(TestGeolocator, self).setUp() lac_area_type = AreaTypeFactory.create(name='LAC') lac = ParliamentaryChamberExtraFactory.create(slug='lac') election2 = ElectionFactory.create( slug='2015-secondary', name='2015 Secondary Election', area_types=(lac_area_type,), organization=lac.base ) area_extra = AreaExtraFactory.create( base__name="Westminster", type=self.wmc_area_type, ) PostExtraFactory.create( elections=(self.election,), base__organization=self.commons, slug='65759', base__label='Member of Parliament for Westminster', party_set=self.gb_parties, base__area=area_extra.base, ) area_extra = AreaExtraFactory.create( base__name="Lambeth and Southwark", type=lac_area_type, ) PostExtraFactory.create( elections=(election2,), base__organization=self.commons, slug='11822', base__label='London Assembly Member for Lambeth and Southwark', party_set=self.gb_parties, base__area=area_extra.base, )
def setUp(self): super(TestGeolocator, self).setUp() lac_area_type = AreaTypeFactory.create(name='LAC') lac = ParliamentaryChamberExtraFactory.create(slug='lac') election2 = ElectionFactory.create(slug='2015-secondary', name='2015 Secondary Election', area_types=(lac_area_type, ), organization=lac.base) area_extra = AreaExtraFactory.create( base__name="Westminster", type=self.wmc_area_type, ) PostExtraFactory.create( elections=(self.election, ), base__organization=self.commons, slug='65759', base__label='Member of Parliament for Westminster', party_set=self.gb_parties, base__area=area_extra.base, ) area_extra = AreaExtraFactory.create( base__name="Lambeth and Southwark", type=lac_area_type, ) PostExtraFactory.create( elections=(election2, ), base__organization=self.commons, slug='11822', base__label='London Assembly Member for Lambeth and Southwark', party_set=self.gb_parties, base__area=area_extra.base, )
def test_results_for_upcoming_elections(self, mock_requests): one_day = timedelta(days=1) future_date = date.today() + one_day london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly' ) lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_lac = AreaExtraFactory.create( base__identifier='gss:E32000010', base__name="Dulwich and West Norwood", type=lac_area_type, ) area_extra_gla = AreaExtraFactory.create( base__identifier='unit_id:41441', base__name='Greater London Authority', type=gla_area_type, ) election_lac = ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', election_date=future_date.isoformat(), area_types=(lac_area_type,), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', election_date=future_date.isoformat(), area_types=(gla_area_type,), ) PostExtraFactory.create( elections=(election_lac,), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug='gss:E32000010', base__label='Assembly Member for Lambeth and Southwark', ) PostExtraFactory.create( elections=(election_gla,), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='unit_id:41441', base__label='Assembly Member', ) mock_requests.get.side_effect = fake_requests_for_mapit response = self.app.get('/upcoming-elections/?postcode=SE24+0AG') output = response.json self.assertEqual(len(output), 2) self.maxDiff = None expected = [ { 'organization': 'London Assembly', 'election_date': text_type(future_date.isoformat()), 'election_name': '2016 London Assembly Election (Constituencies)', 'post_name': 'Assembly Member for Lambeth and Southwark', 'area': { 'identifier': 'gss:E32000010', 'type': 'LAC', 'name': 'Dulwich and West Norwood' } }, { 'organization': 'London Assembly', 'election_date': text_type(future_date.isoformat()), 'election_name': '2016 London Assembly Election (Additional)', 'post_name': 'Assembly Member', 'area': { 'identifier': 'unit_id:41441', 'type': 'GLA', 'name': 'Greater London Authority' } }, ] self.assertEqual(expected, output)
def test_results_for_upcoming_elections(self, mock_requests): one_day = timedelta(days=1) future_date = date.today() + one_day london_assembly = ParliamentaryChamberExtraFactory.create( slug='london-assembly', base__name='London Assembly') lac_area_type = AreaTypeFactory.create(name='LAC') gla_area_type = AreaTypeFactory.create(name='GLA') area_extra_lac = AreaExtraFactory.create( base__identifier='11822', base__name="Dulwich and West Norwood", type=lac_area_type, ) area_extra_gla = AreaExtraFactory.create( base__identifier='2247', base__name='Greater London Authority', type=gla_area_type, ) election_lac = ElectionFactory.create( slug='gb-gla-2016-05-05-c', organization=london_assembly.base, name='2016 London Assembly Election (Constituencies)', election_date=future_date.isoformat(), area_types=(lac_area_type, ), ) election_gla = ElectionFactory.create( slug='gb-gla-2016-05-05-a', organization=london_assembly.base, name='2016 London Assembly Election (Additional)', election_date=future_date.isoformat(), area_types=(gla_area_type, ), ) PostExtraFactory.create( elections=(election_lac, ), base__area=area_extra_lac.base, base__organization=london_assembly.base, slug='11822', base__label='Assembly Member for Lambeth and Southwark', ) PostExtraFactory.create( elections=(election_gla, ), base__area=area_extra_gla.base, base__organization=london_assembly.base, slug='2247', base__label='Assembly Member', ) mock_requests.get.side_effect = fake_requests_for_mapit response = self.app.get('/upcoming-elections/?postcode=SE24+0AG') output = response.json self.assertEquals(len(output), 2) self.maxDiff = None expected = [ { u'organization': u'London Assembly', u'election_date': unicode(future_date.isoformat()), u'election_name': u'2016 London Assembly Election (Constituencies)', u'post_name': u'Assembly Member for Lambeth and Southwark', u'area': { u'identifier': u'11822', u'type': u'LAC', u'name': u'Dulwich and West Norwood' } }, { u'organization': u'London Assembly', u'election_date': unicode(future_date.isoformat()), u'election_name': u'2016 London Assembly Election (Additional)', u'post_name': u'Assembly Member', u'area': { u'identifier': u'2247', u'type': u'GLA', u'name': u'Greater London Authority' } }, ] self.assertEquals(expected, output)