def handle(self, verbosity: int, **_kwargs): log.init(verbosity=verbosity if '-v' in sys.argv else 2) defaults.initialize_parties() defaults.initialize_districts() self.update_elections() self.update_jurisdictions()
def with_active_election_and_one_scrapped_ballot(expect, active_election): defaults.initialize_districts() defaults.initialize_parties() commands.scrape_ballots(starting_precinct_id=1828, ballot_limit=1) commands.parse_ballots() expect(Ballot.objects.count()) == 1 expect(District.objects.count()) == 7
def with_past_election(expect, past_election): defaults.initialize_districts() commands.scrape_ballots(ballot_limit=1, max_election_error_count=1, max_ballot_error_count=1) expect(Election.objects.count()) == 2 expect(BallotWebsite.objects.count()) == 1
def parse_ballot(election_id: int, precinct_id: int) -> int: defaults.initialize_districts() defaults.initialize_parties() website, _ = BallotWebsite.objects.get_or_create( mvic_election_id=election_id, mvic_precinct_id=precinct_id ) website.fetch() website.validate() website.scrape() ballot = website.convert() ballot.website = website return ballot.parse()
def handle(self, verbosity: int, **_kwargs): # type: ignore log.reset() log.silence("datafiles") log.init(verbosity=verbosity if "-v" in sys.argv[-1] else 2) defaults.initialize_parties() defaults.initialize_districts() self.update_elections() self.update_jurisdictions() self.update_candidates() self.import_descriptions() self.export_descriptions()
def test_ballots(expect, db, election_id, precinct_id, item_count): defaults.initialize_districts() defaults.initialize_parties() website = BallotWebsite.objects.create( mi_sos_election_id=election_id, mi_sos_precinct_id=precinct_id ) website.fetch() website.validate() website.scrape() website.convert() ballot = website.convert() ballot.website = website expect(ballot.parse()) == item_count
def it_returns_data_for_a_registered_voter(expect, client, url, election): defaults.initialize_districts() response = client.get(url + "?first_name=Rosalynn" "&last_name=Bliss" "&birth_date=1975-08-03" "&zip_code=49503") expect(response.status_code) == 200 expect(response.data) == { "id": f"{settings.API_CACHE_KEY}42-4085-6199", "message": "Rosalynn Bliss is registered to vote absentee and your ballot was received on 2020-09-29 for the General Election election on 2018-08-07.", "election": { "id": 42, "name": "General Election", "date": "2018-08-07", "description": "", "reference_url": None, }, "precinct": { "id": expect.anything, "county": "Kent", "jurisdiction": "City of Grand Rapids", "ward": "2", "number": "30", }, "status": { "registered": True, "ballot": True, "ballot_url": None, "absentee": True, "absentee_application_received": "2020-06-06", "absentee_ballot_sent": "2020-09-24", "absentee_ballot_received": "2020-09-29", }, }
def it_can_be_called_multiple_times(expect, db): defaults.initialize_districts() defaults.initialize_districts() expect(DistrictCategory.objects.count()) == 26 expect(District.objects.count()) == 1
def it_returns_data_for_a_registered_voter(expect, anything, client, url, db): defaults.initialize_districts() response = client.get(url + '?first_name=Rosalynn' '&last_name=Bliss' '&birth_date=1975-08-03' '&zip_code=49503') expect(response.status_code) == 200 expect(response.data) == { 'registered': True, 'precinct': { 'url': anything, 'id': anything, 'county': 'Kent', 'jurisdiction': 'City of Grand Rapids', 'ward': '2', 'number': '30', }, 'districts': [ { 'url': anything, 'id': anything, 'category': 'Circuit Court District', 'name': '17th Circuit', }, { 'url': anything, 'id': anything, 'category': 'Community College District', 'name': 'Grand Rapids Community College', }, { 'url': anything, 'id': anything, 'category': 'County', 'name': 'Kent' }, { 'url': anything, 'id': anything, 'category': 'County Commissioner District', 'name': '18th District', }, { 'url': anything, 'id': anything, 'category': 'Court of Appeals District', 'name': '3rd District', }, { 'url': anything, 'id': anything, 'category': 'District Court District', 'name': '61st District', }, { 'url': anything, 'id': anything, 'category': 'Intermediate School District', 'name': 'Kent ISD', }, { 'url': anything, 'id': anything, 'category': 'Jurisdiction', 'name': 'City of Grand Rapids', }, { 'url': anything, 'id': anything, 'category': 'Probate Court District', 'name': 'Kent County Probate Court', }, { 'url': anything, 'id': anything, 'category': 'School District', 'name': 'Grand Rapids Public Schools', }, { 'url': anything, 'id': anything, 'category': 'State House District', 'name': '75th District', }, { 'url': anything, 'id': anything, 'category': 'State Senate District', 'name': '29th District', }, { 'url': anything, 'id': anything, 'category': 'US Congress District', 'name': '3rd District', }, ], }
def it_returns_data_for_a_registered_voter(expect, client, url, db): defaults.initialize_districts() response = client.get( url + "?first_name=Rosalynn" "&last_name=Bliss" "&birth_date=1975-08-03" "&zip_code=49503", HTTP_ACCEPT="application/json; version=1", ) expect(response.status_code) == 200 expect(response.data) == { "registered": True, "ballot": True, "absentee": True, "absentee_application_received": "2020-06-06", "absentee_ballot_sent": "2020-09-24", "absentee_ballot_received": "2020-09-29", "polling_location": [ "Encounter Church", "1736 Lyon NE", "Grand Rapids, MI 49503", ], "dropbox_location": [ "300 Ottawa Ave NW", "Grand Rapids, MI 49503", ], "recently_moved": False, "precinct": { "url": expect.anything, "id": expect.anything, "county": "Kent", "jurisdiction": "City of Grand Rapids", "ward": "2", "number": "30", }, "districts": [ { "url": expect.anything, "id": expect.anything, "category": "Circuit Court District", "name": "17th Circuit", }, { "url": expect.anything, "id": expect.anything, "category": "Community College District", "name": "Grand Rapids Community College", }, { "url": expect.anything, "id": expect.anything, "category": "County", "name": "Kent", }, { "url": expect.anything, "id": expect.anything, "category": "County Commissioner District", "name": "18th District", }, { "url": expect.anything, "id": expect.anything, "category": "Court of Appeals District", "name": "3rd District", }, { "url": expect.anything, "id": expect.anything, "category": "District Court District", "name": "61st District", }, { "url": expect.anything, "id": expect.anything, "category": "Intermediate School District", "name": "Kent ISD", }, { "url": expect.anything, "id": expect.anything, "category": "Jurisdiction", "name": "City of Grand Rapids", }, { "url": expect.anything, "id": expect.anything, "category": "Probate Court District", "name": "Kent County Probate Court", }, { "url": expect.anything, "id": expect.anything, "category": "School District", "name": "Grand Rapids Public Schools", }, { "url": expect.anything, "id": expect.anything, "category": "State House District", "name": "75th District", }, { "url": expect.anything, "id": expect.anything, "category": "State Senate District", "name": "29th District", }, { "url": expect.anything, "id": expect.anything, "category": "US Congress District", "name": "3rd District", }, ], }
def it_returns_data_for_a_registered_voter(expect, client, url, db): defaults.initialize_districts() response = client.get( url + "?first_name=Rosalynn" "&last_name=Bliss" "&birth_date=1975-08-03" "&zip_code=49503", ) expect(response.status_code) == 200 expect(response.data) == { "registered": True, "ballot": True, "absentee": True, "absentee_application_received": "2020-06-06", "absentee_ballot_sent": "2020-09-24", "absentee_ballot_received": "2020-09-29", "polling_location": [ "Encounter Church", "1736 Lyon NE", "Grand Rapids, MI 49503", ], "dropbox_locations": [ { "address": [ "300 Ottawa Ave NW", "Grand Rapids, MI 49503", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "1563 Plainfield Avenue NE", "Grand Rapids, MI 49505", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "1017 Leonard, NW", "Grand Rapids, MI 49504", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "427 Market, SW", "Grand Rapids, MI 49503", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "1150 Giddings SE", "Grand Rapids, MI 49506", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "2350 Eastern SE", "Grand Rapids, MI 49507", ], "hours": ["Available 24 Hours/7 Days a Week"], }, { "address": [ "300 Monroe Avenue, NW", "Grand Rapids, MI 49503", ], "hours": [ "Mon. 8am-5pm", "Tue. 8am-5pm", "Wed. 8am-5pm", "Thu. 8am-5pm", "Fri. 8am-5pm", ], }, ], "recently_moved": False, "precinct": { "url": expect.anything, "id": expect.anything, "county": "Kent", "jurisdiction": "City of Grand Rapids", "ward": "2", "number": "30", }, "districts": [ { "url": expect.anything, "id": expect.anything, "category": "Circuit Court District", "name": "17th Circuit", }, { "url": expect.anything, "id": expect.anything, "category": "Community College District", "name": "Grand Rapids Community College", }, { "url": expect.anything, "id": expect.anything, "category": "County", "name": "Kent", }, { "url": expect.anything, "id": expect.anything, "category": "County Commissioner District", "name": "18th District", }, { "url": expect.anything, "id": expect.anything, "category": "Court of Appeals District", "name": "3rd District", }, { "url": expect.anything, "id": expect.anything, "category": "District Court District", "name": "61st District", }, { "url": expect.anything, "id": expect.anything, "category": "Intermediate School District", "name": "Kent ISD", }, { "url": expect.anything, "id": expect.anything, "category": "Jurisdiction", "name": "City of Grand Rapids", }, { "url": expect.anything, "id": expect.anything, "category": "Probate Court District", "name": "Kent County Probate Court", }, { "url": expect.anything, "id": expect.anything, "category": "School District", "name": "Grand Rapids Public Schools", }, { "url": expect.anything, "id": expect.anything, "category": "State House District", "name": "75th District", }, { "url": expect.anything, "id": expect.anything, "category": "State Senate District", "name": "29th District", }, { "url": expect.anything, "id": expect.anything, "category": "US Congress District", "name": "3rd District", }, ], }