Skip to content

Commit

Permalink
feat(for_id): Return None for europarl elections.
Browse files Browse the repository at this point in the history
* There's no clear way to derive Region from Country if the election is in England.
  • Loading branch information
mrwilson committed Aug 24, 2019
1 parent d1e3b52 commit f92aa14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sopn_publish_date/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def for_id(self, election_id: str, country: Country = None) -> date:
election_type, poll_date = type_and_poll_date(election_id)

def valid_election_type(el_type):
return el_type in self.election_id_lookup or el_type in ["local", "parl"]
return el_type in self.election_id_lookup or el_type in ["local", "parl", "europarl"]

def requires_country(el_type):
return el_type not in self.election_id_lookup
Expand All @@ -56,6 +56,8 @@ def requires_country(el_type):
return self.local(poll_date, country=country)
elif election_type == "parl":
return self.uk_parliament(poll_date, country=country)
elif election_type == "europarl":
return None

def northern_ireland_assembly(self, poll_date: date) -> date:
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_sopn_publish_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_publish_date_parl_id_with_country():
assert publish_date == date(2019, 1, 25)


def test_publish_date_europarl_id_with_country():
publish_date = sopn_publish_date.for_id("europarl.2019-02-21", country=Country.ENGLAND)

assert publish_date is None

def test_publish_date_not_an_election_type():

with raises(NoSuchElectionTypeError) as err:
Expand Down

0 comments on commit f92aa14

Please sign in to comment.