def _setup_extra_posts(self):
     # Create some extra posts and areas:
     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_gla = ElectionFactory.create(
         slug="gla.a.2016-05-05",
         organization=london_assembly,
         name="2016 London Assembly Election (Additional)",
     )
     PostFactory.create(
         elections=(election_lac, ),
         organization=london_assembly,
         slug="lambeth-and-southwark",
         label="Assembly Member for Lambeth and Southwark",
     )
     PostFactory.create(
         elections=(election_gla, ),
         organization=london_assembly,
         slug="london",
         label="2016 London Assembly Election (Additional)",
     )
Esempio n. 2
0
 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_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(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_data(self):
     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",
     )
Esempio n. 6
0
 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',
     )
Esempio n. 7
0
 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 setUp(self):
     super(TestConstituencyPostcodeFinderView, self).setUp()
     wmc_area_type = AreaTypeFactory.create()
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug='2015',
         name='2015 General Election',
         area_types=(wmc_area_type,),
         organization=commons,
     )
     area_extra = AreaExtraFactory.create(
         base__name="Dulwich and West Norwood",
         base__identifier='gss:E14000673',
         type=wmc_area_type,
     )
     self.area = area_extra.base
     PostExtraFactory.create(
         elections=(election,),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
         base__area=area_extra.base,
     )
 def setUp(self):
     super(TestConstituencyPostcodeFinderView, self).setUp()
     wmc_area_type = AreaTypeFactory.create()
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug='2015',
         name='2015 General Election',
         area_types=(wmc_area_type, ),
         organization=commons,
     )
     area_extra = AreaExtraFactory.create(
         base__name="Dulwich and West Norwood",
         base__identifier='gss:E14000673',
         type=wmc_area_type,
     )
     self.area = area_extra.base
     PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
         base__area=area_extra.base,
     )
Esempio n. 10
0
    def setUp(self):
        org = ParliamentaryChamberExtraFactory.create()

        self.election = ElectionFactory.create(slug='2015',
                                               name='2015 Election',
                                               election_date=date.today(),
                                               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="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")
Esempio n. 12
0
    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 _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',
     )
Esempio n. 14
0
    def setUp(self):
        org = ParliamentaryChamberFactory.create()

        self.election = ElectionFactory.create(
            slug="2015",
            name="2015 Election",
            election_date=date.today(),
            organization=org,
        )
 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',
     )
Esempio n. 16
0
    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
        )
Esempio n. 17
0
 def setUp(self):
     election = ElectionFactory.create(slug="2015",
                                       name="2015 General Election")
     commons = ParliamentaryChamberFactory.create()
     self.post = PostFactory.create(
         elections=(election, ),
         organization=commons,
         slug="65808",
         label="Member of Parliament for Dulwich and West Norwood",
     )
Esempio n. 18
0
 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',
     )
Esempio n. 19
0
 def setUp(self):
     election = ElectionFactory.create(slug="parl.2015-05-07",
                                       name="2015 General Election")
     commons = ParliamentaryChamberFactory.create()
     self.post = PostFactory.create(
         elections=(election, ),
         organization=commons,
         slug="dulwich-and-west-norwood",
         label="Member of Parliament for Dulwich and West Norwood",
     )
     self.ballot = self.post.ballot_set.get()
Esempio n. 20
0
 def setUp(self):
     wmc_area_type = AreaTypeFactory.create()
     election = ElectionFactory.create(slug='2015',
                                       name='2015 General Election',
                                       area_types=(wmc_area_type, ))
     commons = ParliamentaryChamberFactory.create()
     self.post = PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood')
Esempio n. 21
0
 def setUp(self):
     gb_parties = PartySetFactory.create(slug="gb", name="Great Britain")
     self.election = ElectionFactory.create(
         slug="parl.2015-05-07", name="2015 General Election", current=True
     )
     commons = ParliamentaryChamberFactory.create()
     self.post = PostFactory.create(
         elections=(self.election,),
         organization=commons,
         slug="dulwich-and-west-norwood",
         label="Member of Parliament for Dulwich and West Norwood",
         party_set=gb_parties,
     )
     self.ballot = self.post.ballot_set.get(election=self.election)
Esempio n. 22
0
 def setUp(self):
     wmc_area_type = AreaTypeFactory.create()
     election = ElectionFactory.create(
         slug='2015',
         name='2015 General Election',
         area_types=(wmc_area_type,)
     )
     commons = ParliamentaryChamberFactory.create()
     self.post = PostExtraFactory.create(
         elections=(election,),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood'
     )
Esempio n. 23
0
 def setUp(self):
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     election = ElectionFactory.create(
         slug='2015',
         name='2015 General Election',
         current=True,
     )
     commons = ParliamentaryChamberFactory.create()
     self.post_extra = PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
     )
 def setUp(self):
     super(TestModels, self).setUp()
     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, ))
     commons = ParliamentaryChamberFactory.create()
     self.post_extra = PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
     )
Esempio n. 25
0
 def setUp(self):
     gb_parties = PartySetFactory.create(slug="gb", name="Great Britain")
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug="parl.2017-03-23",
         name="2015 General Election",
         organization=commons,
         election_date="2017-03-23",
     )
     PostFactory.create(
         elections=(election, ),
         organization=commons,
         slug="dulwich-and-west-norwood",
         label="Member of Parliament for Dulwich and West Norwood",
         party_set=gb_parties,
     )
 def setUp(self):
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug='parl.2017-03-23',
         name='2015 General Election',
         organization=commons,
         election_date="2017-03-23",
     )
     PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='dulwich-and-west-norwood',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
     )
 def setUp(self):
     super(TestModels, self).setUp()
     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,)
     )
     commons = ParliamentaryChamberFactory.create()
     self.post_extra = PostExtraFactory.create(
         elections=(election,),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
     )
    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):
     wmc_area_type = AreaTypeFactory.create()
     gb_parties = PartySetFactory.create(slug="gb", name="Great Britain")
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug="2015", name="2015 General Election", area_types=(wmc_area_type,), organization=commons
     )
     area_extra = AreaExtraFactory.create(
         base__name="Dulwich and West Norwood", base__identifier="gss:E14000673", type=wmc_area_type
     )
     self.area = area_extra.base
     PostExtraFactory.create(
         elections=(election,),
         base__organization=commons,
         slug="65808",
         base__label="Member of Parliament for Dulwich and West Norwood",
         party_set=gb_parties,
         base__area=area_extra.base,
     )
 def setUp(self):
     wmc_area_type = AreaTypeFactory.create()
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(slug='2015',
                                       name='2015 General Election',
                                       area_types=(wmc_area_type, ),
                                       organization=commons)
     area_extra = AreaExtraFactory.create(
         base__name="Dulwich and West Norwood",
         type=wmc_area_type,
     )
     self.area = area_extra.base
     PostExtraFactory.create(
         elections=(election, ),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=gb_parties,
         base__area=area_extra.base,
     )
Esempio n. 31
0
    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(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):
     wmc_area_type = AreaTypeFactory.create()
     gb_parties = PartySetFactory.create(slug='gb', name='Great Britain')
     commons = ParliamentaryChamberFactory.create()
     election = ElectionFactory.create(
         slug='2015',
         name='2015 General Election',
         area_types=(wmc_area_type,),
         organization=commons
     )
     area_extra = AreaExtraFactory.create(
         base__name="Dulwich and West Norwood",
         type=wmc_area_type,
     )
     self.area = area_extra.base
     PostExtraFactory.create(
         elections=(election,),
         base__organization=commons,
         slug='65808',
         base__label='Member of Parliament for Dulwich and West Norwood',
         party_set=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_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)
Esempio n. 36
0
    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'
        )
Esempio n. 37
0
    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')
Esempio n. 38
0
    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 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)
Esempio n. 40
0
    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 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)