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

Add validation to sorting option #5509

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

hcaofec
Copy link
Contributor

@hcaofec hcaofec commented Jul 24, 2023

Summary (required)

Limit sortable fields to: ['election_year', 'cycle', 'state', 'office']. Add validation to sortable fields, and set status code to 422 when invalid sorting field is selected.

Required reviewers

1 developer

How to test

  • Download feature branch and run pytest
  • run flask run to start api on local and test these endpoints:

sort = -test
http://127.0.0.1:5000/v1/candidates/totals/?page=1&per_page=20&election_full=true&sort=-test&sort_hide_null=false&sort_null_only=false&sort_nulls_last=false

sort = -election_year
http://127.0.0.1:5000/v1/candidates/totals/?page=1&per_page=20&election_full=true&sort=-election_year&sort_hide_null=false&sort_null_only=false&sort_nulls_last=false

@hcaofec hcaofec changed the title [WIP] Add validation for sorting option [WIP] Add validation to sorting Jul 27, 2023
@hcaofec hcaofec changed the title [WIP] Add validation to sorting Add validation to sorting Jul 27, 2023
@hcaofec hcaofec requested a review from pkfec July 27, 2023 13:43
@hcaofec hcaofec changed the title Add validation to sorting Add validation to sorting option Jul 27, 2023
@pkfec
Copy link
Contributor

pkfec commented Jul 27, 2023

@hcaofec The following endpoints are throwing 422 error. Could you include Party, State, District, Name, Receipts and Disbursements columns as sortable fields?

Presidential Candidates:
http://localhost:8000/data/candidates/president/?election_year=2008&cycle=2008&election_full=true

Senate candidates:
http://localhost:8000/data/candidates/senate/?election_year=2024&cycle=2024&election_full=true&is_active_candidate=true

House of representatives:
http://localhost:8000/data/candidates/house/?election_year=2024&election_full=True&is_active_candidate=true

@hcaofec hcaofec force-pushed the feature/5479-status-code-for-invalid-sort-option branch from 276b775 to 7132dc9 Compare July 31, 2023 20:12
@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

Merging #5509 (7132dc9) into develop (183205d) will increase coverage by 0.00%.
Report is 2 commits behind head on develop.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #5509   +/-   ##
========================================
  Coverage    85.50%   85.50%           
========================================
  Files           81       81           
  Lines         8173     8174    +1     
========================================
+ Hits          6988     6989    +1     
  Misses        1185     1185           
Files Changed Coverage Δ
webservices/resources/candidate_aggregates.py 96.96% <100.00%> (+0.02%) ⬆️

Copy link
Contributor

@pkfec pkfec left a comment

Choose a reason for hiding this comment

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

LGTM @hcaofec

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.

Bug - invalid sort option in /candidates/totals/ throws 500 error when it should be 422 error
2 participants