Skip to content

Commit

Permalink
Merge pull request #3423 from fecgov/feature/fix-aggregate-filters
Browse files Browse the repository at this point in the history
Use full text filter for aggregate resources
  • Loading branch information
pkfec authored Oct 12, 2018
2 parents d1ff96f + a895bbf commit fe37a74
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ class Meta:
class ScheduleBByPurposeFactory(BaseAggregateFactory):
class Meta:
model = models.ScheduleBByPurpose
purpose = 'ADMINISTRATIVE'

class ScheduleBByRecipientFactory(BaseAggregateFactory):
class Meta:
model = models.ScheduleBByRecipient


class ScheduleEByCandidateFactory(BaseAggregateFactory):
Expand Down
55 changes: 55 additions & 0 deletions tests/test_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
ElectioneeringByCandidateView,
ScheduleAByEmployerView,
ScheduleAByStateView,
ScheduleBByPurposeView,
ScheduleBByRecipientView,
ScheduleEByCandidateView,
)
from webservices.resources.candidate_aggregates import (
Expand Down Expand Up @@ -86,6 +88,59 @@ def test_by_state(self):
)
assert len(results) == 1

def test_disbursement_purpose(self):
committee = factories.CommitteeHistoryFactory(cycle=2012)

aggregate = factories.ScheduleBByPurposeFactory(
committee_id=committee.committee_id,
cycle=committee.cycle,
purpose='ADMINISTRATIVE EXPENSES'
)
results = self._results(
api.url_for(
ScheduleBByPurposeView,
committee_id=committee.committee_id,
cycle=2012,
purpose='Administrative'
)
)
self.assertEqual(len(results), 1)
expected = {
'committee_id': committee.committee_id,
'purpose': 'ADMINISTRATIVE EXPENSES',
'cycle': 2012,
'total': aggregate.total,
'count': aggregate.count,
}
self.assertEqual(results[0], expected)

def test_disbursement_recipient(self):
committee = factories.CommitteeHistoryFactory(cycle=2012)

aggregate = factories.ScheduleBByRecipientFactory(
committee_id=committee.committee_id,
cycle=committee.cycle,
recipient_name='STARBOARD STRATEGIES, INC.'
)
results = self._results(
api.url_for(
ScheduleBByRecipientView,
committee_id=committee.committee_id,
cycle=2012,
recipient_name='Starboard Strategies'
)
)
self.assertEqual(len(results), 1)
expected = {
'committee_id': committee.committee_id,
'recipient_name': 'STARBOARD STRATEGIES, INC.',
'cycle': 2012,
'total': aggregate.total,
'count': aggregate.count,
}
self.assertEqual(results[0], expected)


class TestAggregates(ApiBaseTest):
cases = [
(
Expand Down
8 changes: 8 additions & 0 deletions webservices/resources/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class ScheduleAByEmployerView(AggregateResource):
query_args = args.schedule_a_by_employer
filter_multi_fields = [
('cycle', models.ScheduleAByEmployer.cycle),
]
filter_fulltext_fields = [
('employer', models.ScheduleAByEmployer.employer),
]

Expand All @@ -148,6 +150,8 @@ class ScheduleAByOccupationView(AggregateResource):
query_args = args.schedule_a_by_occupation
filter_multi_fields = [
('cycle', models.ScheduleAByOccupation.cycle),
]
filter_fulltext_fields = [
('occupation', models.ScheduleAByOccupation.occupation),
]

Expand All @@ -172,6 +176,8 @@ class ScheduleBByRecipientView(AggregateResource):
query_args = args.schedule_b_by_recipient
filter_multi_fields = [
('cycle', models.ScheduleBByRecipient.cycle),
]
filter_fulltext_fields = [
('recipient_name', models.ScheduleBByRecipient.recipient_name),
]

Expand Down Expand Up @@ -213,6 +219,8 @@ class ScheduleBByPurposeView(AggregateResource):
query_args = args.schedule_b_by_purpose
filter_multi_fields = [
('cycle', models.ScheduleBByPurpose.cycle),
]
filter_fulltext_fields = [
('purpose', models.ScheduleBByPurpose.purpose),
]

Expand Down
2 changes: 1 addition & 1 deletion webservices/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def augment_itemized_aggregate_models(factory, committee_model, *models, namespa
schema = factory(
model,
options={
'exclude': ('committee',),
'exclude': ('idx', 'committee',),
'relationships': [
Relationship(
model.committee,
Expand Down

0 comments on commit fe37a74

Please sign in to comment.