import pytest

from lametro.search_indexes import LAMetroBillIndex

@pytest.mark.parametrize('session_identifier,prepared_session', [
    ('2014', '7/1/2014 to 6/30/2015'),
    ('2015', '7/1/2015 to 6/30/2016'),
    ('2016', '7/1/2016 to 6/30/2017'),
    ('2017', '7/1/2017 to 6/30/2018'),
    ('2018', '7/1/2018 to 6/30/2019'),
])
def test_legislative_session(bill, 
                             legislative_session,
                             session_identifier,
                             prepared_session):
    '''
    This test instantiates LAMetroBillIndex – a subclass of SearchIndex from
    Haystack, used for building the Solr index.

    The test, then, calls the SearchIndex `prepare` function, 
    which returns a dict of prepped data.
    https://github.com/django-haystack/django-haystack/blob/4910ccb01c31d12bf22dcb000894eece6c26f74b/haystack/indexes.py#L198
    '''
    legislative_session.identifier = session_identifier
    legislative_session.save()
    bill = bill.build(legislative_session=legislative_session)

    index = LAMetroBillIndex()
    indexed_data = index.prepare(bill)

    assert indexed_data['legislative_session'] == prepared_session

@@ -6,16 +6,46 @@
 t pytest
+%0Afrom datetime import datetime
 %0A%0Afrom l
@@ -1200,8 +1200,2168 @@
 session%0A
+%0A@pytest.mark.parametrize('session_identifier,prepared_session', %5B%0A    ('2014', '7/1/2014 to 6/30/2015'),%0A    ('2015', '7/1/2015 to 6/30/2016'),%0A    ('2016', '7/1/2016 to 6/30/2017'),%0A    ('2017', '7/1/2017 to 6/30/2018'),%0A    ('2018', '7/1/2018 to 6/30/2019'),%0A%5D)%0Adef test_sponsorships(bill, %0A                      legislative_session,%0A                      session_identifier,%0A                      prepared_session,%0A                      metro_organization,%0A                      event,%0A                      mocker):%0A    '''%0A    This test instantiates LAMetroBillIndex %E2%80%93 a subclass of SearchIndex from%0A    Haystack, used for building the Solr index.%0A%0A    The test, then, calls the SearchIndex %60prepare%60 function, %0A    which returns a dict of prepped data.%0A    https://github.com/django-haystack/django-haystack/blob/4910ccb01c31d12bf22dcb000894eece6c26f74b/haystack/indexes.py#L198%0A    '''%0A    legislative_session.identifier = session_identifier%0A    legislative_session.save()%0A    bill = bill.build(legislative_session=legislative_session)%0A%0A    org1 = metro_organization.build()%0A    org2 = metro_organization.build()%0A    event1 = event.build()%0A    # event2 = event.build()%0A    # event3 = event.build()%0A    actions_and_agendas = %5B%0A        %7B%0A            'date': datetime.now(),%0A            'description': 'org1 description',%0A            'event': event1,%0A            'organization': org1%0A        %7D,%0A        %7B%0A            'date': datetime.now(),%0A            'description': 'org2 descripton',%0A            'event': event1,%0A            'organization': org2%0A        %7D,%0A        %7B%0A            'date': datetime.now(),%0A            'description': 'org2 descripton',%0A            'event': event1,%0A            'organization': org2%0A        %7D%0A    %5D%0A    import pdb%0A    pdb.set_trace()%0A    mock_actions_and_agendas = mocker.patch('lametro.models.LAMetroBill.actions_and_agendas',%5C%0A                                            new_callable=mocker.PropertyMock,%5C%0A                                            return_value=actions_and_agendas)%0A%0A    index = LAMetroBillIndex()%0A    indexed_data = index.prepare(bill)%0A%0A    assert indexed_data%5B'sponsorships'%5D == %7Borg1.name, org2.name%7D%0A

add test_sponsorships