示例#1
0
    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])
示例#2
0
    def test_county_parsing(self):
        from open_elections.content_parser import parse_county_xml
        from open_elections.models import CountyElection
        from open_elections.models import CountyContest
        from open_elections.models import CountyCandidate   

        parse_county_xml(self.sample_files['sample_county_data.xml'])
        # We'll just shortcut checking for values and see if these
        # records exist. I am betting they do.
        assert CountyElection.objects.filter(title="CITY OF SAN DIEGO").exists()
        assert CountyContest.objects.filter(contest_id=1).exists()
        assert CountyCandidate.objects.filter(name="NATHAN FLETCHER").exists()