def setUp(self): super().setUp() OrganisationFactory(official_identifier='TEST1', official_name='Foo & Bar District Council', organisation_type="local-authority", start_date=date(2016, 10, 1), end_date=date(2017, 10, 1)) OrganisationFactory(official_identifier='TEST1', official_name='Bar with Foo District Council', organisation_type="local-authority", start_date=date(2017, 10, 2), end_date=None) OrganisationFactory(official_identifier='TEST2', official_name='Baz District Council', organisation_type="local-authority", start_date=date(2016, 10, 1), end_date=date(2017, 10, 1)) OrganisationFactory( official_identifier='TEST2', official_name='Baz Metropolitan Borough Council', organisation_type="local-authority", start_date=date(2017, 10, 2), end_date=date(2018, 10, 2), )
def test_scotland_local_stv(self): """ Scottish local elections have the type of `local` but unlike the rest of the UK that uses FPTP, it uses STV """ # "Normal" UK local election is FPTP election_id = ElectionBuilder('local', '2017-05-04')\ .build_election_group() assert election_id.voting_system.slug == "FPTP" scot_org = OrganisationFactory(territory_code="SCT", ) ElectedRole.objects.create( election_type=self.election_type1, organisation=scot_org, elected_title="MSP", elected_role_name="MSP for Foo Town", ) # Scotish local elections are STV scot_id = ElectionBuilder('local', '2017-05-04')\ .with_organisation(scot_org)\ .build_organisation_group(None) assert scot_id.voting_system.slug == "STV"
def test_all_ok(self): org = OrganisationFactory() OrganisationDivisionSetFactory(organisation=org) OrganisationGeographyFactory(organisation=org) ElectedRoleFactory(organisation=org) self.assertEqual(len(OrganisationProblem.objects.all()), 0)
def test_import_org_geography(self): cmd = ConcreteOsniCommand() og = OrganisationGeographyFactory(organisation=OrganisationFactory(), geography=None, source="unknown") cmd.import_org_geography(og, fake_record) self.assertEqual(fake_record["geometry"], og.geography) self.assertEqual(cmd.source, og.source)
def test_all_broken(self): OrganisationFactory() self.assertEqual(len(OrganisationProblem.objects.all()), 1) problem = OrganisationProblem.objects.all()[0] self.assertTrue(problem.no_geography) self.assertTrue(problem.no_divisionset) self.assertTrue(problem.no_electedrole) self.assertEqual("No associated OrganisationGeography", problem.problem_text)
def test_no_electedrole(self): org = OrganisationFactory() OrganisationDivisionSetFactory(organisation=org) OrganisationGeographyFactory(organisation=org) self.assertEqual(len(OrganisationProblem.objects.all()), 1) problem = OrganisationProblem.objects.all()[0] self.assertFalse(problem.no_geography) self.assertFalse(problem.no_divisionset) self.assertTrue(problem.no_electedrole) self.assertEqual("No associated ElectedRole", problem.problem_text)
def setUp(self): super().setUp() OrganisationGeographyFactory(organisation=OrganisationFactory( official_identifier="TEST1", official_name="Foo & Bar District Council", organisation_type="local-authority", start_date=date(2016, 10, 1), end_date=date(2017, 10, 1), )) OrganisationFactory( official_identifier="TEST1", official_name="Bar with Foo District Council", organisation_type="local-authority", start_date=date(2017, 10, 2), end_date=None, ) OrganisationFactory( official_identifier="TEST2", official_name="Baz District Council", organisation_type="local-authority", start_date=date(2016, 10, 1), end_date=date(2017, 10, 1), )
def test_one_geography_with_gss(self): org = OrganisationFactory() geo = OrganisationGeographyFactory(organisation=org, gss='X01000001') self.assertEqual(geo, org.get_geography(date.today())) self.assertEqual(geo, org.get_geography("doesn't even need to be a date")) self.assertEqual('https://mapit.mysociety.org/area/X01000001', org.format_geography_link()) geo.gss = '' geo.save() self.assertEqual(None, org.format_geography_link())
def test_multiple_geographies(self): org = OrganisationFactory(start_date=date(2001, 1, 1), end_date=None) OrganisationGeographyFactory(organisation=org, gss='X01000001', start_date=None, end_date='2001-01-01') OrganisationGeographyFactory(organisation=org, gss='X01000002', start_date='2001-01-02', end_date='2002-01-01') OrganisationGeographyFactory(organisation=org, gss='X01000003', start_date='2002-01-02', end_date=None) self.assertEqual('X01000001', org.get_geography(date(2001, 1, 1)).gss) self.assertEqual('X01000002', org.get_geography(date(2001, 7, 20)).gss) self.assertEqual('X01000003', org.get_geography(date(2099, 1, 1)).gss) with self.assertRaises(ValueError): org.get_geography(date(1900, 1, 1)) # before the org start date
def test_organisation_factory(self): o = OrganisationFactory() assert o.slug == "org-{}".format(o.official_identifier)
def test_one_geography_no_gss(self): org = OrganisationFactory() geo = OrganisationGeographyFactory(organisation=org, gss='') self.assertEqual(geo, org.get_geography(date.today())) self.assertEqual(None, org.format_geography_link())
def test_no_geographies(self): org = OrganisationFactory() self.assertEqual(None, org.get_geography(date.today())) self.assertEqual(None, org.format_geography_link())
def setUp(self): super().setUp() self.org = OrganisationFactory( start_date=date(2001, 1, 1), end_date=date(2002, 1, 1), )
def test_all_expected_fields_returned(self): org = OrganisationFactory() org_div = OrganisationDivisionFactory(organisation=org, territory_code="ENG") ElectionFactory(group=None, organisation=org, division=org_div) resp = self.client.get("/api/elections/") assert resp.json() == json.loads(""" { "next": null, "previous": null, "results": [ { "group_type": null, "current": false, "poll_open_date": "2017-03-23", "election_id": "local.place-name-0.2017-03-23", "group": null, "division": { "name": "Division 0", "slug": "0", "geography_curie": "test:0", "divisionset": { "start_date": "2017-05-04", "legislation_url": "https://example.com/the-law", "short_title": "Made up boundary changes", "notes": "This is just for testing.", "end_date": "2025-05-03", "consultation_url": "https://example.com/consultation", "mapit_generation_id": "" }, "mapit_generation_high": null, "seats_total": null, "division_election_sub_type": "", "division_subtype": "", "mapit_generation_low": null, "division_type": "test", "official_identifier": "0", "territory_code": "ENG" }, "election_type": { "name": "Local elections", "election_type": "local" }, "explanation": null, "voting_system": { "slug": "", "name": "", "uses_party_lists": false }, "children": [], "election_subtype": null, "organisation": { "slug": "org-0", "territory_code": "ENG", "organisation_subtype": "", "common_name": "Organisation 0", "official_name": "The Organisation 0 Council", "organisation_type": "local-authority", "election_name": "", "official_identifier": "0", "gss": "E000000" }, "election_title": "Election 0", "elected_role": "Councillor", "seats_contested": 1, "tmp_election_id": null, "metadata": null } ], "count": 1 } """)
def test_all_expected_fields_returned(self): OrganisationFactory.reset_sequence(0) OrganisationDivisionFactory.reset_sequence(0) org = OrganisationFactory() org_div = OrganisationDivisionFactory(organisation=org, territory_code="ENG") ElectionWithStatusFactory(group=None, organisation=org, division=org_div) self.expected_object = json.loads(""" { "group_type": null, "identifier_type": "ballot", "current": false, "poll_open_date": "2017-03-23", "election_id": "local.place-name-0.2017-03-23", "group": null, "division": { "name": "Division 0", "slug": "0", "divisionset": { "start_date": "2017-05-04", "legislation_url": "https://example.com/the-law", "short_title": "Made up boundary changes", "notes": "This is just for testing.", "end_date": "2025-05-03", "consultation_url": "https://example.com/consultation" }, "seats_total": null, "division_election_sub_type": "", "division_subtype": "", "division_type": "test", "official_identifier": "0", "territory_code": "ENG" }, "election_type": { "name": "Local elections", "election_type": "local" }, "explanation": null, "voting_system": { "slug": "", "name": "", "uses_party_lists": false }, "children": [], "election_subtype": null, "organisation": { "url": "http://testserver/api/organisations/local-authority/0/2016-10-01/", "slug": "org-0", "territory_code": "ENG", "organisation_subtype": "", "common_name": "Organisation 0", "official_name": "The Organisation 0 Council", "organisation_type": "local-authority", "election_name": "", "official_identifier": "0", "start_date": "2016-10-01", "end_date": null }, "election_title": "Election 0", "elected_role": "Councillor", "seats_contested": 1, "tmp_election_id": null, "metadata": null, "deleted": false, "cancelled": false, "replaces": null, "replaced_by": null } """) resp = self.client.get("/api/elections/") data = resp.json() self.assertEqual(data["results"][0], self.expected_object) resp = self.client.get("/api/elections/local.place-name-0.2017-03-23/") data = resp.json() self.assertEqual(data, self.expected_object) resp = self.client.get( "/api/elections/local.place-name-0.2017-03-23/geo/", content_type="application/json", ) data = resp.json() self.assertEqual(data["properties"], self.expected_object)