From 1a582eaddaeece1a05e065a41e62d081db4824e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Tue, 11 Jul 2023 17:00:46 +0200 Subject: [PATCH] Fixes missing imports and undefined variables with ruff --- pyproject.toml | 1 + web/flaskr/__init__.py | 5 +---- web/flaskr/models.py | 2 ++ web/flaskr/routes.py | 2 +- web/misc/gunicorn.py | 4 +++- web/tests/meeting/test_join.py | 20 ++++++-------------- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5ff2c22d..d7a4e287 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,4 +63,5 @@ testpaths = "web" ignore = [ "E501", # line too long "E722", # bare expect + "E402", # import not at the top of the file ] diff --git a/web/flaskr/__init__.py b/web/flaskr/__init__.py index 52d85942..4680f9dc 100755 --- a/web/flaskr/__init__.py +++ b/web/flaskr/__init__.py @@ -57,6 +57,7 @@ def global_processor(): "config": app.config, "beta": app.config["BETA"], "documentation_link": app.config["DOCUMENTATION_LINK"], + "LANGUAGES": LANGUAGES, **app.config["WORDINGS"], } @@ -67,10 +68,6 @@ def global_processor(): csrf = CSRFProtect() csrf.init_app(app) - @app.context_processor - def global_processor(): - return {"LANGUAGES": LANGUAGES} - # init database with app.app_context(): import flaskr.routes diff --git a/web/flaskr/models.py b/web/flaskr/models.py index 0a98d168..3e3f9506 100755 --- a/web/flaskr/models.py +++ b/web/flaskr/models.py @@ -24,6 +24,8 @@ from datetime import date, datetime, timedelta, timezone from flaskr.utils import secret_key +import os + db = SQLAlchemy() diff --git a/web/flaskr/routes.py b/web/flaskr/routes.py index 2c3440fc..9e6f8d2b 100755 --- a/web/flaskr/routes.py +++ b/web/flaskr/routes.py @@ -914,7 +914,7 @@ def add_meeting_file_nextcloud(path, meeting_id, is_default): return jsonify( status=500, isfrom="nextcloud", - msg=f"Fichier {title} TROP VOLUMINEUX, ne pas dépasser 20Mo", + msg=f"Fichier {path} TROP VOLUMINEUX, ne pas dépasser 20Mo", ) meetingFile = MeetingFiles() diff --git a/web/misc/gunicorn.py b/web/misc/gunicorn.py index 475be7fa..a6aadd95 100644 --- a/web/misc/gunicorn.py +++ b/web/misc/gunicorn.py @@ -203,7 +203,9 @@ def when_ready(server): def worker_int(worker): worker.log.info("worker received INT or QUIT signal") ## get traceback info - import threading, sys, traceback + import threading + import sys + import traceback id2name = {th.ident: th.name for th in threading.enumerate()} code = [] diff --git a/web/tests/meeting/test_join.py b/web/tests/meeting/test_join.py index 31d4a835..6355ec38 100644 --- a/web/tests/meeting/test_join.py +++ b/web/tests/meeting/test_join.py @@ -62,22 +62,14 @@ def test_auth_attendee_disabled(client_app, app, meeting): the attendee authentication step. https://github.com/numerique-gouv/b3desk/issues/9 """ - # TODO: refactor this test with modern test conventions when #6 is merged - app.config["OIDC_ATTENDEE_ENABLED"] = False + meeting_hash = meeting.get_hash("authenticated") - with app.app_context(): - user_id = 1 - meeting = Meeting.query.get(1) - meeting_id = meeting.id - meeting_hash = meeting.get_hash("authenticated") - - url = f"/meeting/signin/{meeting_id}/creator/{user_id}/hash/{meeting_hash}" - response = client_app.get(url) - - assert response.status_code == 200 - form_action_url = "/meeting/join" - assert form_action_url in response.data.decode() + url = f"/meeting/signin/{meeting.id}/creator/{meeting.user.id}/hash/{meeting_hash}" + response = client_app.get( + url, extra_environ={"REMOTE_ADDR": "127.0.0.1"}, status=200 + ) + response.mustcontain("/meeting/join") def test_join_meeting_as_authenticated_attendee(