FlaskTester 3.0__tar.gz → 3.1__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.
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.egg-info/PKG-INFO +10 -4
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.py +55 -47
- {FlaskTester-3.0 → FlaskTester-3.1}/PKG-INFO +10 -4
- {FlaskTester-3.0 → FlaskTester-3.1}/README.md +9 -3
- {FlaskTester-3.0 → FlaskTester-3.1}/pyproject.toml +1 -1
- {FlaskTester-3.0 → FlaskTester-3.1}/tests/test.py +53 -6
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.egg-info/SOURCES.txt +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.egg-info/dependency_links.txt +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.egg-info/requires.txt +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/FlaskTester.egg-info/top_level.txt +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/LICENSE +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/MANIFEST.in +0 -0
- {FlaskTester-3.0 → FlaskTester-3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: FlaskTester
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1
|
|
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
|

|
|
55
|
-

|
|
56
56
|

|
|
57
57
|

|
|
58
58
|

|
|
@@ -87,8 +87,8 @@ def app(ft_client):
|
|
|
87
87
|
assert res.is_json
|
|
88
88
|
ft_client.setToken("hobbes", res.json["token"])
|
|
89
89
|
# also set a cookie
|
|
90
|
-
ft_client.setCookie("hobbes", "lang", "
|
|
91
|
-
ft_client.setCookie("calvin", "lang", "
|
|
90
|
+
ft_client.setCookie("hobbes", "lang", "fr")
|
|
91
|
+
ft_client.setCookie("calvin", "lang", "en")
|
|
92
92
|
# return working client
|
|
93
93
|
yield ft_client
|
|
94
94
|
|
|
@@ -242,6 +242,12 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
|
|
|
242
242
|
see also the [documentation](https://zx80.github.io/flask-tester/),
|
|
243
243
|
please report any [issues](https://github.com/zx80/flask-tester/issues).
|
|
244
244
|
|
|
245
|
+
### 3.1 on 2024-03-24
|
|
246
|
+
|
|
247
|
+
More consistent test and demo code.
|
|
248
|
+
Reach actual full coverage, without _any_ pragma.
|
|
249
|
+
Fix default allowed authenticator schemes.
|
|
250
|
+
|
|
245
251
|
### 3.0 on 2024-03-23
|
|
246
252
|
|
|
247
253
|
Add support for `none` authentication, with only cookies.
|
|
@@ -455,6 +455,35 @@ class FlaskClient(Client):
|
|
|
455
455
|
|
|
456
456
|
return self._client.open(method=method, path=path, **kwargs)
|
|
457
457
|
|
|
458
|
+
def _ft_authenticator():
|
|
459
|
+
"""Fixture implementation separated for testing."""
|
|
460
|
+
|
|
461
|
+
level = os.environ.get("FLASK_TESTER_LOG_LEVEL", "NOTSET")
|
|
462
|
+
log.setLevel(logging.DEBUG if level == "DEBUG" else
|
|
463
|
+
logging.INFO if level == "INFO" else
|
|
464
|
+
logging.WARNING if level == "WARNING" else
|
|
465
|
+
logging.ERROR if level == "ERROR" else
|
|
466
|
+
logging.CRITICAL if level == "CRITICAL" else
|
|
467
|
+
logging.NOTSET)
|
|
468
|
+
|
|
469
|
+
allow = os.environ.get("FLASK_TESTER_ALLOW", "bearer basic param none").split(" ")
|
|
470
|
+
|
|
471
|
+
# per-scheme parameters, must be consistent with FSA configuration
|
|
472
|
+
user = os.environ.get("FLASK_TESTER_USER", "USER")
|
|
473
|
+
pwd = os.environ.get("FLASK_TESTER_PASS", "PASS")
|
|
474
|
+
login = os.environ.get("FLASK_TESTER_LOGIN", "LOGIN")
|
|
475
|
+
bearer = os.environ.get("FLASK_TESTER_BEARER", "Bearer")
|
|
476
|
+
header = os.environ.get("FLASK_TESTER_HEADER", "Auth")
|
|
477
|
+
cookie = os.environ.get("FLASK_TESTER_COOKIE", "auth")
|
|
478
|
+
tparam = os.environ.get("FLASK_TESTER_TPARAM", "AUTH")
|
|
479
|
+
|
|
480
|
+
# create authenticator, possibly with initial credentials
|
|
481
|
+
auth = Authenticator(allow, user=user, pwd=pwd, login=login, bearer=bearer, header=header, cookie=cookie, tparam=tparam)
|
|
482
|
+
|
|
483
|
+
if "FLASK_TESTER_AUTH" in os.environ:
|
|
484
|
+
auth.setPasses(os.environ["FLASK_TESTER_AUTH"].split(","))
|
|
485
|
+
|
|
486
|
+
return auth
|
|
458
487
|
|
|
459
488
|
@pytest.fixture
|
|
460
489
|
def ft_authenticator():
|
|
@@ -486,56 +515,18 @@ def ft_authenticator():
|
|
|
486
515
|
Default is not set.
|
|
487
516
|
"""
|
|
488
517
|
|
|
489
|
-
|
|
490
|
-
log.setLevel(logging.DEBUG if level == "DEBUG" else
|
|
491
|
-
logging.INFO if level == "INFO" else
|
|
492
|
-
logging.WARNING if level == "WARNING" else
|
|
493
|
-
logging.ERROR if level == "ERROR" else
|
|
494
|
-
logging.CRITICAL if level == "CRITICAL" else
|
|
495
|
-
logging.NOTSET)
|
|
496
|
-
|
|
497
|
-
allow = os.environ.get("FLASK_TESTER_ALLOW", "bearer basic param").split(" ")
|
|
498
|
-
|
|
499
|
-
# per-scheme parameters, must be consistent with FSA configuration
|
|
500
|
-
user = os.environ.get("FLASK_TESTER_USER", "USER")
|
|
501
|
-
pwd = os.environ.get("FLASK_TESTER_PASS", "PASS")
|
|
502
|
-
login = os.environ.get("FLASK_TESTER_LOGIN", "LOGIN")
|
|
503
|
-
bearer = os.environ.get("FLASK_TESTER_BEARER", "Bearer")
|
|
504
|
-
header = os.environ.get("FLASK_TESTER_HEADER", "Auth")
|
|
505
|
-
cookie = os.environ.get("FLASK_TESTER_COOKIE", "auth")
|
|
506
|
-
tparam = os.environ.get("FLASK_TESTER_TPARAM", "AUTH")
|
|
507
|
-
|
|
508
|
-
# create authenticator, possibly with initial credentials
|
|
509
|
-
auth = Authenticator(allow, user=user, pwd=pwd, login=login, bearer=bearer, header=header, cookie=cookie, tparam=tparam)
|
|
510
|
-
|
|
511
|
-
if "FLASK_TESTER_AUTH" in os.environ:
|
|
512
|
-
auth.setPasses(os.environ["FLASK_TESTER_AUTH"].split(","))
|
|
513
|
-
|
|
514
|
-
yield auth
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
@pytest.fixture
|
|
518
|
-
def ft_client(ft_authenticator):
|
|
519
|
-
"""Pytest Fixture: ft_client.
|
|
520
|
-
|
|
521
|
-
Target environment variable, one **must** be defined:
|
|
522
|
-
|
|
523
|
-
- ``FLASK_TESTER_URL``: application HTTP base URL.
|
|
524
|
-
- ``FLASK_TESTER_APP``: Flask application, eg ``app:create_app``.
|
|
525
|
-
|
|
526
|
-
Other environment variable:
|
|
518
|
+
yield _ft_authenticator()
|
|
527
519
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
"""
|
|
520
|
+
def _ft_client(authenticator):
|
|
521
|
+
"""Fixture implementation separated for testing."""
|
|
531
522
|
|
|
532
523
|
default_login = os.environ.get("FLASK_TESTER_DEFAULT", None)
|
|
533
524
|
client: Client
|
|
534
525
|
|
|
535
|
-
if "FLASK_TESTER_URL" in os.environ:
|
|
526
|
+
if "FLASK_TESTER_URL" in os.environ:
|
|
536
527
|
|
|
537
528
|
app_url = os.environ["FLASK_TESTER_URL"]
|
|
538
|
-
client = RequestClient(
|
|
529
|
+
client = RequestClient(authenticator, app_url, default_login)
|
|
539
530
|
|
|
540
531
|
elif "FLASK_TESTER_APP" in os.environ:
|
|
541
532
|
|
|
@@ -553,12 +544,29 @@ def ft_client(ft_authenticator):
|
|
|
553
544
|
if callable(app) and not hasattr(app, "test_client"):
|
|
554
545
|
app = app()
|
|
555
546
|
break
|
|
556
|
-
if not app:
|
|
547
|
+
if not app:
|
|
557
548
|
raise FlaskTesterError(f"cannot find Flask app in {pkg_name}")
|
|
558
|
-
client = FlaskClient(
|
|
549
|
+
client = FlaskClient(authenticator, app.test_client(), default_login)
|
|
559
550
|
|
|
560
|
-
else:
|
|
551
|
+
else:
|
|
561
552
|
|
|
562
553
|
raise FlaskTesterError("no Flask application to test")
|
|
563
554
|
|
|
564
|
-
|
|
555
|
+
return client
|
|
556
|
+
|
|
557
|
+
@pytest.fixture
|
|
558
|
+
def ft_client(ft_authenticator):
|
|
559
|
+
"""Pytest Fixture: ft_client.
|
|
560
|
+
|
|
561
|
+
Target environment variable, one **must** be defined:
|
|
562
|
+
|
|
563
|
+
- ``FLASK_TESTER_URL``: application HTTP base URL.
|
|
564
|
+
- ``FLASK_TESTER_APP``: Flask application, eg ``app:create_app``.
|
|
565
|
+
|
|
566
|
+
Other environment variable:
|
|
567
|
+
|
|
568
|
+
- ``FLASK_TESTER_DEFAULT``: Default client login, default is *None* for no
|
|
569
|
+
default.
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
yield _ft_client(ft_authenticator)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: FlaskTester
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1
|
|
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
|

|
|
55
|
-

|
|
56
56
|

|
|
57
57
|

|
|
58
58
|

|
|
@@ -87,8 +87,8 @@ def app(ft_client):
|
|
|
87
87
|
assert res.is_json
|
|
88
88
|
ft_client.setToken("hobbes", res.json["token"])
|
|
89
89
|
# also set a cookie
|
|
90
|
-
ft_client.setCookie("hobbes", "lang", "
|
|
91
|
-
ft_client.setCookie("calvin", "lang", "
|
|
90
|
+
ft_client.setCookie("hobbes", "lang", "fr")
|
|
91
|
+
ft_client.setCookie("calvin", "lang", "en")
|
|
92
92
|
# return working client
|
|
93
93
|
yield ft_client
|
|
94
94
|
|
|
@@ -242,6 +242,12 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
|
|
|
242
242
|
see also the [documentation](https://zx80.github.io/flask-tester/),
|
|
243
243
|
please report any [issues](https://github.com/zx80/flask-tester/issues).
|
|
244
244
|
|
|
245
|
+
### 3.1 on 2024-03-24
|
|
246
|
+
|
|
247
|
+
More consistent test and demo code.
|
|
248
|
+
Reach actual full coverage, without _any_ pragma.
|
|
249
|
+
Fix default allowed authenticator schemes.
|
|
250
|
+
|
|
245
251
|
### 3.0 on 2024-03-23
|
|
246
252
|
|
|
247
253
|
Add support for `none` authentication, with only cookies.
|
|
@@ -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
|

|
|
12
|
-

|
|
13
13
|

|
|
14
14
|

|
|
15
15
|

|
|
@@ -44,8 +44,8 @@ def app(ft_client):
|
|
|
44
44
|
assert res.is_json
|
|
45
45
|
ft_client.setToken("hobbes", res.json["token"])
|
|
46
46
|
# also set a cookie
|
|
47
|
-
ft_client.setCookie("hobbes", "lang", "
|
|
48
|
-
ft_client.setCookie("calvin", "lang", "
|
|
47
|
+
ft_client.setCookie("hobbes", "lang", "fr")
|
|
48
|
+
ft_client.setCookie("calvin", "lang", "en")
|
|
49
49
|
# return working client
|
|
50
50
|
yield ft_client
|
|
51
51
|
|
|
@@ -199,6 +199,12 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
|
|
|
199
199
|
see also the [documentation](https://zx80.github.io/flask-tester/),
|
|
200
200
|
please report any [issues](https://github.com/zx80/flask-tester/issues).
|
|
201
201
|
|
|
202
|
+
### 3.1 on 2024-03-24
|
|
203
|
+
|
|
204
|
+
More consistent test and demo code.
|
|
205
|
+
Reach actual full coverage, without _any_ pragma.
|
|
206
|
+
Fix default allowed authenticator schemes.
|
|
207
|
+
|
|
202
208
|
### 3.0 on 2024-03-23
|
|
203
209
|
|
|
204
210
|
Add support for `none` authentication, with only cookies.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "FlaskTester"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.1"
|
|
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"
|
|
@@ -38,8 +38,8 @@ def app(ft_client):
|
|
|
38
38
|
assert res.is_json
|
|
39
39
|
ft_client.setToken("hobbes", res.json["token"])
|
|
40
40
|
# also set a cookie
|
|
41
|
-
ft_client.setCookie("hobbes", "lang", "
|
|
42
|
-
ft_client.setCookie("calvin", "lang", "
|
|
41
|
+
ft_client.setCookie("hobbes", "lang", "fr")
|
|
42
|
+
ft_client.setCookie("calvin", "lang", "en")
|
|
43
43
|
# return working client
|
|
44
44
|
yield ft_client
|
|
45
45
|
|
|
@@ -136,16 +136,16 @@ def test_methods(api):
|
|
|
136
136
|
|
|
137
137
|
def test_hello(api):
|
|
138
138
|
res = api.get("/hello", login="calvin", auth="none", status=200)
|
|
139
|
-
assert res.json["hello"] == "Hi"
|
|
139
|
+
assert res.json["lang"] == "en" and res.json["hello"] == "Hi"
|
|
140
140
|
assert res.headers["FSA-User"] == "None (None)"
|
|
141
141
|
res = api.get("/hello", login="hobbes", auth="none", status=200)
|
|
142
|
-
assert res.json["hello"] == "Salut"
|
|
142
|
+
assert res.json["lang"] == "fr" and res.json["hello"] == "Salut"
|
|
143
143
|
assert res.headers["FSA-User"] == "None (None)"
|
|
144
144
|
res = api.get("/hello", login="susie", auth="none", status=200, cookies={"lang": "it"})
|
|
145
|
-
assert res.json["hello"] == "Ciao"
|
|
145
|
+
assert res.json["lang"] == "it" and res.json["hello"] == "Ciao"
|
|
146
146
|
assert res.headers["FSA-User"] == "None (None)"
|
|
147
147
|
res = api.get("/hello", login="moe", auth="none", status=200)
|
|
148
|
-
assert res.json["hello"] == "Hi"
|
|
148
|
+
assert res.json["lang"] == "en" and res.json["hello"] == "Hi"
|
|
149
149
|
assert res.headers["FSA-User"] == "None (None)"
|
|
150
150
|
|
|
151
151
|
def test_authenticator_token():
|
|
@@ -269,6 +269,7 @@ def test_request_flask_response():
|
|
|
269
269
|
assert not xres.is_json and xres.json is None
|
|
270
270
|
|
|
271
271
|
def test_client():
|
|
272
|
+
# abstract class for coverage
|
|
272
273
|
client = ft.Client(ft.Authenticator())
|
|
273
274
|
try:
|
|
274
275
|
client._request("GET", "/", {})
|
|
@@ -277,6 +278,7 @@ def test_client():
|
|
|
277
278
|
assert True, "expected error raised"
|
|
278
279
|
|
|
279
280
|
def test_request_client():
|
|
281
|
+
# start a tmp server on port 8888 for URL client coverage
|
|
280
282
|
httpd = htsv.HTTPServer(("", 8888), htsv.SimpleHTTPRequestHandler)
|
|
281
283
|
thread = threading.Thread(target = lambda: httpd.serve_forever())
|
|
282
284
|
thread.start()
|
|
@@ -290,3 +292,48 @@ def test_request_client():
|
|
|
290
292
|
client.post("/", status=501, data={"hello": "world!"})
|
|
291
293
|
finally:
|
|
292
294
|
httpd.shutdown()
|
|
295
|
+
|
|
296
|
+
def test_client_fixture():
|
|
297
|
+
# ft_client coverage
|
|
298
|
+
auth = ft._ft_authenticator()
|
|
299
|
+
# check and save env
|
|
300
|
+
# assert "FLASK_TESTER_URL" not in os.environ
|
|
301
|
+
url = None
|
|
302
|
+
if "FLASK_TESTER_URL" in os.environ: # pragma: no cover
|
|
303
|
+
url = os.environ["FLASK_TESTER_URL"]
|
|
304
|
+
del os.environ["FLASK_TESTER_URL"]
|
|
305
|
+
app = None
|
|
306
|
+
if "FLASK_TESTER_APP" in os.environ:
|
|
307
|
+
app = os.environ["FLASK_TESTER_APP"]
|
|
308
|
+
del os.environ["FLASK_TESTER_APP"]
|
|
309
|
+
# no url nor app
|
|
310
|
+
try:
|
|
311
|
+
init = ft._ft_client(auth)
|
|
312
|
+
pytest.fail("must fail without environment variables") # pragma: no cover
|
|
313
|
+
except ft.FlaskTesterError:
|
|
314
|
+
assert True, "expected error raised"
|
|
315
|
+
# url
|
|
316
|
+
os.environ["FLASK_TESTER_URL"] = "http://localhost:5000"
|
|
317
|
+
init = ft._ft_client(auth)
|
|
318
|
+
assert isinstance(init, ft.RequestClient)
|
|
319
|
+
del os.environ["FLASK_TESTER_URL"]
|
|
320
|
+
# bad package
|
|
321
|
+
os.environ["FLASK_TESTER_APP"] = "no_such_package"
|
|
322
|
+
try:
|
|
323
|
+
init = ft._ft_client(auth)
|
|
324
|
+
pytest.fail("must fail on missing package") # pragma: no cover
|
|
325
|
+
except ModuleNotFoundError:
|
|
326
|
+
assert True, "expected error raised"
|
|
327
|
+
# bad name
|
|
328
|
+
os.environ["FLASK_TESTER_APP"] = "app:no_such_app"
|
|
329
|
+
try:
|
|
330
|
+
init = ft._ft_client(auth)
|
|
331
|
+
pytest.fail("must fail on missing package") # pragma: no cover
|
|
332
|
+
except ft.FlaskTesterError:
|
|
333
|
+
assert True, "expected error raised"
|
|
334
|
+
del os.environ["FLASK_TESTER_APP"]
|
|
335
|
+
# reset env
|
|
336
|
+
if url: # pragma: no cover
|
|
337
|
+
os.environ["FLASK_TESTER_URL"] = url
|
|
338
|
+
if app:
|
|
339
|
+
os.environ["FLASK_TESTER_APP"] = app
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|