Skip to content

Commit

Permalink
wip 0.10 with FLASK_TESTER_DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Coelho committed Mar 11, 2024
1 parent c02b65e commit 77418f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions FlaskTester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(","))
Expand All @@ -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)
Expand All @@ -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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 77418f8

Please sign in to comment.