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]Refactor elections endpoint to handle candidate finance totals export function #3292

Merged
merged 3 commits into from
Jul 20, 2018

Conversation

fec-jli
Copy link
Contributor

@fec-jli fec-jli commented Jul 19, 2018

Summary

1)In order to enable 'export' button on these two sections in election summery page, we need refactor elections endpoint to extend ApiResouce and handle download function.
These two sections use same endpoint: resource.ElectionView
a)Candidate financial totals section:
https://www.fec.gov/data/elections/senate/VA/2018/?tab=election-data

b)Candidate information section:
https://www.fec.gov/data/elections/senate/VA/2018/?tab=about-election

Include a summary of proposed changes

fec-cms need to be changed to enable the button and make event trigger work.

How to test the changes locally

1)setup openFEC locally
check out openFEC feature branch: feature/refactor_elections_endpoint

set some variables:
export SQLA_CONN=dev
export access_key_id=
export secret_access_key=
export bucket=
export region=

  1. setup fec-cms locally
    checkout fec-cms feature branch: feature/enable_cft_export_button
    and point to your local api:
    export FEC_WEB_API_KEY_PUBLIC=xxxxxxx
    export FEC_WEB_API_KEY=xxxxxxx
    export FEC_CMS_ENVIRONMENT=LOCAL
    export FEC_API_URL=http://localhost:5000
    export DATABASE_URL=postgresql://:@/cfdm_cms_test

3)start redis-server
redis-server

4)Setup Celery Worker and start
export SQLA_CONN=xxxxxxx
export access_key_id=
export secret_access_key=
export bucket=
export region=
celery worker --app webservices.tasks --loglevel INFO

5)test:
example1 url: http://127.0.0.1:8000/data/elections/senate/VA/2018/?tab=election-data
Click "Export" on Candidate financial totals section, download the file.
screen shot 2018-07-19 at 10 36 00 am

example2 url http://127.0.0.1:8000/data/elections/senate/VA/2018/?tab=about-election
Click "Export" on Candidate information section, download the file.
screen shot 2018-07-19 at 10 36 20 am

Refactor ElectionView to enable candidate finance totals(CFT) export function.
@@ -143,8 +143,8 @@ def test_download_cached(self, export, get_cached):
assert not export.delay.called

def test_download_forbidden(self):
with pytest.raises(ApiError):
self.client.post_json(api.url_for(resource.DownloadView, path='elections', office='house', cycle=2018))
response = self.app.get(api.url_for(resource.DownloadView, path='elections', office='house', cycle=2018))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unclear about what this test is trying to accomplish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear either, Can we remove this test case function? Thanks @vrajmohan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another view that does not support downloads that can be used for this test instead?

Copy link
Contributor Author

@fec-jli fec-jli Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question. I look at most of our endpoints, we do have some endpoints don't support download, but they are not added into this test_download_forbidden function.
How about change function name to donttest_download_forbidden for now? in case, we need test other endpoints in the future? Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand "they are not added into this test_download_forbidden function". Why can't we use one of those paths instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I add '/elections/search' (resource.ElectionListView) endpoint into test_download_forbidden function. work well. Thanks.

self.assertEqual(len(results), 0)

response = self.app.get(api.url_for(ElectionView, office='senate', cycle=2012, state='ZZ', per_page=0))
self.assertEquals(response.status_code, 422)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unclear about what this test is trying to accomplish.

query = self._get_records(kwargs)
return utils.fetch_page(query, kwargs, cap=0)
return query

def _get_records(self, kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just rename this to build_query with the right signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. will do. Thanks

Fix 'empty query' test case.
Add space to pass PEP 8.
@fec-jli fec-jli force-pushed the feature/refactor_elections_endpoint branch from 22ed3be to 7b19e6b Compare July 19, 2018 23:45
@codecov-io
Copy link

codecov-io commented Jul 19, 2018

Codecov Report

Merging #3292 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3292   +/-   ##
========================================
  Coverage    87.72%   87.72%           
========================================
  Files           75       75           
  Lines         6159     6159           
========================================
  Hits          5403     5403           
  Misses         756      756
Impacted Files Coverage Δ
webservices/resources/elections.py 99.08% <100%> (-0.02%) ⬇️
webservices/schemas.py 86.3% <100%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f1936d...65c78a7. Read the comment docs.

'elections/search' (resource.ElectionListView) don't support download function for now.
@vrajmohan vrajmohan merged commit b2dd4c2 into develop Jul 20, 2018
@vrajmohan vrajmohan deleted the feature/refactor_elections_endpoint branch July 20, 2018 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants