Skip to content

Commit

Permalink
Revert "Merge pull request #616 from datamade/patch/hcg/revert-bill-f…
Browse files Browse the repository at this point in the history
…ilter"

This reverts commit 97aed9a, reversing
changes made to 8c3961e.
  • Loading branch information
hancush committed May 13, 2020
1 parent 97aed9a commit 84fac15
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
21 changes: 15 additions & 6 deletions lametro/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ def get_queryset(self):
N.b., the scrapers contain logic for populating the restrict_view field:
https://github.com/opencivicdata/scrapers-us-municipal/blob/master/lametro/bills.py
(2) Does the Bill have a classification of "Board Box"? Then, show it.
(2) Does the Bill have a classification of "Board Box" or "Board
Correspondence"? Then, show it.
(3) Is the Bill on a published agenda, i.e., an event with the
status of "passed" or "cancelled"? Then, show it.
NOTE! A single bill can appear on multiple event agendas.
We thus call 'distinct' on the below query, otherwise
the queryset would contain duplicate bills.
(4) Sometimes motions are made during meetings that were not submitted
in advance, i.e., they do not appear on the published agenda. They will
be entered as matter history, which we translate to bill actions. Does
the bill have any associated actions? Then, show it.
https://github.com/datamade/la-metro-councilmatic/issues/477
NOTE! A single bill can appear on multiple event agendas. We thus call
'distinct' on the below query, otherwise the queryset would contain
duplicate bills.
WARNING! Be sure to use LAMetroBill, rather than the base Bill class,
when getting bill querysets. Otherwise restricted view bills
Expand All @@ -68,13 +75,15 @@ def get_queryset(self):
qs = qs.exclude(
extras__restrict_view=True
).annotate(board_box=Case(
When(extras__local_classification='Board Box', then=True),
When(extras__local_classification__in=('Board Box', 'Board Correspondence'), then=True),
When(classification__contains=['Board Box'], then=True),
When(classification__contains=['Board Correspondence'], then=True),
default=False,
output_field=models.BooleanField()
)).filter(Q(eventrelatedentity__agenda_item__event__status='passed') | \
Q(eventrelatedentity__agenda_item__event__status='cancelled') | \
Q(board_box=True)
Q(board_box=True) | \
Q(actions__isnull=False)
).distinct()

return qs
Expand Down
26 changes: 25 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
EventRelatedEntity,
)
from opencivicdata.core.models import Jurisdiction, Division
from opencivicdata.legislative.models import EventDocument
from opencivicdata.legislative.models import EventDocument, BillAction
from councilmatic_core.models import Bill, Membership
from lametro.models import LAMetroPerson, LAMetroEvent, LAMetroBill, \
LAMetroOrganization, LAMetroSubject
Expand Down Expand Up @@ -52,6 +52,30 @@ def build(self, **kwargs):

return BillFactory()


@pytest.fixture
@pytest.mark.django_db
def bill_action(db, bill, metro_organization):
class BillActionFactory():
def build(self, **kwargs):
bill_action_info = {
'organization': metro_organization.build(),
'description': 'test action',
'date': '2019-11-09',
'order': 999,
}

bill_action_info.update(kwargs)

if not bill_action_info.get('bill'):
bill_action_info['bill'] = bill.build()

bill_action = BillAction.objects.create(**bill_action_info)

return bill_action

return BillActionFactory()

@pytest.fixture
@pytest.mark.django_db
def division(db):
Expand Down
20 changes: 14 additions & 6 deletions tests/test_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,23 @@ def test_format_full_text(bill, text, subject):

assert format_full_text(full_text) == subject

@pytest.mark.parametrize('restrict_view,bill_type,event_status,is_public', [
(True, 'Board Box', 'passed', False),
(False, 'Board Box', 'passed', True),
(False, 'Resolution', 'passed', True),
(False, 'Resolution', 'cancelled', True),
(False, 'Resolution', 'confirmed', False),
@pytest.mark.parametrize('restrict_view,bill_type,event_status,has_action,is_public', [
(True, 'Board Box', 'passed', False, False), # private bill
(False, 'Board Box', 'passed', False, True), # board box
(False, 'Board Correspondence', 'passed', False, True), # board correspondence
(False, 'Resolution', 'passed', False, True), # on published agenda
(False, 'Resolution', 'cancelled', False, True), # on published agenda
(False, 'Resolution', 'confirmed', False, False), # not on published agenda
(False, 'Resolution', 'passed', True, True), # has matter history
(False, 'Test', 'test', False, False), # not private, but does not meet conditions for display
])
def test_bill_manager(bill,
bill_action,
event_related_entity,
restrict_view,
bill_type,
event_status,
has_action,
is_public):
'''
Tests if the LAMetroBillManager properly filters public and private bills.
Expand All @@ -92,6 +97,9 @@ def test_bill_manager(bill,

some_bill = bill.build(**bill_info)

if has_action:
bill_action.build(bill=some_bill)

event_related_entity_info = {
'bill': some_bill,
}
Expand Down

0 comments on commit 84fac15

Please sign in to comment.