8000 Support new asgiref · prometheus/client_python@595d2d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 595d2d4

Browse files
committed
Support new asgiref
Signed-off-by: Alexander Shadchin <shadchin@yandex-team.com>
1 parent 92b2397 commit 595d2d4

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

tests/test_asgi.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ def tearDown(self):
4848
asyncio.get_event_loop().run_until_complete(
4949
self.communicator.wait()
5050
)
51-
51+
52+
async def create_communicator(self, app):
53+
return ApplicationCommunicator(app, self.scope)
54+
5255
def seed_app(self, app):
53-
self.communicator = ApplicationCommunicator(app, self.scope)
56+
self.communicator = asyncio.get_event_loop().run_until_complete(
57+
self.create_communicator(app)
58+
)
5459

5560
def send_input(self, payload):
5661
asyncio.get_event_loop().run_until_complete(
@@ -148,9 +153,9 @@ def test_gzip(self):
148153
increments = 2
149154
self.increment_metrics(metric_name, help_text, increments)
150155
app = make_asgi_app(self.registry)
151-
self.seed_app(app)
152156
# Send input with gzip header.
153157
self.scope["headers"] = [(b"accept-encoding", b"gzip")]
158+
self.seed_app(app)
154159
self.send_input({"type": "http.request", "body": b""})
155160
# Assert outputs are compressed.
156161
outputs = self.get_all_output()
@@ -164,9 +169,9 @@ def test_gzip_disabled(self):
164169
self.increment_metrics(metric_name, help_text, increments)
165170
# Disable compression explicitly.
166171
app = make_asgi_app(self.registry, disable_compression=True)
167-
self.seed_app(app)
168172
# Send input with gzip header.
169173
self.scope["headers"] = [(b"accept-encoding", b"gzip")]
174+
self.seed_app(app)
170175
self.send_input({"type": "http.request", "body": b""})
171176
# Assert outputs are not compressed.
172177
outputs = self.get_all_output()
@@ -175,8 +180,8 @@ def test_gzip_disabled(self):
175180
def test_openmetrics_encoding(self):
176181
"""Response content type is application/openmetrics-text when appropriate Accept header is in request"""
177182
app = make_asgi_app(self.registry)
178-
self.seed_app(app)
179183
self.scope["headers"] = [(b"Accept", b"application/openmetrics-text")]
184+
self.seed_app(app)
180185
self.send_input({"type": "http.request", "body": b""})
181186

182187
content_type = self.get_response_header_value('Content-Type').split(";")[0]

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ deps =
77
pytest
88
attrs
99
{py3.9,pypy3.9}: twisted
10-
# NOTE: Pinned due to https://github.com/prometheus/client_python/issues/1020
11-
py3.9: asgiref==3.7
12-
pypy3.9: asgiref==3.7
10+
py3.9: asgiref
11+
pypy3.9: asgiref
1312
commands = coverage run --parallel -m pytest {posargs}
1413

1514
[testenv:py3.9-nooptionals]

0 commit comments

Comments
 (0)
0