Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Significant Date facet and add Fiscal Year facet #727

Merged
merged 11 commits into from
Sep 3, 2021
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ debug.log
/configs/settings_deployment.staging.py

*.csv
.gnupg/
.gnupg/

lametro/secrets.py
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ services:
DATABASE_URL: 'postgis://postgres:@postgres/lametro'
SHARED_DB: "True"
command: sh -c 'pupa update --rpm=600 lametro people && pupa update --rpm=600 lametro bills window=30 && pupa update --rpm=600 lametro events'
volumes:
- ./lametro/secrets.py:/app/lametro/secrets.py

volumes:
lametro-solr-data:
Expand Down
4 changes: 2 additions & 2 deletions lametro/management/commands/refresh_guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ClassificationMixin:
'Subregion',
),
'significant_date_exact': (
'Dates',
'Date',
),
'motion_by_exact': (
'Board Member',
Expand All @@ -77,7 +77,7 @@ class ClassificationMixin:
'Plan',
'Program',
'Policy'
),
)
}

@property
Expand Down
25 changes: 19 additions & 6 deletions lametro/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ def prepare_attachment_text(self, obj):
)

def prepare_legislative_session(self, obj):
start_year = obj.legislative_session.identifier
end_year = int(start_year) + 1

session = '7/1/{start_year} to 6/30/{end_year}'.format(start_year=start_year,
end_year=end_year)
aa = sorted(obj.actions_and_agendas, key=lambda i: i['date'],reverse=True)
agendas = [a for a in aa if a['description'] == 'SCHEDULED']
if len(aa) > 1:
if agendas:
action_date = agendas[0]['date']
else:
action_date = aa[0]['date']

if action_date.month <= 6:
start_year = action_date.year - 1
end_year = action_date.year
else:
start_year = action_date.year
end_year = action_date.year + 1

session = '7/1/{start_year} to 6/30/{end_year}'.format(start_year=start_year,
end_year=end_year)
return session
return None

return session

def prepare_topics(self, obj):
return self._topics_from_classification(obj, 'topics_exact')
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Django>=2.2,<2.3
psycopg2-binary>=2.8,<2.9
opencivicdata>=3.1.0
django-councilmatic[convert_docs]==2.6.1
django-debug-toolbar==1.9.1
Expand All @@ -13,3 +14,4 @@ lxml==4.1.1
dj_database_url
https://github.com/opencivicdata/python-legistar-scraper/zipball/master
locustio==0.13.2
django-recaptcha==2.0.6
97 changes: 79 additions & 18 deletions tests/test_solr_prep.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,100 @@
import pytest
from datetime import datetime
from datetime import datetime, timedelta

from opencivicdata.legislative.models import EventParticipant

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):
@pytest.mark.parametrize('month', [6, 7])
def test_legislative_session(bill, metro_organization, event, mocker, month):
'''
This test instantiates LAMetroBillIndex – a subclass of SearchIndex from
Haystack, used for building the Solr index.

The test, then, calls the SearchIndex `prepare` function,
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)
org = metro_organization.build()
event = event.build()
bill = bill.build()

now = datetime.now()

# Create test actions and agendas
recent_action = {
'date': datetime(now.year, month, now.day),
'description': 'org2 descripton',
'event': event,
'organization': org
}
older_action = {
'date': datetime(now.year, month, now.day) - timedelta(days=365*2),
'description': 'org2 descripton',
'event': event,
'organization': org
}
recent_agenda = {
'date': datetime(now.year, month, now.day) - timedelta(days=365),
'description': 'SCHEDULED',
'event': event,
'organization': org
}
older_agenda = {
'date': datetime(now.year, month, now.day) - timedelta(days=365*3),
'description': 'SCHEDULED',
'event': event,
'organization': org
}

# Test indexed value when there are both actions and agendas
mock_actions_and_agendas = mocker.PropertyMock(
return_value=[recent_action, older_action, recent_agenda, older_agenda]
)

mocker.patch('lametro.models.LAMetroBill.actions_and_agendas', new_callable=mock_actions_and_agendas)

index = LAMetroBillIndex()
expected_fmt = '7/1/{0} to 6/30/{1}'

indexed_data = index.prepare(bill)

assert indexed_data['legislative_session'] == prepared_session
if month <= 6:
expected_value = expected_fmt.format(recent_agenda['date'].year - 1, recent_agenda['date'].year)
else:
expected_value = expected_fmt.format(recent_agenda['date'].year, recent_agenda['date'].year + 1)

assert indexed_data['legislative_session'] == expected_value

# Test indexed value when there are just actions
mock_actions_and_agendas = mocker.PropertyMock(
return_value=[recent_action, older_action]
)

mocker.patch('lametro.models.LAMetroBill.actions_and_agendas', new_callable=mock_actions_and_agendas)

indexed_data = index.prepare(bill)

if month <= 6:
expected_value = expected_fmt.format(recent_action['date'].year - 1, recent_action['date'].year)
else:
expected_value = expected_fmt.format(recent_action['date'].year, recent_action['date'].year + 1)

assert indexed_data['legislative_session'] == expected_value

# Test indexed value when there are neither actions nor agendas
mock_actions_and_agendas = mocker.PropertyMock(
return_value=[]
)

mocker.patch('lametro.models.LAMetroBill.actions_and_agendas', new_callable=mock_actions_and_agendas)

indexed_data = index.prepare(bill)

assert not indexed_data['legislative_session']


def test_sponsorships(bill,
def test_sponsorships(bill,
metro_organization,
event,
event_related_entity,
Expand Down