From fba21ff500127789936f7a65c087ec1b68c3ea2a Mon Sep 17 00:00:00 2001 From: Priya Kasireddy Date: Wed, 24 Apr 2024 23:56:55 -0400 Subject: [PATCH] Update SB test case --- tests/factories.py | 13 ---- tests/test_national_party.py | 82 ++++++++++++++++----- webservices/common/models/national_party.py | 8 +- webservices/resources/national_party.py | 19 +++-- 4 files changed, 78 insertions(+), 44 deletions(-) diff --git a/tests/factories.py b/tests/factories.py index 2c9729de82..3ebfc0195f 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -661,14 +661,6 @@ class Meta: report_year = 2024 two_year_transaction_period = 2024 - @factory.post_generation - def update_fulltext(obj, create, extracted, **kwargs): - obj.contributor_name_text = sa.func.to_tsvector(obj.contributor_name) - obj.contributor_employer_text = sa.func.to_tsvector(obj.contributor_employer) - obj.contributor_occupation_text = sa.func.to_tsvector( - obj.contributor_occupation - ) - class NationalParty_ScheduleBFactory(BaseFactory): class Meta: @@ -677,8 +669,3 @@ class Meta: sub_id = factory.Sequence(lambda n: n) report_year = 2024 two_year_transaction_period = 2024 - - @factory.post_generation - def update_fulltext(obj, create, extracted, **kwargs): - obj.disbursement_description_text = sa.func.to_tsvector(obj.disbursement_description_text) - obj.recipient_name_text = sa.func.to_tsvector(obj.recipient_name_text) diff --git a/tests/test_national_party.py b/tests/test_national_party.py index b386dc332e..fa73e3b934 100644 --- a/tests/test_national_party.py +++ b/tests/test_national_party.py @@ -1,4 +1,5 @@ import datetime +import sqlalchemy as sa from tests import factories from tests.common import ApiBaseTest @@ -235,20 +236,38 @@ def test_filter_case_insensitive(self): self.assertEqual(len(results), 1) self.assertEqual(results[0]['contributor_city'], 'NEW YORK') - def test_filter_fulltext(self): - """ - Note: this is the only test for filter_fulltext. - If this is removed, please add a test to test_filters.py - """ - names = ['David Koch', 'George Soros'] + def test_filter_fulltext_contributor_name(self): [ - factories.NationalParty_ScheduleAFactory(contributor_name=name) for name in names + factories.NationalParty_ScheduleAFactory( + contributor_name_text=sa.func.to_tsvector('SOROS, ALEXANDER GEORGE'), + contributor_name='SOROS, ALEXANDER GEORGE'), + factories.NationalParty_ScheduleAFactory( + contributor_name_text=sa.func.to_tsvector('George Soros'), + contributor_name='George Soros'), + factories.NationalParty_ScheduleAFactory( + contributor_name_text=sa.func.to_tsvector('COX, BOBBY D. MR.'), + contributor_name='COX, BOBBY D. MR.'), + factories.NationalParty_ScheduleAFactory( + contributor_name_text=sa.func.to_tsvector('LOQUERCIO, BOB'), + contributor_name='LOQUERCIO, BOB'), + factories.NationalParty_ScheduleAFactory( + contributor_name_text=sa.func.to_tsvector('FLORENTZ, BOBBY'), + contributor_name='FLORENTZ, BOBBY'), ] results = self._results( - api.url_for(NationalParty_ScheduleAView, contributor_name='soros', **self.kwargs) + api.url_for(NationalParty_ScheduleAView, contributor_name='bob', **self.kwargs) ) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['contributor_name'], 'George Soros') + self.assertEqual(len(results), 3) + + results = self._results( + api.url_for(NationalParty_ScheduleAView, contributor_name='george') + ) + self.assertEqual(len(results), 2) + + results = self._results( + api.url_for(NationalParty_ScheduleAView, contributor_name='N/A') + ) + self.assertEqual(len(results), 0) def test_filter_party_account_type(self): [ @@ -384,25 +403,50 @@ def test_multiple_two_year_transaction_period(self): ) self.assertEqual(len(response['results']), 2) + def test_spender_committee_designation_filter(self): + [ + factories.NationalParty_ScheduleBFactory(spender_committee_designation='A'), + factories.NationalParty_ScheduleBFactory(spender_committee_designation='B'), + factories.NationalParty_ScheduleBFactory(spender_committee_designation='B'), + ] + results = self._results( + api.url_for(NationalParty_ScheduleBView, spender_committee_designation='B', **self.kwargs) + ) + self.assertEqual(len(results), 2) + def test_spender_committee_type_filter(self): [ - factories.NationalParty_ScheduleBFactory(spender_committee_type='S'), - factories.NationalParty_ScheduleBFactory(spender_committee_type='S'), - factories.NationalParty_ScheduleBFactory(spender_committee_type='P'), + factories.NationalParty_ScheduleBFactory(spender_committee_type='W'), + factories.NationalParty_ScheduleBFactory(spender_committee_type='W'), + factories.NationalParty_ScheduleBFactory(spender_committee_type='Z'), ] results = self._results( - api.url_for(NationalParty_ScheduleBView, spender_committee_type='S', **self.kwargs) + api.url_for(NationalParty_ScheduleBView, spender_committee_type='W', **self.kwargs) ) self.assertEqual(len(results), 2) - def test_spender_org_type_filter(self): + def test_disbursement_description_filter(self): [ - factories.NationalParty_ScheduleBFactory(spender_committee_org_type='W'), - factories.NationalParty_ScheduleBFactory(spender_committee_org_type='W'), - factories.NationalParty_ScheduleBFactory(spender_committee_org_type='C'), + factories.NationalParty_ScheduleBFactory( + disbursement_description_text=sa.func.to_tsvector('RECOUNT - TRAVEL'), + disbursement_description='RECOUNT - TRAVEL'), + factories.NationalParty_ScheduleBFactory( + disbursement_description_text=sa.func.to_tsvector('LEGAL/RECOUNT TRAVEL'), + disbursement_description='LEGAL/RECOUNT TRAVEL'), + factories.NationalParty_ScheduleBFactory( + disbursement_description_text=sa.func.to_tsvector('LEGAL FEES'), + disbursement_description='LEGAL FEES'), + factories.NationalParty_ScheduleBFactory( + disbursement_description_text=sa.func.to_tsvector('N/A'), + disbursement_description='N/A'), ] results = self._results( - api.url_for(NationalParty_ScheduleBView, spender_committee_org_type='W', **self.kwargs) + api.url_for(NationalParty_ScheduleBView, disbursement_description='N/A', **self.kwargs) + ) + self.assertEqual(len(results), 1) + + results = self._results( + api.url_for(NationalParty_ScheduleBView, disbursement_description='LEGAL') ) self.assertEqual(len(results), 2) diff --git a/webservices/common/models/national_party.py b/webservices/common/models/national_party.py index 80b9ca5ef7..77ec6e46fb 100644 --- a/webservices/common/models/national_party.py +++ b/webservices/common/models/national_party.py @@ -5,8 +5,7 @@ class NationalParty_ScheduleA(db.Model): __table_args__ = {'schema': 'public'} - # __tablename__ = 'ofec_sched_a_national_party_mv' - __tablename__ = 'ofec_sched_a_national_party_mv_tmp_pk' + __tablename__ = 'ofec_sched_a_national_party_mv' amendment_indicator = db.Column('action_cd', db.String) amendment_indicator_desc = db.Column('action_cd_desc', db.String) @@ -114,8 +113,7 @@ class NationalParty_ScheduleA(db.Model): class NationalParty_ScheduleB(db.Model): __table_args__ = {'schema': 'public'} - # __tablename__ = 'ofec_sched_b_national_party_mv' - __tablename__ = 'ofec_sched_b_national_party_mv_tmp_pk' + __tablename__ = 'ofec_sched_b_national_party_mv' amendment_indicator = db.Column('action_cd', db.String) amendment_indicator_desc = db.Column('action_cd_desc', db.String) @@ -149,7 +147,7 @@ class NationalParty_ScheduleB(db.Model): conduit_committee_street2 = db.Column('conduit_cmte_st2', db.String) conduit_committee_zip = db.Column('conduit_cmte_zip', db.String) disbursement_amount = db.Column('disb_amt', db.Numeric, index=True) - disbursement_desc = db.Column('disb_desc', db.String) + disbursement_description = db.Column('disb_desc', db.String) disbursement_date = db.Column('disb_dt', db.Date, index=True) disbursement_type = db.Column('disb_tp', db.String) disbursement_type_desc = db.Column('disb_tp_desc', db.String) diff --git a/webservices/resources/national_party.py b/webservices/resources/national_party.py index ac6a029486..5933be7728 100644 --- a/webservices/resources/national_party.py +++ b/webservices/resources/national_party.py @@ -28,10 +28,13 @@ class NationalParty_ScheduleAView(ApiResource): ('is_individual', models.NationalParty_ScheduleA.is_individual), ] - filter_fulltext_fields = [ - ('contributor_name', models.NationalParty_ScheduleA.contributor_name_text), - ('contributor_employer', models.NationalParty_ScheduleA.contributor_employer_text), - ('contributor_occupation', models.NationalParty_ScheduleA.contributor_occupation_text), + filter_fulltext_fields_NA = [ + ('contributor_name', models.NationalParty_ScheduleA.contributor_name_text, + models.NationalParty_ScheduleA.contributor_name), + ('contributor_employer', models.NationalParty_ScheduleA.contributor_employer_text, + models.NationalParty_ScheduleA.contributor_employer), + ('contributor_occupation', models.NationalParty_ScheduleA.contributor_occupation_text, + models.NationalParty_ScheduleA.contributor_occupation), ] filter_multi_start_with_fields = [ @@ -109,9 +112,11 @@ class NationalParty_ScheduleBView(ApiResource): schema = schemas.NationalPartyScheduleBSchema page_schema = schemas.NationalPartyScheduleBPageSchema - filter_fulltext_fields = [ - ('disbursement_description_text', models.NationalParty_ScheduleB.disbursement_description_text), - ('recipient_name_text', models.NationalParty_ScheduleB.recipient_name_text), + filter_fulltext_fields_NA = [ + ('disbursement_description', models.NationalParty_ScheduleB.disbursement_description_text, + models.NationalParty_ScheduleB.disbursement_description), + ('recipient_name', models.NationalParty_ScheduleB.recipient_name_text, + models.NationalParty_ScheduleB.recipient_name), ] filter_multi_start_with_fields = [