|
18 | 18 | }
|
19 | 19 |
|
20 | 20 |
|
| 21 | +def test_specification__factory_app(): |
| 22 | + def mini_endpoint() -> dict: |
| 23 | + return {'message': 'test_factory_app'} |
| 24 | + |
| 25 | + first = First(Path(BASEDIR, 'specs/v3.1.0/mini.openapi.yaml')) |
| 26 | + |
| 27 | + def create_app(): |
| 28 | + flask_app = Flask('factory_app') |
| 29 | + first.init_app(flask_app) |
| 30 | + first.add_view_func(mini_endpoint) |
| 31 | + return flask_app |
| 32 | + |
| 33 | + app = create_app() |
| 34 | + |
| 35 | + with app.test_client() as test_client: |
| 36 | + r = test_client.get('/mini_endpoint') |
| 37 | + assert r.status_code == 200 |
| 38 | + assert r.json['message'] == 'test_factory_app' |
| 39 | + |
| 40 | + |
| 41 | +def test_flask_first__swagger_ui(fx_create_app): |
| 42 | + def mini_endpoint() -> dict: |
| 43 | + return {'message': 'test_flask_first__swagger_ui'} |
| 44 | + |
| 45 | + test_client = fx_create_app(Path(BASEDIR, 'specs/v3.1.0/mini.openapi.yaml'), [mini_endpoint]) |
| 46 | + |
| 47 | + r = test_client.get('/docs/openapi.json') |
| 48 | + assert r.status_code == 200 |
| 49 | + assert r.text |
| 50 | + |
| 51 | + r = test_client.get('/docs', follow_redirects=True) |
| 52 | + assert r.status_code == 200 |
| 53 | + assert '<title>Swagger UI</title>' in r.text |
| 54 | + |
| 55 | + |
| 56 | +# Old test |
| 57 | + |
| 58 | + |
21 | 59 | def test_specification__create_item(fx_app, fx_client):
|
22 | 60 | def create_item() -> tuple:
|
23 | 61 | obj = {**request.json, 'uuid': ITEM['uuid']}
|
@@ -218,29 +256,6 @@ def endpoint_with_header() -> dict:
|
218 | 256 | assert r.json['message'] == 'test_header'
|
219 | 257 |
|
220 | 258 |
|
221 |
| -def test_specification__factory_app(): |
222 |
| - def mini_endpoint() -> dict: |
223 |
| - return {'message': 'test_factory_app'} |
224 |
| - |
225 |
| - first = First(Path(BASEDIR, 'specs/v3.1.0/mini.openapi.yaml')) |
226 |
| - |
227 |
| - def create_app(): |
228 |
| - app = Flask('factory_app') |
229 |
| - app.debug = 1 |
230 |
| - app.testing = 1 |
231 |
| - app.config['FIRST_RESPONSE_VALIDATION'] = True |
232 |
| - first.init_app(app) |
233 |
| - first.add_view_func(mini_endpoint) |
234 |
| - return app |
235 |
| - |
236 |
| - app = create_app() |
237 |
| - |
238 |
| - with app.test_client() as test_client: |
239 |
| - r = test_client.get('/mini_endpoint') |
240 |
| - assert r.status_code == 200 |
241 |
| - assert r.json['message'] == 'test_factory_app' |
242 |
| - |
243 |
| - |
244 | 259 | def test_specification__registration_function():
|
245 | 260 | def mini_endpoint() -> dict:
|
246 | 261 | return {'message': 'test_factory_app'}
|
|
0 commit comments