Compare commits
6 Commits
s-allius/i
...
s-allius/i
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
514c0c4985 | ||
|
|
5460f6f6f9 | ||
|
|
b081060033 | ||
|
|
f3e61ba18e | ||
|
|
14042ef3ac | ||
|
|
97b19a6ffc |
@@ -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/<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
|
||||
|
||||
@@ -4,7 +4,27 @@
|
||||
{% block menu3_class %}w3-blue{% endblock %}
|
||||
{% block headline %}<i class="fa fa-file-export fa-fw"></i> {{_('Log Files')}}{% endblock headline %}
|
||||
{% block content %}
|
||||
<div id="id01" class="w3-modal">
|
||||
<div class="w3-modal-content" style="width:600px">
|
||||
<div class="w3-container w3-padding-24">
|
||||
<h2>{{_("Do you really want to delete the log file")}}:<br><b><span id="id03"></span></b> ?</h2>
|
||||
<div class="w3-bar">
|
||||
<button id="id02" class="w3-button w3-red" onclick="deleteFile(); document.getElementById('id01').style.display='none'">{{_('Delete File</button')}}>
|
||||
<button class="w3-button w3-grey w3-right" onclick="document.getElementById('id01').style.display='none'">{{_('Abort')}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w3-container" id="file-list"></div>
|
||||
|
||||
<script>
|
||||
function deleteFile() {
|
||||
fname = document.getElementById('id02').href;
|
||||
fetch(fname, {method: 'DELETE'})
|
||||
.then(fetch_data())
|
||||
}
|
||||
</script>
|
||||
{% endblock content%}
|
||||
|
||||
{% block footer %}{% endblock footer %}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="w3-quarter w3-margin-bottom">
|
||||
|
||||
<div class="w3-card-4">
|
||||
<header class="w3-container w3-blue">
|
||||
<header class="w3-container w3-blue" style="min-height:80px">
|
||||
<h4>{{file.name}}</h4>
|
||||
</header>
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
</table>
|
||||
|
||||
<footer class="w3-blue">
|
||||
<a href="{{ url_for('web.send',file=file.name)}}" class="w3-button w3-hover-blue w3-hover-text-black"><i class="fa fa-file-export"></i> {{_('Download File')}}</a>
|
||||
<a href="{{ url_for('.send',file=file.name)}}" class="w3-button w3-hover-blue w3-hover-text-black"><i class="fa fa-file-download"></i> {{_('Download File')}}</a>
|
||||
<a class="w3-button w3-right w3-hover-blue w3-hover-text-black"
|
||||
onclick="document.getElementById('id03').innerHTML='{{file.name}}'; document.getElementById('id02').href='{{ url_for('.delete',file=file.name)}}'; document.getElementById('id01').style.display='block';"><i class="fa fa-trash"></i></a>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <EMAIL@ADDRESS>\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</button"
|
||||
msgstr "File löschen"
|
||||
|
||||
#: src/web/templates/page_logging.html.j2:13
|
||||
msgid "Abort"
|
||||
msgstr "Abbruch"
|
||||
|
||||
#: src/web/templates/templ_log_files_list.html.j2:11
|
||||
msgid "Created"
|
||||
msgstr "Erzeugt"
|
||||
@@ -104,4 +116,3 @@ msgstr "Größe"
|
||||
msgid "Download File"
|
||||
msgstr "Datei Download"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user