diff --git a/tests/factories.py b/tests/factories.py index 45362b600..1430721d0 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -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): diff --git a/tests/test_aggregates.py b/tests/test_aggregates.py index 00a04d170..23d138daa 100644 --- a/tests/test_aggregates.py +++ b/tests/test_aggregates.py @@ -10,6 +10,8 @@ ElectioneeringByCandidateView, ScheduleAByEmployerView, ScheduleAByStateView, + ScheduleBByPurposeView, + ScheduleBByRecipientView, ScheduleEByCandidateView, ) from webservices.resources.candidate_aggregates import ( @@ -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 = [ ( diff --git a/webservices/resources/aggregates.py b/webservices/resources/aggregates.py index 820523b42..542d36ba1 100644 --- a/webservices/resources/aggregates.py +++ b/webservices/resources/aggregates.py @@ -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), ] @@ -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), ] @@ -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), ] @@ -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), ] diff --git a/webservices/schemas.py b/webservices/schemas.py index 5fd05a4c9..9964cded1 100644 --- a/webservices/schemas.py +++ b/webservices/schemas.py @@ -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,