From 53316c2ce92343b8329fb8b03978bdcee3577b75 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:36:11 +0200 Subject: [PATCH] Black formatting --- src/stacosys/interface/__init__.py | 6 +++--- src/stacosys/interface/form.py | 2 +- src/stacosys/interface/web/admin.py | 16 +++++++++------- src/stacosys/run.py | 12 +++++++----- src/stacosys/service/mail.py | 4 +++- tests/test_config.py | 4 ++-- tests/test_form.py | 6 +++--- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/stacosys/interface/__init__.py b/src/stacosys/interface/__init__.py index c6211a4..fb1fbd1 100644 --- a/src/stacosys/interface/__init__.py +++ b/src/stacosys/interface/__init__.py @@ -19,7 +19,7 @@ logger = logging.getLogger(__name__) @background.task def submit_new_comment(comment): - site_url = app.config['CONFIG'].get(ConfigParameter.SITE_URL) + site_url = app.config["CONFIG"].get(ConfigParameter.SITE_URL) comment_list = ( f"Web admin interface: {site_url}/web/admin", "", @@ -34,9 +34,9 @@ def submit_new_comment(comment): email_body = "\n".join(comment_list) # send email to notify admin - site_name = app.config['CONFIG'].get(ConfigParameter.SITE_NAME) + site_name = app.config["CONFIG"].get(ConfigParameter.SITE_NAME) subject = f"STACOSYS {site_name}" - if app.config['MAILER'].send(subject, email_body): + if app.config["MAILER"].send(subject, email_body): logger.debug("new comment processed") # save notification datetime dao.notify_comment(comment) diff --git a/src/stacosys/interface/form.py b/src/stacosys/interface/form.py index 72e5e52..11d2ca3 100644 --- a/src/stacosys/interface/form.py +++ b/src/stacosys/interface/form.py @@ -46,7 +46,7 @@ def new_form_comment(): # send notification e-mail asynchronously submit_new_comment(comment) - return redirect(app.config['CONFIG'].get(ConfigParameter.SITE_REDIRECT), code=302) + return redirect(app.config["CONFIG"].get(ConfigParameter.SITE_REDIRECT), code=302) def check_form_data(posted_comment): diff --git a/src/stacosys/interface/web/admin.py b/src/stacosys/interface/web/admin.py index 4c8b9dd..64aa3da 100644 --- a/src/stacosys/interface/web/admin.py +++ b/src/stacosys/interface/web/admin.py @@ -24,8 +24,8 @@ def index(): def is_login_ok(username, password): hashed = hashlib.sha256(password.encode()).hexdigest().upper() return ( - app.config['CONFIG'].get(ConfigParameter.WEB_USERNAME) == username - and app.config['CONFIG'].get(ConfigParameter.WEB_PASSWORD) == hashed + app.config["CONFIG"].get(ConfigParameter.WEB_USERNAME) == username + and app.config["CONFIG"].get(ConfigParameter.WEB_PASSWORD) == hashed ) @@ -41,7 +41,9 @@ def login(): flash("Identifiant ou mot de passe incorrect") return redirect("/web/login") # GET - return render_template("login_" + app.config['CONFIG'].get(ConfigParameter.LANG) + ".html") + return render_template( + "login_" + app.config["CONFIG"].get(ConfigParameter.LANG) + ".html" + ) @app.route("/web/logout", methods=["GET"]) @@ -54,7 +56,7 @@ def logout(): def admin_homepage(): if not ( "user" in session - and session["user"] == app.config['CONFIG'].get(ConfigParameter.WEB_USERNAME) + and session["user"] == app.config["CONFIG"].get(ConfigParameter.WEB_USERNAME) ): # TODO localization flash("Vous avez été déconnecté.") @@ -62,9 +64,9 @@ def admin_homepage(): comments = dao.find_not_published_comments() return render_template( - "admin_" + app.config['CONFIG'].get(ConfigParameter.LANG) + ".html", + "admin_" + app.config["CONFIG"].get(ConfigParameter.LANG) + ".html", comments=comments, - baseurl=app.config['CONFIG'].get(ConfigParameter.SITE_URL), + baseurl=app.config["CONFIG"].get(ConfigParameter.SITE_URL), ) @@ -76,7 +78,7 @@ def admin_action(): flash("Commentaire introuvable") elif request.form.get("action") == "APPROVE": dao.publish_comment(comment) - app.config['RSS'].generate() + app.config["RSS"].generate() # TODO localization flash("Commentaire publié") else: diff --git a/src/stacosys/run.py b/src/stacosys/run.py index ae7b81b..5634764 100644 --- a/src/stacosys/run.py +++ b/src/stacosys/run.py @@ -9,14 +9,16 @@ import sys from stacosys.db import database from stacosys.interface import api, app, form from stacosys.interface.web import admin +from stacosys.service.configuration import Config, ConfigParameter from stacosys.service.mail import Mailer from stacosys.service.rssfeed import Rss -from stacosys.service.configuration import Config, ConfigParameter # configure logging def configure_logging() -> logging.Logger: - logging.basicConfig(level=logging.INFO, format="[%(asctime)s] %(name)s %(levelname)s %(message)s") + logging.basicConfig( + level=logging.INFO, format="[%(asctime)s] %(name)s %(levelname)s %(message)s" + ) logger = logging.getLogger(__name__) logging.getLogger("werkzeug").level = logging.WARNING return logger @@ -72,9 +74,9 @@ def main(config_pathname): mailer = configure_and_validate_mailer(config, logger) logger.info("start interfaces %s %s %s", api, form, admin) - app.config['CONFIG'] = config - app.config['MAILER'] = mailer - app.config['RSS'] = rss + app.config["CONFIG"] = config + app.config["MAILER"] = mailer + app.config["RSS"] = rss app.run( host=config.get(ConfigParameter.HTTP_HOST), port=config.get_int(ConfigParameter.HTTP_PORT), diff --git a/src/stacosys/service/mail.py b/src/stacosys/service/mail.py index ad3530c..4e52228 100644 --- a/src/stacosys/service/mail.py +++ b/src/stacosys/service/mail.py @@ -16,7 +16,9 @@ class Mailer: self._smtp_password = "" self._site_admin_email = "" - def configure_smtp(self, smtp_host: str, smtp_port: int, smtp_login: str, smtp_password: str) -> None: + def configure_smtp( + self, smtp_host: str, smtp_port: int, smtp_login: str, smtp_password: str + ) -> None: self._smtp_host = smtp_host self._smtp_port = smtp_port self._smtp_login = smtp_login diff --git a/tests/test_config.py b/tests/test_config.py index ecee23f..78a2da4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,8 +3,7 @@ import pytest -from stacosys.service.configuration import Config -from stacosys.service.configuration import ConfigParameter +from stacosys.service.configuration import Config, ConfigParameter EXPECTED_DB = "sqlite://db.sqlite" EXPECTED_HTTP_PORT = 8080 @@ -12,6 +11,7 @@ EXPECTED_LANG = "fr" config = Config() + @pytest.fixture def init_config(): config.put(ConfigParameter.DB, EXPECTED_DB) diff --git a/tests/test_form.py b/tests/test_form.py index 875dbf6..f87a172 100644 --- a/tests/test_form.py +++ b/tests/test_form.py @@ -17,9 +17,9 @@ def client(): logger = logging.getLogger(__name__) database.configure("sqlite:memory://db.sqlite") logger.info(f"start interface {form}") - app.config['CONFIG'] = Config() - app.config['MAILER'] = Mailer() - app.config['RSS'] = Rss() + app.config["CONFIG"] = Config() + app.config["MAILER"] = Mailer() + app.config["RSS"] = Rss() return app.test_client()