FlaskTester 4.2__tar.gz → 4.3__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: 4.2
3
+ Version: 4.3
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
@@ -19,7 +19,6 @@ Requires-Python: >=3.10
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: requests
22
- Requires-Dist: flask
23
22
  Requires-Dist: pytest
24
23
  Provides-Extra: dev
25
24
  Requires-Dist: mypy; extra == "dev"
@@ -34,6 +33,7 @@ Requires-Dist: types-flask; extra == "dev"
34
33
  Requires-Dist: types-requests; extra == "dev"
35
34
  Requires-Dist: FlaskSimpleAuth>=30.0; extra == "dev"
36
35
  Requires-Dist: passlib; extra == "dev"
36
+ Requires-Dist: bcrypt; extra == "dev"
37
37
  Requires-Dist: pydantic; extra == "dev"
38
38
  Provides-Extra: doc
39
39
  Requires-Dist: sphinx; extra == "doc"
@@ -1,5 +1,4 @@
1
1
  requests
2
- flask
3
2
  pytest
4
3
 
5
4
  [dev]
@@ -15,6 +14,7 @@ types-flask
15
14
  types-requests
16
15
  FlaskSimpleAuth>=30.0
17
16
  passlib
17
+ bcrypt
18
18
  pydantic
19
19
 
20
20
  [doc]
@@ -348,11 +348,13 @@ class Client:
348
348
  cookies.update(kwargs["cookies"])
349
349
  del kwargs["cookies"]
350
350
 
351
- # FIXME allow or forbid?
352
- # if "json" in kwargs and "data" in kwargs:
353
- # log.warning("mix of json and data parameters in request")
351
+ # this is forbidden by Flask client
352
+ if "json" in kwargs and "data" in kwargs:
353
+ # merge into data to possibly keep uploads
354
+ kwargs["data"].update(kwargs["json"])
355
+ del kwargs["json"]
354
356
 
355
- # convert json parameters
357
+ # convert json parameters to json
356
358
  if "json" in kwargs:
357
359
  json_param = kwargs["json"]
358
360
  assert isinstance(json_param, dict)
@@ -368,7 +370,7 @@ class Client:
368
370
  else: # pydantic or standard dataclasses?
369
371
  json_param[name] = dataclasses.asdict(val)
370
372
 
371
- # convert data parameters
373
+ # convert data parameters to simple strings
372
374
  if "data" in kwargs:
373
375
  data_param = kwargs["data"]
374
376
  assert isinstance(data_param, dict)
@@ -388,6 +390,7 @@ class Client:
388
390
  else:
389
391
  data_param[name] = json.dumps(dataclasses.asdict(val))
390
392
 
393
+ # now set authentication headers and do the query
391
394
  self._auth.setAuth(login, kwargs, cookies, auth=auth)
392
395
  res = self._request(method, path, cookies, **kwargs) # type: ignore
393
396
 
@@ -530,6 +533,7 @@ def _ft_authenticator():
530
533
  auth = Authenticator(allow, user=user, pwd=pwd, login=login, bearer=bearer,
531
534
  header=header, cookie=cookie, tparam=tparam, ptype=ptype)
532
535
 
536
+ # possibly load credentials from the environment
533
537
  if "FLASK_TESTER_AUTH" in os.environ:
534
538
  auth.setPasses(os.environ["FLASK_TESTER_AUTH"].split(","))
535
539
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 4.2
3
+ Version: 4.3
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
@@ -19,7 +19,6 @@ Requires-Python: >=3.10
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: requests
22
- Requires-Dist: flask
23
22
  Requires-Dist: pytest
24
23
  Provides-Extra: dev
25
24
  Requires-Dist: mypy; extra == "dev"
@@ -34,6 +33,7 @@ Requires-Dist: types-flask; extra == "dev"
34
33
  Requires-Dist: types-requests; extra == "dev"
35
34
  Requires-Dist: FlaskSimpleAuth>=30.0; extra == "dev"
36
35
  Requires-Dist: passlib; extra == "dev"
36
+ Requires-Dist: bcrypt; extra == "dev"
37
37
  Requires-Dist: pydantic; extra == "dev"
38
38
  Provides-Extra: doc
39
39
  Requires-Dist: sphinx; extra == "doc"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "FlaskTester"
7
- version = "4.2"
7
+ version = "4.3"
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"
@@ -12,7 +12,6 @@ license = { text = "CC0" }
12
12
  requires-python = ">=3.10"
13
13
  dependencies = [
14
14
  "requests",
15
- "flask",
16
15
  "pytest"
17
16
  ]
18
17
  classifiers = [
@@ -39,7 +38,7 @@ dev = [
39
38
  # packaging
40
39
  "build", "twine", "wheel",
41
40
  # tests
42
- "types-flask", "types-requests", "FlaskSimpleAuth>=30.0", "passlib", "pydantic"
41
+ "types-flask", "types-requests", "FlaskSimpleAuth>=30.0", "passlib", "bcrypt", "pydantic"
43
42
  ]
44
43
  # documentation generation
45
44
  doc = ["sphinx", "sphinx_rtd_theme", "sphinx-autoapi", "sphinx-lint", "myst_parser"]
@@ -65,15 +65,15 @@ def test_app_who_am_i(app): # GET /who-am-i
65
65
  def api(ft_client):
66
66
  # set a default
67
67
  ft_client._default_login = "calvin"
68
- # bad password / token
68
+ # bad password and token
69
69
  ft_client.setPass("moe", None)
70
70
  ft_client.setToken("moe", None)
71
71
  ft_client.setPass("moe", "bad password")
72
72
  ft_client.setToken("moe", "bad token")
73
- # cookies
73
+ # set language cookies
74
74
  ft_client.setCookie("calvin", "lang", "en")
75
75
  ft_client.setCookie("hobbes", "lang", "fr")
76
- # get valid tokens using password authn
76
+ # get valid tokens using password authn on /login
77
77
  res = ft_client.get("/login", login="calvin", auth="basic", status=200)
78
78
  assert res.json["user"] == "calvin"
79
79
  ft_client._auth.setToken("calvin", res.json["token"])
@@ -100,7 +100,7 @@ def api(ft_client):
100
100
  assert res.json["user"] == "calvin"
101
101
  res = ft_client.get("/who-am-i", status=200)
102
102
  assert res.json["user"] == "calvin"
103
- # add a bad password
103
+ # ready for testing routes
104
104
  yield ft_client
105
105
 
106
106
  def test_admin(api):
@@ -26,3 +26,12 @@ def test_something(app):
26
26
  app.get("/open", 200, "Hello", login="calvin", auth="none")
27
27
  app.get("/open", 200, "Bonjour", login="hobbes", auth="none")
28
28
  app.get("/open", 200, "Guten Tag", login=None)
29
+
30
+ def test_params(app):
31
+ res = app.get("/add", 200, data={"i": 39, "j": 3}, login=None)
32
+ assert res.is_json and res.json["sum"] == 42
33
+ res = app.get("/add", 200, json={"i": 35, "j": 7}, login=None)
34
+ assert res.is_json and res.json["sum"] == 42
35
+ # mixing data/json is okay for FlaskTester
36
+ res = app.get("/add", 200, data={"i": 30}, json={"j": 12}, login=None)
37
+ assert res.is_json and res.json["sum"] == 42
File without changes
File without changes
File without changes
File without changes