# Path: pupa/scrape/event.py
# class Event(BaseModel, SourceMixin, AssociatedLinkMixin, LinkMixin):
#     """
#     Details for an event in .format
#     """
#     _type = 'event'
#     _schema = schema
# 
#     def __init__(self, name, start_date, *,
#                  location_name=None,
#                  all_day=False, description="", end_date="",
#                  status="confirmed", classification="event"
#                  ):
#         super(Event, self).__init__()
#         self.start_date = start_date
#         self.all_day = all_day
#         self.end_date = end_date
#         self.name = name
#         self.description = description
#         self.status = status
#         self.classification = classification
#         if location_name:
#             self.location = {"name": location_name, "note": "", "coordinates": None}
#         else:
#             self.location = None
#         self.documents = []
#         self.participants = []
#         self.media = []
#         self.agenda = []
# 
#     def __str__(self):
#         return '{} {}'.format(self.start_date, self.name.strip())
# 
#     def set_location(self, name, *, note="", url="", coordinates=None):
#         self.location = {"name": name, "note": note, "url": url, "coordinates": coordinates}
# 
#     def add_participant(self, name, type, *, id=None, note='participant'):
#         p = {
#             "name": name,
#             "entity_type": type,
#             "note": note
#         }
#         if id:
#             p['id'] = id
#         elif type:
#             id = _make_pseudo_id(name=name)
#             p[type + '_id'] = id
# 
#         self.participants.append(p)
# 
#     def add_person(self, name, *, id=None, note='participant'):
#         return self.add_participant(name=name, type='person', id=id, note=note)
# 
#     def add_committee(self, name, *, id=None, note='participant'):
#         return self.add_participant(name=name, type='organization', id=id, note=note)
# 
#     def add_agenda_item(self, description):
#         obj = EventAgendaItem(description, self)
#         self.agenda.append(obj)
#         return obj
# 
#     def add_media_link(self, note, url, media_type, *, text='',
#                        type='media', on_duplicate='error', date=''):
#         return self._add_associated_link(collection='media',
#                                          note=note,
#                                          url=url,
#                                          text=text,
#                                          media_type=media_type,
#                                          on_duplicate=on_duplicate,
#                                          date=date)
# 
#     def add_document(self, note, url, *, text='', media_type='', on_duplicate='error', date=''):
#         return self._add_associated_link(collection='documents',
#                                          note=note, url=url,
#                                          text=text,
#                                          media_type=media_type,
#                                          on_duplicate=on_duplicate,
#                                          date=date)


import pytest
from pupa.scrape import Event as ScrapeEvent
from pupa.importers import (EventImporter, OrganizationImporter, PersonImporter, BillImporter,
                            VoteEventImporter)
from opencivicdata.legislative.models import VoteEvent, Bill, Event
from opencivicdata.core.models import (Person, Membership, Organization, Jurisdiction, Division)
                             organization=org)

    event1 = ge()
    event2 = ge()

    for event in [event1, event2]:
        item = event.add_agenda_item("Cookies will be served")
        item.add_vote_event(vote_event="Roll no. 12")

    result = EventImporter('jid', oi, pi, bi, vei).import_data([event1.as_dict()])
    assert result['event']['insert'] == 1

    result = EventImporter('jid', oi, pi, bi, vei).import_data([event2.as_dict()])
    assert result['event']['noop'] == 1

    assert Event.objects.get(name="America's Birthday"
                             ).agenda.first().related_entities.first().vote_event_id == 'vote-1'


@pytest.mark.django_db
def test_related_bill_event():
    j = create_jurisdiction()
    session = j.legislative_sessions.create(name='1900', identifier='1900')
    Organization.objects.create(id='org-id', name='House', classification='lower')
    Bill.objects.create(id='bill-1', identifier='HB 101',
                        legislative_session=session)
    event1 = ge()
    event2 = ge()

    for event in [event1, event2]:

# Path: pupa/scrape/event.py
# class Event(BaseModel, SourceMixin, AssociatedLinkMixin, LinkMixin):
#     """
#     Details for an event in .format
#     """
#     _type = 'event'
#     _schema = schema
# 
#     def __init__(self, name, start_date, *,
#                  location_name=None,
#                  all_day=False, description="", end_date="",
#                  status="confirmed", classification="event"
#                  ):
#         super(Event, self).__init__()
#         self.start_date = start_date
#         self.all_day = all_day
#         self.end_date = end_date
#         self.name = name
#         self.description = description
#         self.status = status
#         self.classification = classification
#         if location_name:
#             self.location = {"name": location_name, "note": "", "coordinates": None}
#         else:
#             self.location = None
#         self.documents = []
#         self.participants = []
#         self.media = []
#         self.agenda = []
# 
#     def __str__(self):
#         return '{} {}'.format(self.start_date, self.name.strip())
# 
#     def set_location(self, name, *, note="", url="", coordinates=None):
#         self.location = {"name": name, "note": note, "url": url, "coordinates": coordinates}
# 
#     def add_participant(self, name, type, *, id=None, note='participant'):
#         p = {
#             "name": name,
#             "entity_type": type,
#             "note": note
#         }
#         if id:
#             p['id'] = id
#         elif type:
#             id = _make_pseudo_id(name=name)
#             p[type + '_id'] = id
# 
#         self.participants.append(p)
# 
#     def add_person(self, name, *, id=None, note='participant'):
#         return self.add_participant(name=name, type='person', id=id, note=note)
# 
#     def add_committee(self, name, *, id=None, note='participant'):
#         return self.add_participant(name=name, type='organization', id=id, note=note)
# 
#     def add_agenda_item(self, description):
#         obj = EventAgendaItem(description, self)
#         self.agenda.append(obj)
#         return obj
# 
#     def add_media_link(self, note, url, media_type, *, text='',
#                        type='media', on_duplicate='error', date=''):
#         return self._add_associated_link(collection='media',
#                                          note=note,
#                                          url=url,
#                                          text=text,
#                                          media_type=media_type,
#                                          on_duplicate=on_duplicate,
#                                          date=date)
# 
#     def add_document(self, note, url, *, text='', media_type='', on_duplicate='error', date=''):
#         return self._add_associated_link(collection='documents',
#                                          note=note, url=url,
#                                          text=text,
#                                          media_type=media_type,
#                                          on_duplicate=on_duplicate,
#                                          date=date)


# Path: pupa/tests/importers/test_event_importer.py
import pytest
from pupa.scrape import Event as ScrapeEvent
from pupa.importers import (EventImporter, OrganizationImporter, PersonImporter, BillImporter,
                            VoteEventImporter)
from opencivicdata.legislative.models import VoteEvent, Bill, Event
from opencivicdata.core.models import (Person, Membership, Organization, Jurisdiction, Division)

                             organization=org)

    event1 = ge()
    event2 = ge()

    for event in [event1, event2]:
        item = event.add_agenda_item("Cookies will be served")
        item.add_vote_event(vote_event="Roll no. 12")

    result = EventImporter('jid', oi, pi, bi, vei).import_data([event1.as_dict()])
    assert result['event']['insert'] == 1

    result = EventImporter('jid', oi, pi, bi, vei).import_data([event2.as_dict()])
    assert result['event']['noop'] == 1

    assert Event.objects.get(name="America's Birthday"
                             ).agenda.first().related_entities.first().vote_event_id == 'vote-1'


@pytest.mark.django_db
def test_related_bill_event():
    j = create_jurisdiction()
    session = j.legislative_sessions.create(name='1900', identifier='1900')
    Organization.objects.create(id='org-id', name='House', classification='lower')
    Bill.objects.create(id='bill-1', identifier='HB 101',
                        legislative_session=session)
    event1 = ge()
    event2 = ge()

    for event in [event1, event2]:

        item = event.add_agenda_item("Cookies will be served")