Fix base test class (#2152)

This commit is contained in:
Adrià Casajús 2024-07-10 13:41:50 +02:00 committed by GitHub
parent d8f7cb2852
commit 747dfc04bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import os import os
from flask import testing
# use the tests/test.env config fle # use the tests/test.env config fle
# flake8: noqa: E402 # flake8: noqa: E402
@ -46,6 +47,15 @@ def flask_app():
from app import config, constants from app import config, constants
class CustomTestClient(testing.FlaskClient):
def open(self, *args, **kwargs):
if isinstance(args[0], str):
headers = kwargs.pop("headers", {})
headers.update({constants.HEADER_ALLOW_API_COOKIES: "allow"})
kwargs["headers"] = headers
return super().open(*args, **kwargs)
@pytest.fixture @pytest.fixture
def flask_client(): def flask_client():
transaction = connection.begin() transaction = connection.begin()
@ -54,6 +64,7 @@ def flask_client():
# disable rate limit during test # disable rate limit during test
config.DISABLE_RATE_LIMIT = True config.DISABLE_RATE_LIMIT = True
try: try:
app.test_client_class = CustomTestClient
client = app.test_client() client = app.test_client()
client.environ_base[constants.HEADER_ALLOW_API_COOKIES] = "allow" client.environ_base[constants.HEADER_ALLOW_API_COOKIES] = "allow"
yield client yield client