diff --git a/FlaskTester.py b/FlaskTester.py index ace2b11..4c9b9f2 100755 --- a/FlaskTester.py +++ b/FlaskTester.py @@ -345,7 +345,7 @@ def _request(self, method: str, path: str, **kwargs): @pytest.fixture def ft_authenticator(): - allow = os.environ["FLASK_TESTER_ALLOW"].split(" ") if "FLASK_TESTER_ALLOW" in os.environ else ["bearer", "basic", "param"] + allow = os.environ.get("FLASK_TESTER_ALLOW", "bearer basic param").split(" ") auth = Authenticator(allow) if "FLASK_TESTER_AUTH" in os.environ: auth.setPasses(os.environ["FLASK_TESTER_AUTH"].split(",")) @@ -354,10 +354,11 @@ def ft_authenticator(): @pytest.fixture def ft_client(ft_authenticator): + default_login = os.environ.get("FLASK_TESTER_DEFAULT", None) client: Client if "FLASK_TESTER_URL" in os.environ: app_url = os.environ["FLASK_TESTER_URL"] - client = RequestClient(ft_authenticator, app_url) + client = RequestClient(ft_authenticator, app_url, default_login) elif "FLASK_TESTER_APP" in os.environ: pkg_name = os.environ["FLASK_TESTER_APP"] pkg = importlib.import_module(pkg_name) @@ -367,7 +368,7 @@ def ft_client(ft_authenticator): app = getattr(pkg, "create_app")() else: raise FlaskTesterError(f"cannot find Flask app in {pkg_name}") - client = FlaskClient(ft_authenticator, app.test_client()) + client = FlaskClient(ft_authenticator, app.test_client(), default_login) else: raise FlaskTesterError("no Flask application to test") yield client diff --git a/README.md b/README.md index ef9825c..4c2f464 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ The package provides two fixtures: - `ft_client` for app testing, which depends on the previous fixture, plus environment variables which allow to find the application, at least one must be defined. + - `FLASK_TESTER_DEFAULT` default login for authentication. - `FLASK_TESTER_URL` URL of the running application for external tests. - `FLASK_TESTER_APP` package (filename with `.py`) to be imported for the application. - the application is expected to be named `app` @@ -80,6 +81,10 @@ The implementation of these fixtures is based on four classes: ## Versions -### 0.9 on ? +### 0.10 on ? + +Add `FLASK_TESTER_DEFAULT` environment configuration to `ft_client`. + +### 0.9 on 2024-03-11 Initial revision extracted from a separate project. diff --git a/pyproject.toml b/pyproject.toml index 32c4c18..35811f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "FlaskTester" -version = "0.9" +version = "0.10" authors = [ { name = "Fabien Coelho", email = "flask.tester@coelho.net" } ] description = "Pytest fixtures for Flask authenticated internal and external tests" readme = "README.md"