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 2, 2024
1 parent 499f55d commit 9ed935f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 46 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)
84 changes: 64 additions & 20 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,28 +403,53 @@ def test_multiple_two_year_transaction_period(self):
)
self.assertEqual(len(response['results']), 2)

def test_spender_committee_type_filter(self):
def test_spender_committee_designation_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_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_type='S', **self.kwargs)
api.url_for(NationalParty_ScheduleBView, spender_committee_designation='B', **self.kwargs)
)
self.assertEqual(len(results), 2)

def test_spender_org_type_filter(self):
def test_spender_committee_type_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(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_org_type='W', **self.kwargs)
api.url_for(NationalParty_ScheduleBView, spender_committee_type='W', **self.kwargs)
)
self.assertEqual(len(results), 2)

def test_disbursement_description_filter(self):
[
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('RECOUNT LEGAL SVCS'),
disbursement_description='RECOUNT LEGAL SVCS'),
]
results = self._results(
api.url_for(NationalParty_ScheduleBView, disbursement_description='N/A', **self.kwargs)
)
self.assertEqual(len(results), 0)

results = self._results(
api.url_for(NationalParty_ScheduleBView, disbursement_description='LEGAL')
)
self.assertEqual(len(results), 3)

def test_line_number(self):
[
factories.NationalParty_ScheduleBFactory(line_number='21b', filing_form='F3X'),
Expand Down
8 changes: 3 additions & 5 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 @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 12 additions & 7 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 Down
2 changes: 1 addition & 1 deletion webservices/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def sqla_conn_string():
]
app.config['PROPAGATE_EXCEPTIONS'] = True

# app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_ECHO'] = True

# Modify app configuration and logging level for production
if not app.debug:
Expand Down

0 comments on commit 9ed935f

Please sign in to comment.