From 2aa1258500507b6a46d08952628d9dca18b0da79 Mon Sep 17 00:00:00 2001 From: CasVT Date: Mon, 25 Aug 2025 21:43:01 +0200 Subject: [PATCH] Refactored ui.py --- frontend/ui.py | 59 +++++++++++++++++++++------------------ tests/Tbackend/ui_test.py | 21 -------------- 2 files changed, 32 insertions(+), 48 deletions(-) delete mode 100644 tests/Tbackend/ui_test.py diff --git a/frontend/ui.py b/frontend/ui.py index a51a8f7..0d46a19 100644 --- a/frontend/ui.py +++ b/frontend/ui.py @@ -9,53 +9,58 @@ from flask import Blueprint, render_template, send_file from backend.internals.server import Server ui = Blueprint('ui', __name__) -methods = ['GET'] def render(filename: str, **kwargs: Any) -> str: return render_template(filename, url_prefix=Server.url_prefix, **kwargs) -@ui.route('/manifest.json', methods=methods) +@ui.route('/manifest.json') def ui_manifest(): - return send_file( - BytesIO(dumps( + # autopep8: off + manifest = { + "name": "MIND", + "short_name": "MIND", + "description": + "MIND is a simple self hosted reminder application that can send " + "push notifications to your device. Set the reminder and forget " + "about it!", + "display": "standalone", + "orientation": "portrait-primary", + "start_url": f"{Server.url_prefix}/", + "scope": f"{Server.url_prefix}/", + "id": f"{Server.url_prefix}/", + "background_color": "#1b1b1b", + "theme_color": "#6b6b6b", + "icons": [ { - "name": "MIND", - "short_name": "MIND", - "description": "MIND is a simple self hosted reminder application that can send push notifications to your device. Set the reminder and forget about it!", - "display": "standalone", - "orientation": "portrait-primary", - "start_url": f"{Server.url_prefix}/", - "scope": f"{Server.url_prefix}/", - "id": f"{Server.url_prefix}/", - "background_color": "#1b1b1b", - "theme_color": "#6b6b6b", - "icons": [ - { - "src": f"{Server.url_prefix}/static/img/favicon.svg", - "type": "image/svg+xml", - "sizes": "any" - } - ] - }, - indent=4 - ).encode('utf-8')), + "src": f"{Server.url_prefix}/static/img/favicon.svg", + "type": "image/svg+xml", + "sizes": "any" + } + ] + } + # autopep8: on + + return send_file( + BytesIO( + dumps(manifest, indent=4).encode('utf-8') + ), mimetype="application/manifest+json", download_name="manifest.json" ), 200 -@ui.route('/', methods=methods) +@ui.route('/') def ui_login(): return render('login.html') -@ui.route('/reminders', methods=methods) +@ui.route('/reminders') def ui_reminders(): return render('reminders.html') -@ui.route('/admin', methods=methods) +@ui.route('/admin') def ui_admin(): return render('admin.html') diff --git a/tests/Tbackend/ui_test.py b/tests/Tbackend/ui_test.py deleted file mode 100644 index 332b79b..0000000 --- a/tests/Tbackend/ui_test.py +++ /dev/null @@ -1,21 +0,0 @@ -import unittest - -from flask import Blueprint, Flask - -from frontend.ui import methods, ui - - -class Test_UI(unittest.TestCase): - def test_methods(self): - self.assertEqual(len(methods), 1) - self.assertEqual(methods[0], 'GET') - - def test_blueprint(self): - self.assertIsInstance(ui, Blueprint) - - def test_route_methods(self): - temp_app = Flask(__name__) - temp_app.register_blueprint(ui) - for rule in temp_app.url_map.iter_rules(): - self.assertEqual(len(rule.methods or []), 3) - self.assertIn(methods[0], rule.methods or [])