BrowsableAPIRenderer, Testing and 204 No Content #9423
Unanswered
josepdecid
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have encountered a problem testing an endpoint that should return a
204
status.After some debugging, I found that the problem comes from the DRF renderer classes. With the renderer
BrowsableAPIRenderer
, it renders the API page where you can see that the response status is HTTP204
as it should be. However, testing that endpoint it returns a200
. I've tried with Postman and it produces the same response, a200
instead of204
(Check the screenshot below).The solution was quite simple, I had the
BrowsableAPIRenderer
before theJSONRenderer
so it was just a matter of changing the order:However, this brings me to the two questions/doubts/thoughts I have:
1 - I think it is an error that the
BrowsableAPIRenderer
returns200
when the status is204
. Sure, the response is not empty because it returns the HTML and a204
is not semantically correct, but in my opinion it should be consistent, more so when in the rest of the status it works as expected. I've tried to replicate the same with all other20X
status codes but it seems that204
is the only one that is causing issues. I have also tried with the40X
and no problems either (haven't tried all status codes but I expect that all the others work properly).2 - I find it odd that someone would want to test the result of the
BrowsableAPIRenderer
and not the JSON itself. I think the tests could default to using theJSONRenderer
and always have the option to change it if required (this one is perhaps a bit more controversial).Any thoughts on my 2 takes? Especially the first one.
I'm open to opening an issue if we end up considering that if it is a problem, and I could look into fixing it myself if need be.
Beta Was this translation helpful? Give feedback.
All reactions