def handle(self, *args, **options): content = ContentFetcher() try: if args[0] == 'state': from open_elections.content_parser import parse_state_xml state_xml_files = content.fetch_sos() parse_state_xml(state_xml_files) emit_combined_csv_results() elif args[0] == 'county': from open_elections.content_parser import parse_county_xml county_xml_file = content.fetch_xml_content(server="county") parse_county_xml(county_xml_file) emit_combined_csv_results() elif args[0] == 'ap': from open_elections.content_parser import parse_ap_xml ap_xml_file = content.fetch_xml_content(server="ap") parse_county_xml(ap_xml_file) emit_combined_csv_results() self.stdout.write('Successfully ran function "parse_%s_xml()"' % args[0]) except ImportError: raise CommandError('Function "parse_%s_xml()" does not exist' % args[0])
def test_state_parsing(self): from open_elections.content_parser import parse_state_xml from open_elections.models import StateContest from open_elections.models import StateCandidate # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# ## GOAL: Argument must be a list, tuple open-able files. ## It will raise an assertion error if not, so this code should run fine. ## ---- ## state_sample = [self.sample_files['sample_state.xml']] parse_state_xml(state_sample) ## Goal: Query the database for values we know are in the file. ## ---- ## ## Let's try a candidate first: obama = StateCandidate.objects.get(candidate_name="Barack Obama") self.assertEquals(obama.affiliation, 'DEM') self.assertEquals(obama.valid_votes, 7854285) ## How's about a contest next: pres = StateContest.objects.get(contest_name='President') self.assertEquals(pres.total_precincts, 24491) self.assertEquals(pres.total_precincts, 24491) self.assertEquals(pres.contest_identifier, '010000000000')