From 6149d174d3d04e704643103daf2a8c04646c8260 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/args.py | 1 + webservices/common/models/national_party.py | 25 +------ webservices/docs.py | 4 + webservices/resources/national_party.py | 28 ++++--- 6 files changed, 87 insertions(+), 66 deletions(-) diff --git a/tests/factories.py b/tests/factories.py index 2c9729de8..3ebfc0195 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 b386dc332..fa73e3b93 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/args.py b/webservices/args.py index 73de559e9..779bdd05b 100644 --- a/webservices/args.py +++ b/webservices/args.py @@ -1418,6 +1418,7 @@ def make_seek_args(field=fields.Int, description=None): 'recipient_committee_id': fields.List(Committee_ID, description=docs.RECIPIENT_COMMITTEE_ID), 'recipient_name': fields.List(Keyword, description=docs.RECIPIENT_NAME), 'recipient_state': fields.List(IStr, description=docs.RECIPIENT_STATE), + 'recipient_zip': fields.List(IStr, description=docs.RECIPIENT_ZIP), 'spender_committee_designation': fields.List( IStr(validate=validate.OneOf(['', 'A', 'J', 'P', 'U', 'B', 'D'])), description=docs.DESIGNATION, diff --git a/webservices/common/models/national_party.py b/webservices/common/models/national_party.py index 80b9ca5ef..2749b5543 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) @@ -40,13 +39,6 @@ class NationalParty_ScheduleA(db.Model): committee_name = db.Column('cmte_nm', db.String, doc=docs.COMMITTEE_NAME) recipient_committee_type = db.Column('cmte_tp', db.String, doc=docs.COMMITTEE_TYPE) committee_type_full = db.Column(db.String) - conduit_committee_city = db.Column('conduit_cmte_city', db.String) - conduit_committee_id = db.Column('conduit_cmte_id', db.String) - conduit_committee_name = db.Column('conduit_cmte_nm', db.String) - conduit_committee_state = db.Column('conduit_cmte_st', db.String) - conduit_committee_street1 = db.Column('conduit_cmte_st1', db.String) - conduit_committee_street2 = db.Column('conduit_cmte_st2', db.String) - conduit_committee_zip = db.Column('conduit_cmte_zip', db.String) contributor_aggregate_ytd = db.Column('contb_aggregate_ytd', db.Numeric(14, 2)) contribution_receipt_amount = db.Column('contb_receipt_amt', db.Numeric(14, 2)) contribution_receipt_date = db.Column('contb_receipt_dt', db.Date) @@ -90,8 +82,6 @@ class NationalParty_ScheduleA(db.Model): memo_cd_desc = db.Column(db.String) memo_text = db.Column(db.String) national_cmte_nonfed_acct = db.Column(db.String) - recipient_committee_org_type = db.Column('org_tp', db.String) - organization_type_full = db.Column(db.String) orig_sub_id = db.Column(db.Numeric) party = db.Column(db.String) party_account_type = db.Column('party_account', db.String) @@ -114,8 +104,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) @@ -142,14 +131,8 @@ class NationalParty_ScheduleB(db.Model): spender_committee_type = db.Column('cmte_tp', db.String, doc=docs.COMMITTEE_TYPE) committee_type = db.Column(db.String) committee_type_full = db.Column(db.String) - conduit_committee_city = db.Column('conduit_cmte_city', db.String) - conduit_committee_name = db.Column('conduit_cmte_nm', db.String) - conduit_committee_state = db.Column('conduit_cmte_st', db.String) - conduit_committee_street1 = db.Column('conduit_cmte_st1', db.String) - 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) @@ -173,8 +156,6 @@ class NationalParty_ScheduleB(db.Model): memo_cd_desc = db.Column(db.String) memo_text = db.Column(db.String) national_cmte_nonfed_acct = db.Column('national_cmte_nonfed_acct', db.String) - spender_committee_org_type = db.Column('org_tp', db.String) - organization_type_full = db.Column('organization_type', db.String) orig_sub_id = db.Column(db.Numeric) party = db.Column(db.String) party_account = db.Column('party_account', db.String) diff --git a/webservices/docs.py b/webservices/docs.py index 60a4e3a30..6e4d986ca 100644 --- a/webservices/docs.py +++ b/webservices/docs.py @@ -2535,3 +2535,7 @@ def add_ytd(var): MAX_DISBURSEMENT_AMOUNT = ''' Maximum disbursement amount ''' + +RECIPIENT_ZIP = ''' +Zipcode of recipient +''' diff --git a/webservices/resources/national_party.py b/webservices/resources/national_party.py index ac6a02948..cf0159784 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 = [ @@ -127,7 +132,6 @@ class NationalParty_ScheduleBView(ApiResource): ('disbursement_purpose_category', models.NationalParty_ScheduleB.disbursement_purpose_category), ('spender_committee_type', models.NationalParty_ScheduleB.spender_committee_type), - ('spender_committee_org_type', models.NationalParty_ScheduleB.spender_committee_org_type), ('spender_committee_designation', models.NationalParty_ScheduleB.spender_committee_designation), ('two_year_transaction_period', models.NationalParty_ScheduleB.two_year_transaction_period), @@ -160,8 +164,8 @@ def build_query(self, **kwargs): query = super().build_query(**kwargs) query = filters.filter_contributor_type(query, self.model.entity_type, kwargs) zip_list = [] - if kwargs.get('contributor_zip'): - for value in kwargs['contributor_zip']: + if kwargs.get('recipient_zip'): + for value in kwargs['recipient_zip']: if re.search('[^a-zA-Z0-9-\s]', value): # noqa raise exceptions.ApiError( 'Invalid zip code. It can not have special character', @@ -169,9 +173,9 @@ def build_query(self, **kwargs): ) else: zip_list.append(value[:5]) - contributor_zip_list = {'contributor_zip': zip_list} + recipient_zip_list = {'recipient_zip': zip_list} query = filters.filter_multi_start_with( - query, contributor_zip_list, self.filter_multi_start_with_fields + query, recipient_zip_list, self.filter_multi_start_with_fields ) if kwargs.get('line_number'): # line number is a composite value of 'filing_form-line_number'