Skip to content

Commit

Permalink
Update SB test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pkfec committed May 3, 2024
1 parent 499f55d commit 5b8e1f7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 62 deletions.
13 changes: 0 additions & 13 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
82 changes: 63 additions & 19 deletions tests/test_national_party.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import sqlalchemy as sa

from tests import factories
from tests.common import ApiBaseTest
Expand Down Expand Up @@ -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):
[
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 3 additions & 22 deletions webservices/common/models/national_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions webservices/resources/national_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand All @@ -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),
Expand Down

0 comments on commit 5b8e1f7

Please sign in to comment.