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

Use full text filter for aggregate resources #3423

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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