Skip to content

Conversation

vrt-boss-bfx
Copy link

Flask's testing.TestClient sets and allows overriding its environ_base.

This PR makes flask_socketio's SocketIOTestClient honor the environ_base if it exists.

This would allow testing handler that depend on overridden environ_base. For example

import unittest

from flask import Flask, request
from flask_socketio import SocketIO

app = Flask(__name__)
app.config["SECRET_KEY"] = "secret"
socketio = SocketIO(app)


@socketio.on("connect")
def on_connect(auth):
    return request.remote_addr == "10.0.0.0"


class TestWithClient(unittest.TestCase):
    def test_connect(self):
        flask_test_client = app.test_client()
        flask_test_client.environ_base = {
            **flask_test_client.environ_base,
            "REMOTE_ADDR": "10.0.0.0",
        }

        client = socketio.test_client(app, flask_test_client=flask_test_client)
        self.assertTrue(client.is_connected())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant