<s> import pytest <EOL> from pupa . scrape import Event as ScrapeEvent <EOL> from pupa . importers import ( EventImporter , OrganizationImporter , PersonImporter , BillImporter , <EOL> VoteEventImporter ) <EOL> from opencivicdata . models import ( Jurisdiction , Event , Person , Membership , Organization , Bill , <EOL> VoteEvent ) <EOL> def ge ( ) : <EOL> event = ScrapeEvent ( <EOL> name = "<STR_LIT>" , <EOL> start_time = "<STR_LIT>" , <EOL> location_name = "<STR_LIT>" , <EOL> timezone = "<STR_LIT>" , <EOL> all_day = True ) <EOL> event . add_person ( "<STR_LIT>" ) <EOL> return event <EOL> oi = OrganizationImporter ( '<STR_LIT>' ) <EOL> pi = PersonImporter ( '<STR_LIT>' ) <EOL> bi = BillImporter ( '<STR_LIT>' , oi , pi ) <EOL> vei = VoteEventImporter ( '<STR_LIT>' , pi , oi , bi ) <EOL> @ pytest . mark . django_db <EOL> def test_related_people_event ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> george = Person . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> john = Person . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> o = Organization . objects . create ( name = '<STR_LIT>' , jurisdiction_id = '<STR_LIT>' ) <EOL> Membership . objects . create ( person = george , organization = o ) <EOL> Membership . objects . create ( person = john , organization = o ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> item = event . add_agenda_item ( "<STR_LIT>" ) <EOL> item . add_person ( person = "<STR_LIT>" ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> assert Event . objects . get ( name = "<STR_LIT>" ) . participants . first ( ) . person_id == '<STR_LIT>' <EOL> assert Event . objects . get ( name = "<STR_LIT>" ) . agenda . first ( ) . related_entities . first ( ) . person_id == '<STR_LIT>' <EOL> @ pytest . mark . django_db <EOL> def test_related_vote_event ( ) : <EOL> j = Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> session = j . legislative_sessions . create ( name = '<STR_LIT>' , identifier = '<STR_LIT>' ) <EOL> org = Organization . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' , classification = '<STR_LIT>' ) <EOL> bill = Bill . objects . create ( id = '<STR_LIT>' , identifier = '<STR_LIT>' , <EOL> legislative_session = session ) <EOL> vote = VoteEvent . objects . create ( id = '<STR_LIT>' , <EOL> identifier = "<STR_LIT>" , <EOL> bill = bill , <EOL> legislative_session = session , <EOL> organization = org ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> item = event . add_agenda_item ( "<STR_LIT>" ) <EOL> item . add_vote_event ( vote_event = "<STR_LIT>" ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> assert Event . objects . get ( name = "<STR_LIT>" ) . agenda . first ( ) . related_entities . first ( ) . vote_event_id == '<STR_LIT>' <EOL> @ pytest . mark . django_db <EOL> def test_related_bill_event ( ) : <EOL> j = Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> session = j . legislative_sessions . create ( name = '<STR_LIT>' , identifier = '<STR_LIT>' ) <EOL> org = Organization . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' , classification = '<STR_LIT>' ) <EOL> bill = Bill . objects . create ( id = '<STR_LIT>' , identifier = '<STR_LIT>' , <EOL> legislative_session = session ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> item = event . add_agenda_item ( "<STR_LIT>" ) <EOL> item . add_bill ( bill = "<STR_LIT>" ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> assert Event . objects . get ( name = "<STR_LIT>" ) . agenda . first ( ) . related_entities . first ( ) . bill_id == '<STR_LIT>' <EOL> @ pytest . mark . django_db <EOL> def test_related_committee_event ( ) : <EOL> j = Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> session = j . legislative_sessions . create ( name = '<STR_LIT>' , identifier = '<STR_LIT>' ) <EOL> org = Organization . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> classification = '<STR_LIT>' , <EOL> jurisdiction = j ) <EOL> com = Organization . objects . create ( id = '<STR_LIT>' , name = "<STR_LIT>" , <EOL> classification = '<STR_LIT>' , <EOL> parent = org , <EOL> jurisdiction = j ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> item = event . add_agenda_item ( "<STR_LIT>" ) <EOL> item . add_committee ( committee = "<STR_LIT>" ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> assert Event . objects . get ( name = "<STR_LIT>" ) . agenda . first ( ) . related_entities . first ( ) . organization_id == '<STR_LIT>' <EOL> @ pytest . mark . django_db <EOL> def test_media_event ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> item = event . add_agenda_item ( "<STR_LIT>" ) <EOL> item . add_media_link ( <EOL> note = "<STR_LIT>" , <EOL> media_type = '<STR_LIT>' , <EOL> url = "<STR_LIT>" <EOL> ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> @ pytest . mark . django_db <EOL> def test_media_document ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> event1 = ge ( ) <EOL> event2 = ge ( ) <EOL> for event in [ event1 , event2 ] : <EOL> event . add_document ( note = "<STR_LIT>" , <EOL> url = "<STR_LIT>" ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> @ pytest . mark . django_db <EOL> def test_full_event ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> george = Person . objects . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> o = Organization . objects . create ( name = '<STR_LIT>' , jurisdiction_id = '<STR_LIT>' ) <EOL> Membership . objects . create ( person = george , organization = o ) <EOL> event = ge ( ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> event = ge ( ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> event = ge ( ) <EOL> event . location [ '<STR_LIT:name>' ] = "<STR_LIT>" <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> @ pytest . mark . django_db <EOL> def test_bad_event_time ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> event = ge ( ) <EOL> event . start_time = "<STR_LIT>" <EOL> pytest . raises ( <EOL> ValueError , <EOL> EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_item , <EOL> event . as_dict ( ) <EOL> ) <EOL> @ pytest . mark . django_db <EOL> def test_top_level_media_event ( ) : <EOL> Jurisdiction . objects . create ( id = '<STR_LIT>' , division_id = '<STR_LIT>' ) <EOL> event1 , event2 = ge ( ) , ge ( ) <EOL> event1 . add_media_link ( "<STR_LIT>" , "<STR_LIT>" , <EOL> media_type = '<STR_LIT>' ) <EOL> event2 . add_media_link ( "<STR_LIT>" , "<STR_LIT>" , <EOL> media_type = '<STR_LIT>' ) <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event1 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> result = EventImporter ( '<STR_LIT>' , oi , pi , bi , vei ) . import_data ( [ event2 . as_dict ( ) ] ) <EOL> assert result [ '<STR_LIT>' ] [ '<STR_LIT>' ] == <NUM_LIT:1> </s>
