@@ -48,9 +48,14 @@ def tearDown(self):
48
48
asyncio .get_event_loop ().run_until_complete (
49
49
self .communicator .wait ()
50
50
)
51
-
51
+
52
+ async def create_communicator (self , app ):
53
+ return ApplicationCommunicator (app , self .scope )
54
+
52
55
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
+ )
54
59
55
60
def send_input (self , payload ):
56
61
asyncio .get_event_loop ().run_until_complete (
@@ -148,9 +153,9 @@ def test_gzip(self):
148
153
increments = 2
149
154
self .increment_metrics (metric_name , help_text , increments )
150
155
app = make_asgi_app (self .registry )
151
- self .seed_app (app )
152
156
# Send input with gzip header.
153
157
self .scope ["headers" ] = [(b"accept-encoding" , b"gzip" )]
158
+ self .seed_app (app )
154
159
self .send_input ({"type" : "http.request" , "body" : b"" })
155
160
# Assert outputs are compressed.
156
161
outputs = self .get_all_output ()
@@ -164,9 +169,9 @@ def test_gzip_disabled(self):
164
169
self .increment_metrics (metric_name , help_text , increments )
165
170
# Disable compression explicitly.
166
171
app = make_asgi_app (self .registry , disable_compression = True )
167
- self .seed_app (app )
168
172
# Send input with gzip header.
169
173
self .scope ["headers" ] = [(b"accept-encoding" , b"gzip" )]
174
+ self .seed_app (app )
170
175
self .send_input ({"type" : "http.request" , "body" : b"" })
171
176
# Assert outputs are not compressed.
172
177
outputs = self .get_all_output ()
@@ -175,8 +180,8 @@ def test_gzip_disabled(self):
175
180
def test_openmetrics_encoding (self ):
176
181
"""Response content type is application/openmetrics-text when appropriate Accept header is in request"""
177
182
app = make_asgi_app (self .registry )
178
- self .seed_app (app )
179
183
self .scope ["headers" ] = [(b"Accept" , b"application/openmetrics-text" )]
184
+ self .seed_app (app )
180
185
self .send_input ({"type" : "http.request" , "body" : b"" })
181
186
182
187
content_type = self .get_response_header_value ('Content-Type' ).split (";" )[0 ]
0 commit comments