Skip to content

Commit ccb9a75

Browse files
Use Flask test client's own environ dict if available (Fixes #2142)
1 parent e05f135 commit ccb9a75

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ classifiers = [
1212
"License :: OSI Approved :: MIT License",
1313
"Operating System :: OS Independent",
1414
]
15-
requires-python = ">=3.6"
15+
requires-python = ">=3.8"
1616
dependencies = [
17-
"Flask >= 0.9",
17+
"Flask >= 2.1.0",
1818
"python-socketio >= 5.12.0",
1919
]
2020

@@ -30,6 +30,12 @@ Homepage = "https://github.com/miguelgrinberg/flask-socketio"
3030
docs = [
3131
"sphinx",
3232
]
33+
dev = [
34+
"tox",
35+
"pytest",
36+
"pytest-cov",
37+
"redis",
38+
]
3339

3440
[tool.setuptools]
3541
zip-safe = false

src/flask_socketio/test_client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from socketio import packet
44
from socketio.pubsub_manager import PubSubManager
5-
from werkzeug.test import EnvironBuilder
5+
from flask.testing import EnvironBuilder
66

77

88
class SocketIOTestClient:
@@ -128,8 +128,16 @@ def connect(self, namespace=None, query_string=None, headers=None,
128128
if query_string[0] != '?':
129129
query_string = '?' + query_string
130130
url += query_string
131-
environ = EnvironBuilder(url, headers=headers).get_environ()
131+
if self.flask_test_client:
132+
# let Flask's test client build an environ dictionary
133+
req = self.flask_test_client._request_from_builder_args(
134+
args=(), kwargs={'path': url, 'headers': headers})
135+
environ = req.environ
136+
else:
137+
environ = EnvironBuilder(
138+
self.app, path=url, headers=headers).get_environ()
132139
environ['flask.app'] = self.app
140+
133141
if self.flask_test_client:
134142
# inject cookies from Flask
135143
if hasattr(self.flask_test_client, '_add_cookies_to_wsgi'):

0 commit comments

Comments
 (0)