Skip to content
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

Support new asgiref #1081

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ def tearDown(self):
asyncio.get_event_loop().run_until_complete(
self.communicator.wait()
)


async def create_communicator(self, app):
return ApplicationCommunicator(app, self.scope)

def seed_app(self, app):
self.communicator = ApplicationCommunicator(app, self.scope)
self.communicator = asyncio.get_event_loop().run_until_complete(
self.create_communicator(app)
)

def send_input(self, payload):
asyncio.get_event_loop().run_until_complete(
Expand Down Expand Up @@ -148,9 +153,9 @@ def test_gzip(self):
increments = 2
self.increment_metrics(metric_name, help_text, increments)
app = make_asgi_app(self.registry)
self.seed_app(app)
# Send input with gzip header.
self.scope["headers"] = [(b"accept-encoding", b"gzip")]
self.seed_app(app)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these are reordered?

self.send_input({"type": "http.request", "body": b""})
# Assert outputs are compressed.
outputs = self.get_all_output()
Expand All @@ -164,9 +169,9 @@ def test_gzip_disabled(self):
self.increment_metrics(metric_name, help_text, increments)
# Disable compression explicitly.
app = make_asgi_app(self.registry, disable_compression=True)
self.seed_app(app)
# Send input with gzip header.
self.scope["headers"] = [(b"accept-encoding", b"gzip")]
self.seed_app(app)
self.send_input({"type": "http.request", "body": b""})
# Assert outputs are not compressed.
outputs = self.get_all_output()
Expand All @@ -175,8 +180,8 @@ def test_gzip_disabled(self):
def test_openmetrics_encoding(self):
"""Response content type is application/openmetrics-text when appropriate Accept header is in request"""
app = make_asgi_app(self.registry)
self.seed_app(app)
self.scope["headers"] = [(b"Accept", b"application/openmetrics-text")]
self.seed_app(app)
self.send_input({"type": "http.request", "body": b""})

content_type = self.get_response_header_value('Content-Type').split(";")[0]
Expand Down
9 changes: 4 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[tox]
envlist = coverage-clean,py{3.9,3.10,3.11,3.12,3.13,py3.9,3.9-nooptionals},coverage-report,flake8,isort,mypy
envlist = coverage-clean,py{3.9.18,3.10,3.11,3.12,3.13,py3.9,3.9-nooptionals},coverage-report,flake8,isort,mypy

[testenv]
deps =
coverage
pytest
attrs
{py3.9,pypy3.9}: twisted
# NOTE: Pinned due to https://github.com/prometheus/client_python/issues/1020
py3.9: asgiref==3.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to break for users running on asgiref==3.7?

pypy3.9: asgiref==3.7
{py3.9.18,pypy3.9}: twisted
py3.9.18: asgiref
pypy3.9: asgiref
commands = coverage run --parallel -m pytest {posargs}

[testenv:py3.9-nooptionals]
Expand Down