fix(elections): return 200 with empty list when no elections exist - #190
Closed
HarshRajSinghania wants to merge 2 commits into
Closed
HarshRajSinghania wants to merge 2 commits into
HarshRajSinghania wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #189.
Summary
GET /api/electionandGET /api/election?with_nominees=truereturned HTTP 404 when the elections table was empty. An empty collection is a valid result, so the endpoint now returns200with[].A 404 is still used for
GET /api/election/{name}when a specific election slug does not exist.Motivation
Issue #189: returning 404 when there are no rows is semantically incorrect and makes it look like the route or table is missing.
Implementation
list_elections(src/elections/urls.py).[].Testing
Unit tests added:
tests/unit/test_elections.py::test__list_elections_returns_empty_list_when_none_existtests/unit/test_elections.py::test__list_elections_with_nominees_returns_empty_list_when_none_existThese tests call
list_electionsdirectly with mocked CRUD and do not require a database. Existing integration tests for non-empty lists were not changed.I did not run the full integration suite here because it needs the project's Postgres test database.