def test_is_election_day(self): today = Election(election_date=datetime.date(2021, 5, 6)) future = Election(election_date=datetime.date(2021, 5, 7)) past = Election(election_date=datetime.date(2021, 5, 5)) assert today.is_election_day is True assert future.is_election_day is False assert past.is_election_day is False
def _build(self, record): def merge_dicts(d1, d2): d3 = d1.copy() d3.update(d2) return d3 try: return Election.private_objects.get( election_id=record["election_id"]) except Election.DoesNotExist: # return an instance of elections.models.Election # but don't persist it to the DB yet. # The calling code is responsible for calling .save() return Election(**merge_dicts( record, { "poll_open_date": self.date, "election_type": self.election_type, "election_subtype": self.subtype, "organisation": self.organisation, "division": self.division, "elected_role": self.get_elected_role(), "voting_system": self.get_voting_system(), }, ))
def create_and_save_election_object_jformat( election_type, election_websurvey, election_date, slug, human_friendly_name): """ Create a new election given the election information Keyword Arguments election_type -- indicates whether the election is a general election of by election election_websurvey -- the link to the election's websurvey election_date - the date and time of the election slug - the slug for the election human_friendly_name -- the human friendly name of the election Return the election object """ election = Election(slug=slug, election_type=election_type, date=election_date, websurvey=election_websurvey, human_friendly_name=human_friendly_name) election.save() logger.info(f"[elections/save_new_election_obj_jformat.py create_and_save_election_object_jformat()] " f"saving new election object {election} with date {election_date}, election_type {election_type} " f"websurvey link {election_websurvey}, slug {slug} and " f"human friendly name {human_friendly_name} " ) return election
def test_election(self): e = Election( election_date=datetime.datetime.today(), current=True, ) e.save()
def test_name_without_brackets(self, name, expected): election = Election(name=name, any_non_by_elections=True) assert election.name_without_brackets == expected
def test_in_past(self): yesterday = datetime.date.today() - datetime.timedelta(days=1) election = Election(election_date=yesterday) assert election.in_past is True
def city_of_london_election(self): return Election(slug="local.city-of-london")
def election(self): return Election(slug="not.city-of-london")
def setUp(self): self.election = Election(slug="not.city-of-london") self.city_of_london_election = Election(slug="local.city-of-london")