From a1f78619fa95f985ec1a909c98ff48e9d771c1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Tue, 13 Jun 2023 01:05:13 +0200 Subject: [PATCH] refactor tests --- tests/conftest.py | 8 ++++---- tests/test_login.py | 4 ++-- tests/test_main.py | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cf4a54d..01d2cf4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,21 +36,21 @@ def auth(client): @pytest.fixture def app(admin_user, admin_password): - socketio, app = application.create_app("testing") + app = application.create_app("testing") app.test_client_class = FlaskLoginClient with app.app_context(): db_seed(db, admin_user, admin_password) - return socketio, app + return app @pytest.fixture def client(app): - return app[1].test_client() + return app.test_client() @pytest.fixture def runner(app): - return app[1].test_cli_runner() + return app.test_cli_runner() @pytest.fixture diff --git a/tests/test_login.py b/tests/test_login.py index bec1005..8f52aa3 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -2,7 +2,7 @@ from flask import session, g, url_for def test_login(app, client, auth, admin_user, admin_password): - with app[1].test_request_context(): + with app.test_request_context(): url_login = url_for("main.login") url_index = url_for("main.index") @@ -34,7 +34,7 @@ def test_login_invalid(auth, admin_user): def test_access_page_not_logged(client, app, auth, guest_user, guest_password): - with app[1].test_request_context(): + with app.test_request_context(): url_login = url_for("main.login") url_config = url_for("main.config") # Check if a not logged in user is redirected to login with next param diff --git a/tests/test_main.py b/tests/test_main.py index ab5270b..202105b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,9 +2,9 @@ from flask import url_for, g from beflask import app -# def test_config_init(): -# assert not app.create_app()[1].testing -# assert app.create_app("testing")[1].testing +def test_config_init(): + assert not app.create_app().testing + assert app.create_app("testing").testing def test_index(client): @@ -30,7 +30,7 @@ def test_index_logged(client, auth): def test_set_benchmark_guest(client, auth, app): assert auth.login(follow_redirects=True).status_code == 200 - with app[1].test_request_context(): + with app.test_request_context(): url = url_for("main.set_benchmark", benchmark_id=1) with client: response = client.get(url, follow_redirects=True) @@ -51,7 +51,7 @@ def test_set_benchmark_admin(client, auth, app, admin_user, admin_password): ).status_code == 200 ) - with app[1].test_request_context(): + with app.test_request_context(): url = url_for("main.set_benchmark", benchmark_id=1) with client: response = client.get(url, follow_redirects=True) @@ -94,7 +94,7 @@ def test_config(app, client, auth): "framework": "HTML Framework default used in be_flask command", } assert auth.login(follow_redirects=True).status_code == 200 - with app[1].test_request_context(): + with app.test_request_context(): url = url_for("main.config") with client: response = client.get(url)