Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] upgrade flask #5508

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ static/swagger-ui/js
.pytest_cache/

# Pycharm
.idea
.idea
.vscode/launch.json
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apispec==0.39.0
apispec==4.0.0
certifi==2022.12.7
cfenv==0.5.2
defusedxml==0.6.0
elasticsearch==7.6.0
elasticsearch-dsl==7.3.0
Flask==2.1.2
Flask==2.2.5
Flask-Cors==3.0.10
Flask-RESTful==0.3.9
Flask-SQLAlchemy==2.5.1
Expand All @@ -19,20 +19,20 @@ prance[osv]==0.22.11.4.0
psycopg2-binary==2.9.1
python-dateutil==2.8.1
python-dotenv>=0.20.0 # Sets variable defaults in .flaskenv file
requests==2.31.0
requests-aws4auth==1.2.3
requests==2.25.1
requests-aws4auth==1.0
sqlalchemy-postgres-copy==0.3.0
SQLAlchemy==1.3.19
ujson==5.4.0 # decoding CSP violation reported
vine==5.0.0 # previosly pinned to 1.3.0 to fix amqp dependency, which is a dependency of kombu
webargs==5.5.3
webargs==7.0.0
werkzeug==2.2.3

# Marshalling
flask-apispec==0.7.0
git+https://github.com/fecgov/marshmallow-pagination@master
marshmallow==2.16.3
marshmallow-sqlalchemy==0.15.0
flask-apispec==0.11.4
git+https://github.com/fecgov/marshmallow-pagination@feature/upgrade-marshmallow
marshmallow==3.0.0
marshmallow-sqlalchemy==0.23.1

# Data export
smart_open==1.8.0
Expand Down
22 changes: 18 additions & 4 deletions tests/integration/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,33 @@ def test_candidate_counts_house(self):
)
)
results_tab = self.connection.execute(sql_extract).fetchall()
params = {
candidate_params = {
'election_year': election_year,
'cycle': election_year,
'district': '01',
'state': 'MD',
}

election_params = {
'cycle': election_year,
'election_full': True,
'district': '01',
'state': 'MD',
}

total_params = {
'cycle': election_year,
'election_full': True,
'district': '01',
'state': 'MD',
'election_year': election_year,
}
candidates_api = self._results(rest.api.url_for(CandidateList, **params))
candidates_api = self._results(rest.api.url_for(CandidateList, **candidate_params))
candidates_totals_api = self._results(
rest.api.url_for(TotalsCandidateView, **params)
rest.api.url_for(TotalsCandidateView, **total_params)
)
elections_api = self._results(
rest.api.url_for(ElectionView, office='house', **params)
rest.api.url_for(ElectionView, office='house', **election_params)
)
assert (
len(results_tab)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_tsvector_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,12 @@ def test_accent_insensitive_sched_b(self):
connection.execute(insert, data)
manage.refresh_materialized(concurrent=False)
results = self._results(
api.url_for(ScheduleBView, contributor_employer='ést-lou')
api.url_for(ScheduleBView, recipient_name='ést-lou')
)
contbr_employer_list = {r['recipient_name'] for r in results}
assert names.issubset(contbr_employer_list)
results = self._results(
api.url_for(ScheduleBView, contributor_employer='est lou')
api.url_for(ScheduleBView, recipient_name='est lou')
)
contbr_employer_list = {r['recipient_name'] for r in results}
assert names.issubset(contbr_employer_list)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_candidate_aggregates_by_committee(self):
)
)
assert len(results) == 1
serialized = schema().dump(aggregates[0]).data
serialized = schema().dump(aggregates[0])
serialized.update(
{
'committee_name': self.committee.name,
Expand All @@ -278,14 +278,13 @@ def test_candidate_aggregates_by_committee_full(self):
api.url_for(
resource,
candidate_id=self.candidate.candidate_id,
committee_id=self.committee.committee_id,
cycle=2012,
office='president',
election_full='true',
)
)
assert len(results) == 1
serialized = schema().dump(aggregates[0]).data
serialized = schema().dump(aggregates[0])
serialized.update(
{
'committee_name': self.committee.name,
Expand Down
31 changes: 14 additions & 17 deletions tests/test_committees.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def test_committee_sort(self):

def test_first_f1_date_sort(self):
committees = [
factories.CommitteeFactory(first_f1_date="2003-10-12"),
factories.CommitteeFactory(first_f1_date="2017-05-14"),
factories.CommitteeFactory(first_f1_date=datetime.date.fromisoformat("2003-10-12")),
factories.CommitteeFactory(first_f1_date=datetime.date.fromisoformat("2017-05-14")),
]
committee_ids = [each.committee_id for each in committees]
results = self._results(api.url_for(CommitteeList, sort="first_f1_date"))
Expand Down Expand Up @@ -386,13 +386,12 @@ def _test_committee_date_filters(self, date_field, values, min_date_field, max_d
for each in results
)
)
results = self._results(
api.url_for(
CommitteeList,
**{min_date_field: datetime.date.fromisoformat(values[1]),
max_date_field: datetime.date.fromisoformat(values[2])}
)
)
results = self._results(api.url_for(
CommitteeList,
**{min_date_field: datetime.date.fromisoformat(values[1]),
max_date_field: datetime.date.fromisoformat(values[2])}
)
)
self.assertTrue(
all(
datetime.date.fromisoformat(values[1]).isoformat()
Expand Down Expand Up @@ -614,22 +613,22 @@ def test_is_active(self):
CommitteeHistoryProfileView,
committee_id=self.committees[4].committee_id,
cycle=2014,
election_full=False,
is_active=False,
election_full=False
)
)
assert len(results) == 1
self.assertFalse(results[0]["is_active"])

results = self._results(
api.url_for(
CommitteeHistoryProfileView,
committee_id=self.committees[2].committee_id,
cycle=2014,
election_full=False,
is_active=True,
election_full=False
)
)
assert len(results) == 1
self.assertTrue(results[0]["is_active"])

def test_candidate_cycle(self):
results = self._results(
Expand Down Expand Up @@ -739,8 +738,7 @@ def test_case_insensitivity(self):
CommitteeHistoryProfileView,
committee_id="id01",
cycle=2014,
election_full=False,
is_active=False,
election_full=False
)
)
assert len(results) == 1
Expand All @@ -750,8 +748,7 @@ def test_case_insensitivity(self):
CommitteeHistoryProfileView,
candidate_id="h01",
cycle=2014,
election_full=False,
is_active=False,
election_full=False
)
)
assert len(results) == 1
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_reporting_dates_filters(self):
factories.ReportDateFactory(update_date=datetime.datetime(2014, 4, 2))

filter_fields = (
('due_date', '2014-01-02'),
('min_due_date', '2014-01-02'),
('report_year', 2015),
('report_type', 'YE'),
('min_create_date', '2014-03-02'),
Expand Down
29 changes: 13 additions & 16 deletions tests/test_itemized.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ def test_schedule_a_null_pagination_with_null_sort_column_values_descending(self
api.url_for(
ScheduleAView,
sort='-contribution_receipt_date',
sort_reverse_nulls='true',
**self.kwargs
)
)
Expand Down Expand Up @@ -681,7 +680,6 @@ def test_schedule_a_null_pagination_with_null_sort_column_values_ascending(self)
api.url_for(
ScheduleAView,
sort='contribution_receipt_date',
sort_reverse_nulls='true',
**self.kwargs
)
)
Expand Down Expand Up @@ -969,7 +967,6 @@ def test_schedule_b_sort_ignores_nulls_last_parameter(self):
api.url_for(
ScheduleBView,
sort='-disbursement_date',
sort_nulls_last=True,
**self.kwargs
)
)
Expand Down Expand Up @@ -1151,15 +1148,15 @@ def test_filter_sched_e_spender_name_text(self):
),
]
results = self._results(
api.url_for(ScheduleEView, q_spender='action', **self.kwargs)
api.url_for(ScheduleEView, q_spender='action')
)
self.assertEqual(len(results), 2)
results = self._results(
api.url_for(ScheduleEView, q_spender='abc', **self.kwargs)
api.url_for(ScheduleEView, q_spender='abc')
)
self.assertEqual(len(results), 1)
results = self._results(
api.url_for(ScheduleEView, q_spender='C001', **self.kwargs)
api.url_for(ScheduleEView, q_spender='C001')
)
self.assertEqual(len(results), 1)

Expand Down Expand Up @@ -1196,7 +1193,7 @@ def test_schedule_e_sort_args_descending(self):
def test_schedule_e_expenditure_description_field(self):
factories.ScheduleEFactory(committee_id='C001', expenditure_description='Advertising Costs')
results = self._results(
api.url_for(ScheduleEView, **self.kwargs)
api.url_for(ScheduleEView)
)
self.assertEqual(len(results), 1)
self.assertEqual(results[0]['expenditure_description'], 'Advertising Costs')
Expand Down Expand Up @@ -1322,7 +1319,7 @@ def test_filter_sched_e_most_recent(self):
factories.ScheduleEFactory(committee_id='C006', filing_form='F3X'),
]
results = self._results(
api.url_for(ScheduleEView, most_recent=True, **self.kwargs)
api.url_for(ScheduleEView, most_recent=True)
)
# Most recent should include null values
self.assertEqual(len(results), 5)
Expand All @@ -1347,7 +1344,7 @@ def test_filter_sched_e_efile_most_recent(self):
factories.EFilingsFactory(file_number=123)
db.session.flush()
results = self._results(
api.url_for(ScheduleEEfileView, most_recent=True, **self.kwargs)
api.url_for(ScheduleEEfileView, most_recent=True)
)
# Most recent should include null values
self.assertEqual(len(results), 5)
Expand Down Expand Up @@ -1396,21 +1393,21 @@ def test_schedule_h4_filter_fulltext_purpose_and(self):
for purpose in purposes
]
results = self._results(
api.url_for(ScheduleH4View, disbursement_purpose='Test&Test', **self.kwargs)
api.url_for(ScheduleH4View, q_disbursement_purpose='Test&Test')
)
self.assertIn(results[0]['disbursement_purpose'], purposes)
results = self._results(
api.url_for(
ScheduleH4View, disbursement_purpose='Test & Test', **self.kwargs
ScheduleH4View, q_disbursement_purpose='Test & Test'
)
)
self.assertIn(results[0]['disbursement_purpose'], purposes)
results = self._results(
api.url_for(ScheduleH4View, disbursement_purpose='Test& Test', **self.kwargs)
api.url_for(ScheduleH4View, q_disbursement_purpose='Test& Test')
)
self.assertIn(results[0]['disbursement_purpose'], purposes)
results = self._results(
api.url_for(ScheduleH4View, disbursement_purpose='Test &Test', **self.kwargs)
api.url_for(ScheduleH4View, q_disbursement_purpose='Test &Test')
)
self.assertIn(results[0]['disbursement_purpose'], purposes)

Expand All @@ -1420,12 +1417,12 @@ def test_schedule_h4_filter_payee_name_text_pass(self):
'Test com',
'Testerosa',
'Test#com',
'Not.com',
'Not.com', # this should not be a result
'Test.com and Test.com',
]
[factories.ScheduleH4Factory(payee_name=payee) for payee in payee_names]
results = self._results(api.url_for(ScheduleH4View, payee_name='test'))
self.assertEqual(len(results), len(payee_names))
results = self._results(api.url_for(ScheduleH4View, q_payee_name='test'))
self.assertEqual(len(results), 5)

def test_schedule_h4_efile_event_purpose_date_range(self):

Expand Down
2 changes: 0 additions & 2 deletions tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ def test_efile_presidential_reports(self):
results = self._results(
api.url_for(
EFilingPresidentialSummaryView,
entity_type='presidential',
committee_id=committee_id,
)
)
Expand Down Expand Up @@ -463,7 +462,6 @@ def test_efile_house_senate_reports(self):
results = self._results(
api.url_for(
EFilingHouseSenateSummaryView,
entity_type='house-senate',
committee_id=committee_id,
)
)
Expand Down
Loading