-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: structure api error messages #214
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9534dfc
using renderer class tostructure error messages
Geeker1 9c5593c
fixed error response bug on renderer
Geeker1 b082bb5
handle errors raised by django
Geeker1 06f6aaf
handle errors raised by django
Geeker1 4d9f69e
fixed renderer bug
Geeker1 f91ce6b
pushed tests
Geeker1 3272f81
removed non-functional test code, added new tests
Geeker1 7871413
cleaned code and removed comments
Geeker1 8697b7c
replaced renderer with custom exception handler, added unit testing tβ¦
Geeker1 f6fd2af
fixed server error handler, refactored test code
Geeker1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
DJANGO_SECRET_KEY=flkdjsflkdsjflkjlk4j4lk3j4l | ||
DATABASE_URL=postgis://wazimap_ng:wazimap_ng@db:5432/wazimap_ng | ||
DJANGO_DEBUG=True | ||
GDAL_LIBRARY_PATH=/usr/share/gdal | ||
GDAL_LIBRARY_PATH=/usr/share/gdal | ||
REDIS_URL=redis://redis:6379 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from test_plus import APITestCase | ||
|
||
from rest_framework import status | ||
|
||
|
||
class TestErrorResponseData(APITestCase): | ||
|
||
def test_404_error_format(self): | ||
expected_response = { | ||
'error': { | ||
"message": { | ||
"detail": 'Not found.' | ||
}, | ||
'type': 'not_found', | ||
'code': status.HTTP_404_NOT_FOUND | ||
} | ||
} | ||
|
||
response = self.get('dataset-detail', pk=234) | ||
|
||
assert response.data == expected_response | ||
|
||
def test_custom_exception(self): | ||
response = self.get('/api/v1/datasets/3452/') | ||
|
||
assert response.status_code == status.HTTP_404_NOT_FOUND | ||
assert response.data['error']['type'] == 'not_found' |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the correct test for the 404.
thanks. we need a similar one for the 500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During testing, django raises the exception inplace of calling the handler500 function which returns the json response. I wrote the unit test for the handler500 function which is the
test_error_handler_func
, should I write the live server test case for 500 error ?