diff --git a/app/src/web/log_files.py b/app/src/web/log_files.py index 82fe0c4..fccbd7e 100644 --- a/app/src/web/log_files.py +++ b/app/src/web/log_files.py @@ -50,3 +50,12 @@ async def send(file): directory=Config.get_log_path(), file_name=secure_filename(file), as_attachment=True) + + +@web.route('/del-file/', methods=['DELETE']) +async def delete(file): + try: + os.remove(Config.get_log_path() + secure_filename(file)) + except OSError: + return 'File not found', 404 + return '', 204 diff --git a/app/src/web/templates/page_logging.html.j2 b/app/src/web/templates/page_logging.html.j2 index 701b3b5..99064a6 100644 --- a/app/src/web/templates/page_logging.html.j2 +++ b/app/src/web/templates/page_logging.html.j2 @@ -4,7 +4,27 @@ {% block menu3_class %}w3-blue{% endblock %} {% block headline %}  {{_('Log Files')}}{% endblock headline %} {% block content %} +
+
+
+

{{_("Do you really want to delete the log file")}}:
?

+
+ +
+
+
+
+
+ + {% endblock content%} {% block footer %}{% endblock footer %} diff --git a/app/src/web/templates/templ_log_files_list.html.j2 b/app/src/web/templates/templ_log_files_list.html.j2 index 9df7ee5..fad9be7 100644 --- a/app/src/web/templates/templ_log_files_list.html.j2 +++ b/app/src/web/templates/templ_log_files_list.html.j2 @@ -3,7 +3,7 @@
-
+

{{file.name}}

@@ -17,7 +17,9 @@
diff --git a/app/tests/test_web_route.py b/app/tests/test_web_route.py index 9b36649..5e51e1b 100644 --- a/app/tests/test_web_route.py +++ b/app/tests/test_web_route.py @@ -6,6 +6,8 @@ from async_stream import AsyncStreamClient from gen3plus.inverter_g3p import InverterG3P from test_inverter_g3p import FakeReader, FakeWriter, config_conn from cnf.config import Config +from mock import patch +import os, errno pytest_plugins = ('pytest_asyncio',) @@ -206,3 +208,39 @@ async def test_invalid_send_file(client, config_conn): assert Config.log_path == 'app/tests/log/' response = await client.get('/send-file/../test_web_route.py') assert response.status_code == 404 + +@pytest.fixture +def patch_os_remove_err(): + def new_remove(file_path: str): + raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), file_path) + + + with patch.object(os, 'remove', new_remove) as wrapped_os: + yield wrapped_os + +@pytest.fixture +def patch_os_remove_ok(): + def new_remove(file_path: str): + return + + with patch.object(os, 'remove', new_remove) as wrapped_os: + yield wrapped_os + +@pytest.mark.asyncio +async def test_del_file_ok(client, config_conn, patch_os_remove_ok): + """Test the del-file route with no error.""" + _ = config_conn + _ = patch_os_remove_ok + assert Config.log_path == 'app/tests/log/' + response = await client.delete ('/del-file/test.txt') + assert response.status_code == 204 + + +@pytest.mark.asyncio +async def test_del_file_err(client, config_conn, patch_os_remove_err): + """Test the send-file route with OSError.""" + _ = config_conn + _ = patch_os_remove_err + assert Config.log_path == 'app/tests/log/' + response = await client.delete ('/del-file/test.txt') + assert response.status_code == 404 diff --git a/app/translations/de/LC_MESSAGES/messages.po b/app/translations/de/LC_MESSAGES/messages.po index b09eca8..42a900c 100644 --- a/app/translations/de/LC_MESSAGES/messages.po +++ b/app/translations/de/LC_MESSAGES/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: tsun-gen3-proxy 0.14.0\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2025-05-01 17:48+0200\n" +"POT-Creation-Date: 2025-05-02 17:00+0200\n" "PO-Revision-Date: 2025-04-18 16:24+0200\n" "Last-Translator: FULL NAME \n" "Language: de\n" @@ -88,6 +88,18 @@ msgstr "Emu Modus" msgid "Emulation sends data to cloud" msgstr "Emulation sendet in die Cloud" +#: src/web/templates/page_logging.html.j2:10 +msgid "Do you really want to delete the log file" +msgstr "Soll die Datei wirklich gelöscht werden" + +#: src/web/templates/page_logging.html.j2:12 +msgid "Delete File