|
13 | 13 | import django.test |
14 | 14 | from django.test.utils import override_settings |
15 | 15 | from unittest import mock |
| 16 | +from django.http import HttpResponse |
16 | 17 |
|
17 | 18 | from django_declarative_apis.authentication.oauthlib import oauth_errors |
18 | 19 | from django_declarative_apis.resources import resource |
@@ -212,3 +213,23 @@ def test_email_exception(self): |
212 | 213 | (subj, body, _, __), ___ = mock_email.call_args_list[0] |
213 | 214 | self.assertEqual(subj, "[Django] Django Declarative APIs crash report") |
214 | 215 | self.assertEqual(body, traceback) |
| 216 | + |
| 217 | + def test_call_no_content_response(self): |
| 218 | + """Test that HTTP 204 responses return empty content with content-length 0""" |
| 219 | + |
| 220 | + def handle_delete(request, *args, **kwargs): |
| 221 | + # Handler returns an HttpResponse with 204 status as the result |
| 222 | + return http.HTTPStatus.OK, HttpResponse(status=http.HTTPStatus.NO_CONTENT) |
| 223 | + |
| 224 | + class Handler: |
| 225 | + allowed_methods = ("DELETE",) |
| 226 | + method_handlers = {"DELETE": handle_delete} |
| 227 | + |
| 228 | + req = self.create_request(method="DELETE") |
| 229 | + res = resource.Resource(lambda: Handler()) |
| 230 | + resp = res(req) |
| 231 | + |
| 232 | + # Verify the response has 204 status and empty content |
| 233 | + self.assertEqual(resp.status_code, http.HTTPStatus.NO_CONTENT) |
| 234 | + self.assertEqual(resp.content, b"") |
| 235 | + self.assertEqual(len(resp.content), 0) |
0 commit comments