FlaskTester 3.5__tar.gz → 3.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 3.5
3
+ Version: 3.6
4
4
  Summary: Pytest fixtures for Flask internal and external authenticated tests
5
5
  Author-email: Fabien Coelho <flask.tester@coelho.net>
6
6
  License: CC0
@@ -52,7 +52,7 @@ Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
53
53
 
54
54
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
55
- ![Tests](https://img.shields.io/badge/tests-13%20✓-success)
55
+ ![Tests](https://img.shields.io/badge/tests-14%20✓-success)
56
56
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
57
57
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
58
58
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -107,7 +107,7 @@ This can be run against a (local) server:
107
107
  export TEST_SEED="some-random-data" # shared test seed
108
108
  flask --app app:app run & # start flask app
109
109
  pid=$! # keep pid
110
- export FLASK_TESTER_URL="http://localhost:5000" # set app local url
110
+ export FLASK_TESTER_APP="http://localhost:5000" # set app local url
111
111
  pytest test.py # run external tests
112
112
  kill $pid # stop app with pid
113
113
  ```
@@ -115,7 +115,7 @@ kill $pid # stop app with pid
115
115
  Or locally with the Flask internal test infrastructure:
116
116
 
117
117
  ```shell
118
- export FLASK_TESTER_APP="app:app" # set app module
118
+ export FLASK_TESTER_APP="app:app" # set app package
119
119
  pytest test.py # run internal tests
120
120
  ```
121
121
 
@@ -8,4 +8,5 @@ FlaskTester.egg-info/SOURCES.txt
8
8
  FlaskTester.egg-info/dependency_links.txt
9
9
  FlaskTester.egg-info/requires.txt
10
10
  FlaskTester.egg-info/top_level.txt
11
- tests/test.py
11
+ tests/test_app.py
12
+ tests/test_app2.py
@@ -532,15 +532,14 @@ def _ft_client(authenticator):
532
532
  default_login = os.environ.get("FLASK_TESTER_DEFAULT", None)
533
533
  client: Client
534
534
 
535
- if "FLASK_TESTER_URL" in os.environ:
536
-
537
- app_url = os.environ["FLASK_TESTER_URL"]
538
- client = RequestClient(authenticator, app_url, default_login)
539
-
540
- elif "FLASK_TESTER_APP" in os.environ:
535
+ app_def = os.environ.get("FLASK_TESTER_URL", "app")
536
+ app_def = os.environ.get("FLASK_TESTER_APP", app_def)
541
537
 
538
+ if app_def.startswith("http://") or app_def.startswith("https://"):
539
+ client = RequestClient(authenticator, app_def, default_login)
540
+ else:
542
541
  # load app package
543
- pkg_name, app = os.environ["FLASK_TESTER_APP"], None
542
+ pkg_name, app = app_def, None
544
543
  app_names = ["app", "application", "create_app", "make_app"]
545
544
  if ":" in pkg_name: # override defaults
546
545
  pkg_name, app_name = pkg_name.split(":", 1)
@@ -557,20 +556,17 @@ def _ft_client(authenticator):
557
556
  raise FlaskTesterError(f"cannot find Flask app in {pkg_name}")
558
557
  client = FlaskClient(authenticator, app.test_client(), default_login)
559
558
 
560
- else:
561
-
562
- raise FlaskTesterError("no Flask application to test")
563
-
564
559
  return client
565
560
 
566
561
  @pytest.fixture
567
562
  def ft_client(ft_authenticator):
568
563
  """Pytest Fixture: ft_client.
569
564
 
570
- Target environment variable, one **must** be defined:
565
+ Target environment variable:
571
566
 
572
- - ``FLASK_TESTER_URL``: application HTTP base URL, eg ``http://localhost:5000``.
573
- - ``FLASK_TESTER_APP``: Flask application, eg ``app:create_app``.
567
+ - ``FLASK_TESTER_APP``: find the Flask application, eg
568
+ ``app:create_app`` for an internal test, or
569
+ ``http://localhost:5000`` for an external test.
574
570
 
575
571
  Other environment variable:
576
572
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 3.5
3
+ Version: 3.6
4
4
  Summary: Pytest fixtures for Flask internal and external authenticated tests
5
5
  Author-email: Fabien Coelho <flask.tester@coelho.net>
6
6
  License: CC0
@@ -52,7 +52,7 @@ Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
53
53
 
54
54
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
55
- ![Tests](https://img.shields.io/badge/tests-13%20✓-success)
55
+ ![Tests](https://img.shields.io/badge/tests-14%20✓-success)
56
56
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
57
57
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
58
58
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -107,7 +107,7 @@ This can be run against a (local) server:
107
107
  export TEST_SEED="some-random-data" # shared test seed
108
108
  flask --app app:app run & # start flask app
109
109
  pid=$! # keep pid
110
- export FLASK_TESTER_URL="http://localhost:5000" # set app local url
110
+ export FLASK_TESTER_APP="http://localhost:5000" # set app local url
111
111
  pytest test.py # run external tests
112
112
  kill $pid # stop app with pid
113
113
  ```
@@ -115,7 +115,7 @@ kill $pid # stop app with pid
115
115
  Or locally with the Flask internal test infrastructure:
116
116
 
117
117
  ```shell
118
- export FLASK_TESTER_APP="app:app" # set app module
118
+ export FLASK_TESTER_APP="app:app" # set app package
119
119
  pytest test.py # run internal tests
120
120
  ```
121
121
 
@@ -9,7 +9,7 @@ Only one set of tests is needed, switching from internal to external is
9
9
  achieved through environment variables.
10
10
 
11
11
  ![Status](https://github.com/zx80/flask-tester/actions/workflows/package.yml/badge.svg?branch=main&style=flat)
12
- ![Tests](https://img.shields.io/badge/tests-13%20✓-success)
12
+ ![Tests](https://img.shields.io/badge/tests-14%20✓-success)
13
13
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
14
14
  ![Issues](https://img.shields.io/github/issues/zx80/flask-tester?style=flat)
15
15
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -64,7 +64,7 @@ This can be run against a (local) server:
64
64
  export TEST_SEED="some-random-data" # shared test seed
65
65
  flask --app app:app run & # start flask app
66
66
  pid=$! # keep pid
67
- export FLASK_TESTER_URL="http://localhost:5000" # set app local url
67
+ export FLASK_TESTER_APP="http://localhost:5000" # set app local url
68
68
  pytest test.py # run external tests
69
69
  kill $pid # stop app with pid
70
70
  ```
@@ -72,7 +72,7 @@ kill $pid # stop app with pid
72
72
  Or locally with the Flask internal test infrastructure:
73
73
 
74
74
  ```shell
75
- export FLASK_TESTER_APP="app:app" # set app module
75
+ export FLASK_TESTER_APP="app:app" # set app package
76
76
  pytest test.py # run internal tests
77
77
  ```
78
78
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "FlaskTester"
7
- version = "3.5"
7
+ version = "3.6"
8
8
  authors = [ { name = "Fabien Coelho", email = "flask.tester@coelho.net" } ]
9
9
  description = "Pytest fixtures for Flask internal and external authenticated tests"
10
10
  readme = "README.md"
@@ -309,7 +309,6 @@ def test_client_fixture():
309
309
  # ft_client coverage
310
310
  auth = ft._ft_authenticator()
311
311
  # check and save env
312
- # assert "FLASK_TESTER_URL" not in os.environ
313
312
  url = None
314
313
  if "FLASK_TESTER_URL" in os.environ: # pragma: no cover
315
314
  url = os.environ["FLASK_TESTER_URL"]
@@ -318,12 +317,8 @@ def test_client_fixture():
318
317
  if "FLASK_TESTER_APP" in os.environ:
319
318
  app = os.environ["FLASK_TESTER_APP"]
320
319
  del os.environ["FLASK_TESTER_APP"]
321
- # no url nor app
322
- try:
323
- init = ft._ft_client(auth)
324
- pytest.fail("must fail without environment variables") # pragma: no cover
325
- except ft.FlaskTesterError:
326
- assert True, "expected error raised"
320
+ # no url nor app, defaults to "app"
321
+ init = ft._ft_client(auth)
327
322
  # url
328
323
  os.environ["FLASK_TESTER_URL"] = "http://localhost:5000"
329
324
  init = ft._ft_client(auth)
@@ -0,0 +1,28 @@
1
+ import os
2
+ import pytest
3
+ from FlaskTester import ft_client, ft_authenticator
4
+
5
+ os.environ.update(FLASK_TESTER_ALLOW="basic param none")
6
+
7
+ @pytest.fixture
8
+ def app(ft_client):
9
+ ft_client.setPass("calvin", "clv-pw")
10
+ ft_client.setCookie("calvin", "lang", "en")
11
+ ft_client.setPass("hobbes", "hbs-pw")
12
+ ft_client.setCookie("hobbes", "lang", "fr")
13
+ yield ft_client
14
+
15
+ def test_something(app):
16
+ # requires an authentication
17
+ app.get("/authenticated", 401, login=None)
18
+ res = app.get("/authenticated", 200, login="calvin")
19
+ assert "Hello" in res.text
20
+ app.get("/authenticated", 200, "Bonjour", login="hobbes")
21
+ # only allowed to calvin
22
+ app.get("/only-calvin", 401, login=None)
23
+ app.get("/only-calvin", 200, login="calvin")
24
+ app.get("/only-calvin", 403, login="hobbes")
25
+ # no authentication required, but depends on lang
26
+ res = app.get("/no-auth", 200, login="calvin", auth="none")
27
+ assert "Hello" in res.text
28
+ app.get("/no-auth", 200, "Bonjour", login="hobbes", auth="none")
File without changes
File without changes
File without changes