FlaskTester 3.1__tar.gz → 3.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: 3.1
3
+ Version: 3.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
@@ -46,7 +46,7 @@ Requires-Dist: myst_parser; extra == "doc"
46
46
  This package allows to run authenticated tests against a Flask application,
47
47
  either with internal Flask tests (aka `test_client`) or external tests (with
48
48
  `requests` which performs actual HTTP requests), including password and token
49
- authentication.
49
+ authentication and per-user cookies.
50
50
 
51
51
  Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
@@ -109,7 +109,7 @@ def test_app_admin(app):
109
109
  This can be run against a (local) server:
110
110
 
111
111
  ```shell
112
- export TEST_SEED="some-random-data" # shared seed
112
+ export TEST_SEED="some-random-data" # shared test seed
113
113
  flask --app app:app run & # start flask app
114
114
  pid=$! # keep pid
115
115
  export FLASK_TESTER_URL="http://localhost:5000" # set app local url
@@ -128,6 +128,11 @@ The above test runs with [`tests/app.py`](tests/app.py)
128
128
  [Flask](https://flask.palletsprojects.com/)
129
129
  REST application back-end with password and token authentication based on
130
130
  [FlaskSimpleAuth](https://pypi.org/project/FlaskSimpleAuth/).
131
+ The code uses _25_ lines of Python for implementing
132
+ password (basic and parameters) and token authentications,
133
+ admin group authorization, and routes for
134
+ token generation (2), identity tests (2) and an incredible open cookie-based
135
+ translation service.
131
136
 
132
137
  ## Fixtures
133
138
 
@@ -155,11 +160,12 @@ The package provides two fixtures:
155
160
  - `FLASK_TESTER_LOG_LEVEL` log level for module,
156
161
  default is `NOTSET`.
157
162
 
158
- The fixture has 3 main methods:
163
+ The fixture has 4 main methods:
159
164
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
160
165
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
161
166
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
162
- - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
167
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
168
+ This method is called automatically for adding credentials to a request.
163
169
 
164
170
  - `ft_client` for app testing, which depends on the previous fixture, plus
165
171
  environment variables which allow to find the application, at least one must
@@ -178,7 +184,7 @@ The package provides two fixtures:
178
184
 
179
185
  The fixture then provides test methods to issue test requests against a Flask application:
180
186
  - `request` generic request with `login`, `auth`, `status` end `content` extensions.
181
- - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
187
+ - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
182
188
  Moreover, `setPass`, `setToken` and `setCookie` are forwarded to the internal authenticator.
183
189
 
184
190
  Authenticator environment variables can be set from the pytest Python test file by
@@ -242,6 +248,15 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
242
248
  see also the [documentation](https://zx80.github.io/flask-tester/),
243
249
  please report any [issues](https://github.com/zx80/flask-tester/issues).
244
250
 
251
+ ### 3.3 on 2024-03-25
252
+
253
+ Fix missing parameter on `check` to ensure upward compatibility.
254
+
255
+ ### 3.2 on 2024-03-24
256
+
257
+ Improved documentation.
258
+ Simpler code and API documentation.
259
+
245
260
  ### 3.1 on 2024-03-24
246
261
 
247
262
  More consistent test and demo code.
@@ -293,7 +293,8 @@ class Client:
293
293
  """Run a request and return response."""
294
294
  raise NotImplementedError()
295
295
 
296
- def request(self, method: str, path: str, status: int|None = None, auth: str|None = None, **kwargs):
296
+ def request(self, method: str, path: str, status: int|None = None, content: str|None = None,
297
+ auth: str|None = None, **kwargs):
297
298
  """Run a possibly authenticated HTTP request.
298
299
 
299
300
  Mandatory parameters:
@@ -304,6 +305,7 @@ class Client:
304
305
  Optional parameters:
305
306
 
306
307
  - ``status``: expected HTTP status, *None* to skip status check
308
+ - ``content``: regular expression for response body, *None* to skip content check
307
309
  - ``login``: authenticated user, use **explicit** *None* to skip
308
310
  - ``auth``: authentication scheme to use instead of default behavior
309
311
  - ``**kwargs``: more request parameters (headers, data, json…)
@@ -323,11 +325,18 @@ class Client:
323
325
  self._auth.setAuth(login, kwargs, cookies, auth=auth)
324
326
  res = self._request(method, path, cookies, **kwargs) # type: ignore
325
327
 
328
+ # check status
326
329
  if status is not None:
327
330
  if res.status_code != status: # show error before aborting
328
331
  log.error(f"bad {status} result: {res.status_code} {res.text[:512]}")
329
332
  assert res.status_code == status, f"unexpected status {res.status_code}, expecting {status}"
330
333
 
334
+ # check content
335
+ if content is not None:
336
+ if not re.search(content, res.text, re.DOTALL):
337
+ log.error(f"cannot find {content} in {res.text}")
338
+ assert False, f"expected content {content} not found in {res.text}"
339
+
331
340
  return res
332
341
 
333
342
  def get(self, path, **kwargs):
@@ -351,31 +360,12 @@ class Client:
351
360
  return self.request("DELETE", path, **kwargs)
352
361
 
353
362
  def check(self, method: str, path: str, status: int, content: str|None = None, **kwargs):
354
- """Run a query and check the response.
355
-
356
- Mandatory parameters:
357
-
358
- - ``method``: HTTP method ("GET", "POST", "PATCH", "DELETE"…)
359
- - ``path``: local path under the base URL
360
- - ``status``: expected HTTP status
363
+ """Run a query and check the response status.
361
364
 
362
- Optional parameters:
363
-
364
- - ``content``: regular expression in response body
365
- - ``login``: authenticated user, use explicit *None* to skip
366
- - ``**kwargs``: more request parameters (headers, data, json…)
365
+ Same as ``request``, but ``status`` is mandatory.
367
366
  """
368
367
 
369
- # get HTTP response
370
- res = self.request(method, path, status=status, **kwargs)
371
-
372
- # check contents
373
- if content is not None:
374
- if not re.search(content, res.text, re.DOTALL):
375
- log.error(f"cannot find {content} in {res.text}")
376
- assert False, f"expected content {content} not found in {res.text}"
377
-
378
- return res
368
+ return self.request(method, path, status=status, content=content, **kwargs)
379
369
 
380
370
 
381
371
  class RequestClient(Client):
@@ -496,7 +486,7 @@ def ft_authenticator():
496
486
  Default is ``NOTSET``.
497
487
  - ``FLASK_TESTER_ALLOW``: allowed space-separated authentication schemes, in
498
488
  ``basic param bearer header cookie tparam fake none``.
499
- Default is ``bearer basic param``.
489
+ Default is ``bearer basic param none``.
500
490
  - ``FLASK_TESTER_USER``: user login parameter for ``param`` authentication.
501
491
  Default is ``USER``.
502
492
  - ``FLASK_TESTER_PASS``: user password parameter for ``param`` authentication.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlaskTester
3
- Version: 3.1
3
+ Version: 3.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
@@ -46,7 +46,7 @@ Requires-Dist: myst_parser; extra == "doc"
46
46
  This package allows to run authenticated tests against a Flask application,
47
47
  either with internal Flask tests (aka `test_client`) or external tests (with
48
48
  `requests` which performs actual HTTP requests), including password and token
49
- authentication.
49
+ authentication and per-user cookies.
50
50
 
51
51
  Only one set of tests is needed, switching from internal to external is
52
52
  achieved through environment variables.
@@ -109,7 +109,7 @@ def test_app_admin(app):
109
109
  This can be run against a (local) server:
110
110
 
111
111
  ```shell
112
- export TEST_SEED="some-random-data" # shared seed
112
+ export TEST_SEED="some-random-data" # shared test seed
113
113
  flask --app app:app run & # start flask app
114
114
  pid=$! # keep pid
115
115
  export FLASK_TESTER_URL="http://localhost:5000" # set app local url
@@ -128,6 +128,11 @@ The above test runs with [`tests/app.py`](tests/app.py)
128
128
  [Flask](https://flask.palletsprojects.com/)
129
129
  REST application back-end with password and token authentication based on
130
130
  [FlaskSimpleAuth](https://pypi.org/project/FlaskSimpleAuth/).
131
+ The code uses _25_ lines of Python for implementing
132
+ password (basic and parameters) and token authentications,
133
+ admin group authorization, and routes for
134
+ token generation (2), identity tests (2) and an incredible open cookie-based
135
+ translation service.
131
136
 
132
137
  ## Fixtures
133
138
 
@@ -155,11 +160,12 @@ The package provides two fixtures:
155
160
  - `FLASK_TESTER_LOG_LEVEL` log level for module,
156
161
  default is `NOTSET`.
157
162
 
158
- The fixture has 3 main methods:
163
+ The fixture has 4 main methods:
159
164
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
160
165
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
161
166
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
162
- - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
167
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
168
+ This method is called automatically for adding credentials to a request.
163
169
 
164
170
  - `ft_client` for app testing, which depends on the previous fixture, plus
165
171
  environment variables which allow to find the application, at least one must
@@ -178,7 +184,7 @@ The package provides two fixtures:
178
184
 
179
185
  The fixture then provides test methods to issue test requests against a Flask application:
180
186
  - `request` generic request with `login`, `auth`, `status` end `content` extensions.
181
- - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
187
+ - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
182
188
  Moreover, `setPass`, `setToken` and `setCookie` are forwarded to the internal authenticator.
183
189
 
184
190
  Authenticator environment variables can be set from the pytest Python test file by
@@ -242,6 +248,15 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
242
248
  see also the [documentation](https://zx80.github.io/flask-tester/),
243
249
  please report any [issues](https://github.com/zx80/flask-tester/issues).
244
250
 
251
+ ### 3.3 on 2024-03-25
252
+
253
+ Fix missing parameter on `check` to ensure upward compatibility.
254
+
255
+ ### 3.2 on 2024-03-24
256
+
257
+ Improved documentation.
258
+ Simpler code and API documentation.
259
+
245
260
  ### 3.1 on 2024-03-24
246
261
 
247
262
  More consistent test and demo code.
@@ -3,7 +3,7 @@
3
3
  This package allows to run authenticated tests against a Flask application,
4
4
  either with internal Flask tests (aka `test_client`) or external tests (with
5
5
  `requests` which performs actual HTTP requests), including password and token
6
- authentication.
6
+ authentication and per-user cookies.
7
7
 
8
8
  Only one set of tests is needed, switching from internal to external is
9
9
  achieved through environment variables.
@@ -66,7 +66,7 @@ def test_app_admin(app):
66
66
  This can be run against a (local) server:
67
67
 
68
68
  ```shell
69
- export TEST_SEED="some-random-data" # shared seed
69
+ export TEST_SEED="some-random-data" # shared test seed
70
70
  flask --app app:app run & # start flask app
71
71
  pid=$! # keep pid
72
72
  export FLASK_TESTER_URL="http://localhost:5000" # set app local url
@@ -85,6 +85,11 @@ The above test runs with [`tests/app.py`](tests/app.py)
85
85
  [Flask](https://flask.palletsprojects.com/)
86
86
  REST application back-end with password and token authentication based on
87
87
  [FlaskSimpleAuth](https://pypi.org/project/FlaskSimpleAuth/).
88
+ The code uses _25_ lines of Python for implementing
89
+ password (basic and parameters) and token authentications,
90
+ admin group authorization, and routes for
91
+ token generation (2), identity tests (2) and an incredible open cookie-based
92
+ translation service.
88
93
 
89
94
  ## Fixtures
90
95
 
@@ -112,11 +117,12 @@ The package provides two fixtures:
112
117
  - `FLASK_TESTER_LOG_LEVEL` log level for module,
113
118
  default is `NOTSET`.
114
119
 
115
- The fixture has 3 main methods:
120
+ The fixture has 4 main methods:
116
121
  - `setPass` to associate a password to a user, set to _None_ to remove credential.
117
122
  - `setToken` to associate a token to a user, set to _None_ to remove credential.
118
123
  - `setCookie` to add a cookie to a user, set value to _None_ to remove cookie.
119
- - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
124
+ - `setAuth` to add authentication data to a request `kwargs` and `cookies`.
125
+ This method is called automatically for adding credentials to a request.
120
126
 
121
127
  - `ft_client` for app testing, which depends on the previous fixture, plus
122
128
  environment variables which allow to find the application, at least one must
@@ -135,7 +141,7 @@ The package provides two fixtures:
135
141
 
136
142
  The fixture then provides test methods to issue test requests against a Flask application:
137
143
  - `request` generic request with `login`, `auth`, `status` end `content` extensions.
138
- - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
144
+ - `get post put patch delete` methods with `login`, `auth` and `status` extensions.
139
145
  Moreover, `setPass`, `setToken` and `setCookie` are forwarded to the internal authenticator.
140
146
 
141
147
  Authenticator environment variables can be set from the pytest Python test file by
@@ -199,6 +205,15 @@ Packages are distributed from [PyPI](https://pypi.org/project/FlaskTester/),
199
205
  see also the [documentation](https://zx80.github.io/flask-tester/),
200
206
  please report any [issues](https://github.com/zx80/flask-tester/issues).
201
207
 
208
+ ### 3.3 on 2024-03-25
209
+
210
+ Fix missing parameter on `check` to ensure upward compatibility.
211
+
212
+ ### 3.2 on 2024-03-24
213
+
214
+ Improved documentation.
215
+ Simpler code and API documentation.
216
+
202
217
  ### 3.1 on 2024-03-24
203
218
 
204
219
  More consistent test and demo code.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "FlaskTester"
7
- version = "3.1"
7
+ version = "3.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"
File without changes
File without changes
File without changes
File without changes