{{{
def test_head(client):
response = client.head('/packages/core/x86_64/linux/')
assert response.status_code == 200
}}}
{{{
client = <django.test.client.Client object at 0x7ffb428281d0>, package =
None
def test_head(client, package):
print(client)
> response = client.head('/packages/core/x86_64/linux/')
packages/tests/test_views.py:114:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
env/lib/python3.11/site-packages/django/test/client.py:975: in head
response = super().head(
env/lib/python3.11/site-packages/django/test/client.py:495: in head
return self.generic(
env/lib/python3.11/site-packages/django/test/client.py:609: in generic
return self.request(**r)
env/lib/python3.11/site-packages/django/test/client.py:886: in request
response = self.handler(environ)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <django.test.client.ClientHandler object at 0x7ffb427cae50>
environ = {'HTTP_COOKIE': '', 'PATH_INFO': '/packages/core/x86_64/linux/',
'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', ...}
def __call__(self, environ):
# Set up middleware if needed. We couldn't do this earlier,
because
# settings weren't available.
if self._middleware_chain is None:
self.load_middleware()
request_started.disconnect(close_old_connections)
request_started.send(sender=self.__class__, environ=environ)
request_started.connect(close_old_connections)
request = WSGIRequest(environ)
# sneaky little hack so that we can easily get round
# CsrfViewMiddleware. This makes life easier, and is probably
# required for backwards compatibility with external tests against
# admin views.
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
# Request goes through middleware.
response = self.get_response(request)
# Simulate behaviors of most web servers.
conditional_content_removal(request, response)
# Attach the originating request to the response so that it could
be
# later retrieved.
response.wsgi_request = request
# Emulate a WSGI server by calling the close method on completion.
if response.streaming:
> if response.is_async:
E AttributeError: 'HttpResponse' object has no attribute
'is_async'
env/lib/python3.11/site-packages/django/test/client.py:187: AttributeError
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34902>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => worksforme
* component: Uncategorized => Testing framework
Comment:
Thanks for the report, however the following works for me with Django
4.2.6:
{{{#!diff
diff --git a/tests/handlers/tests.py b/tests/handlers/tests.py
index 0348b8e5d6..6bfa852db5 100644
--- a/tests/handlers/tests.py
+++ b/tests/handlers/tests.py
@@ -253,6 +253,10 @@ class HandlerRequestTests(SimpleTestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(b"".join(list(response)), b"streaming content")
+ def test_head_streaming(self):
+ response = self.client.head("/streaming/")
+ self.assertEqual(response.status_code, 200)
+
def test_async_streaming(self):
response = self.client.get("/async_streaming/")
self.assertEqual(response.status_code, 200)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34902#comment:1>