FlaskTester 3.4__tar.gz → 3.5__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.4
3
+ Version: 3.5
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
@@ -1,7 +1,6 @@
1
1
  """FlaskTester - Pytest fixtures for Flask authenticated internal and external tests.
2
2
 
3
- This is needed when testing this module, but may not be desirable when it is
4
- used depending on the ``assert``: PYTEST_DONT_REWRITE
3
+ PYTEST_DONT_REWRITE: local assertions are really that, not pytest assertions.
5
4
  """
6
5
 
7
6
  import os
@@ -25,6 +24,20 @@ class AuthError(FlaskTesterError):
25
24
  pass
26
25
 
27
26
 
27
+ class _AssertError(FlaskTesterError):
28
+ """User assertion Exception, only for internal testing."""
29
+ pass
30
+
31
+
32
+ def _raiseError(msg: str):
33
+ """Undocumented switch for FlaskTester own tests."""
34
+ log.error(msg)
35
+ if "FLASK_TESTER_TESTING" in os.environ:
36
+ raise _AssertError(msg)
37
+ else: # pragma: no cover # cannot cover an expected pytest failure!
38
+ pytest.fail(msg)
39
+
40
+
28
41
  class Authenticator:
29
42
  """Manage HTTP request authentication.
30
43
 
@@ -336,14 +349,12 @@ class Client:
336
349
  # check status
337
350
  if status is not None:
338
351
  if res.status_code != status: # show error before aborting
339
- log.error(f"bad {status} result: {res.status_code} {res.text[:512]}")
340
- assert res.status_code == status, f"unexpected status {res.status_code}, expecting {status}"
352
+ _raiseError(f"bad {status} result: {res.status_code} {res.text[:512]}...")
341
353
 
342
354
  # check content
343
355
  if content is not None:
344
356
  if not re.search(content, res.text, re.DOTALL):
345
- log.error(f"cannot find {content} in {res.text}")
346
- assert False, f"expected content {content} not found in {res.text}"
357
+ _raiseError(f"cannot find {content} in {res.text[:512]}...")
347
358
 
348
359
  return res
349
360
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 3.4
3
+ Version: 3.5
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "FlaskTester"
7
- version = "3.4"
7
+ version = "3.5"
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"
@@ -15,6 +15,7 @@ logging.basicConfig(level=logging.INFO)
15
15
 
16
16
  # set authn for ft_authenticator
17
17
  os.environ.update(
18
+ FLASK_TESTER_TESTING="*",
18
19
  FLASK_TESTER_ALLOW="bearer basic param none",
19
20
  FLASK_TESTER_AUTH=",".join(f"{l}:{p}" for l, p in secret.PASSES.items()),
20
21
  )
@@ -109,25 +110,32 @@ def test_admin(api):
109
110
  api.get("/admin", 403, login="hobbes", auth=auth)
110
111
  api.get("/admin", 401, login="moe", auth=auth)
111
112
  api.get("/admin", 401, login=None, auth=auth)
113
+ # test status error
112
114
  try:
113
115
  api.get("/admin", status=599, login="calvin", auth=auth)
114
116
  pytest.fail("assert on status must fail") # pragma: no cover
115
- except AssertionError as e:
117
+ except ft._AssertError as e:
116
118
  assert "200" in str(e)
119
+ # test content error
117
120
  try:
118
121
  api.get("/admin", status=200, login="calvin", auth=auth, content="NOT THERE")
119
122
  pytest.fail("assert on content must fail") # pragma: no cover
120
- except AssertionError as e:
123
+ except ft._AssertError as e:
121
124
  assert "NOT THERE" in str(e)
122
125
 
123
126
  def test_errors(api):
124
127
  # these schemes are not allowed
125
- for scheme in ("header", "cookie", "fake", "tparam", "unexpected"):
128
+ for scheme in ("header", "cookie", "fake", "tparam"):
126
129
  try:
127
130
  api.get("/login", login="calvin", auth=scheme)
128
131
  pytest.fail("must raise an exception") # pragma: no cover
129
132
  except ft.AuthError as e:
130
- assert True, "expected error"
133
+ assert "auth is not allowed" in str(e)
134
+ try:
135
+ api.get("/login", login="calvin", auth="foobla")
136
+ pytest.fail("must raise an exception") # pragma: no cover
137
+ except ft.AuthError as e:
138
+ assert "unexpected auth" in str(e)
131
139
 
132
140
  def test_methods(api):
133
141
  res = api.get("/who-am-i", login="susie", status=200, cookies={"lang": "it"})
File without changes
File without changes
File without changes
File without changes