Compare commits

..

18 Commits

Author SHA1 Message Date
Stefan Allius
c6a5490229 update changelog 2025-05-10 19:27:56 +02:00
Stefan Allius
bdf08f64a1 update changelog 2025-05-10 19:25:25 +02:00
Stefan Allius
25145a9c29 check print output in test_save_and_restore 2025-05-08 00:23:44 +02:00
Stefan Allius
628f992922 coverage: ignore quart template files 2025-05-08 00:22:49 +02:00
Stefan Allius
fc93930656 add unit test for error handling in build_config() 2025-05-07 23:42:55 +02:00
Stefan Allius
e1f0aac9bf fix deprecated pytest async warning
- Cleanup pending async tasks
- fix deprecated warning about event_loop
2025-05-07 23:37:24 +02:00
Stefan Allius
b321cfce0f add HypercornLogHndl tests 2025-05-07 12:05:58 +02:00
Stefan Allius
cf9911f2f1 test the init_logging_system() method 2025-05-07 11:42:04 +02:00
Stefan Allius
d35c4e7b90 move code from app.py into server.py 2025-05-07 10:26:58 +02:00
Stefan Allius
911d0a9612 add unit tests 2025-05-06 22:23:41 +02:00
Stefan Allius
4012196fcd remove Web() instance from the testcase
- with importing app.py The blueprint Web() will
  automatically created and a second call in test-
  cases must avoided
2025-05-05 23:58:30 +02:00
Stefan Allius
cfe13a01d1 define config in test_emu_init_close 2025-05-05 23:50:20 +02:00
Stefan Allius
ab2d4ed831 move get_log_level into Server class 2025-05-05 23:47:06 +02:00
Stefan Allius
089fb92a43 change proxy into a ASGI application
- move Quart init from server.py into app.py
- create Server class for config and loggin setup
- restore hypercorn logging configuration after
  start of Quart/Hypercorn
2025-05-05 23:35:13 +02:00
Stefan Allius
6560079d89 fix the hypercorn log handler only once 2025-05-05 09:16:14 +02:00
Stefan Allius
4688e6a75b workaround: restore the hypercorn logger config
- quart/hyercorn overwrites the logger config.
  as a workaround we restore the config at the
  beginning of a request
2025-05-05 08:23:41 +02:00
Stefan Allius
4f6764e151 use logger.ini to setup dashboard logger 2025-05-05 08:22:13 +02:00
Stefan Allius
484df1dc46 setup logger for hypercorn and dashboard 2025-05-05 08:21:34 +02:00
5 changed files with 7 additions and 61 deletions

View File

@@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [unreleased] ## [unreleased]
- Update ghcr.io/hassio-addons/base Docker tag to v17.2.5
- fix a lot of pytest-asyncio problems in the unit tests - fix a lot of pytest-asyncio problems in the unit tests
- Cleanup startup code for Quart and the Proxy - Cleanup startup code for Quart and the Proxy
- Redirect the hypercorn traces to a separate log-file - Redirect the hypercorn traces to a separate log-file

View File

@@ -1,58 +1,26 @@
from quart import render_template from quart import render_template
from quart_babel import format_datetime, format_decimal, _ from quart_babel import format_datetime, format_decimal
from quart.helpers import send_from_directory from quart.helpers import send_from_directory
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from cnf.config import Config from cnf.config import Config
from datetime import datetime
from os import DirEntry
import os import os
from dateutil import tz
from . import web from . import web
def _get_birth_from_log(path: str) -> None | datetime: def _get_file(file):
'''read timestamp from the first line of a log file'''
dt = None
try:
with open(path) as f:
first_line = f.readline()
first_line = first_line.lstrip("'")
fmt = "%Y-%m-%d %H:%M:%S" if first_line[4] == '-' \
else "%d-%m-%Y %H:%M:%S"
dt = datetime.strptime(first_line[0:19], fmt). \
replace(tzinfo=tz.tzlocal())
except Exception:
pass
return dt
def _get_file(file: DirEntry) -> dict:
'''build one row for the connection table''' '''build one row for the connection table'''
entry = {} entry = {}
entry['name'] = file.name entry['name'] = file.name
stat = file.stat() stat = file.stat()
entry['size'] = format_decimal(stat.st_size) entry['size'] = format_decimal(stat.st_size)
try: entry['date'] = stat.st_mtime
dt = stat.st_birthtime entry['created'] = format_datetime(stat.st_ctime, format="short")
except Exception:
dt = _get_birth_from_log(file.path)
if dt:
entry['created'] = format_datetime(dt, format="short")
# sort by creating date, if available
entry['date'] = dt if isinstance(dt, float) else dt.timestamp()
else:
entry['created'] = _('n/a')
entry['date'] = stat.st_mtime
entry['modified'] = format_datetime(stat.st_mtime, format="short") entry['modified'] = format_datetime(stat.st_mtime, format="short")
return entry return entry
def get_list_data() -> list: def get_list_data():
'''build the connection table''' '''build the connection table'''
file_list = [] file_list = []
with os.scandir(Config.get_log_path()) as it: with os.scandir(Config.get_log_path()) as it:

View File

@@ -9,8 +9,6 @@ from cnf.config import Config
from mock import patch from mock import patch
from proxy import Proxy from proxy import Proxy
import os, errno import os, errno
from os import DirEntry, stat_result
import datetime
pytest_plugins = ('pytest_asyncio',) pytest_plugins = ('pytest_asyncio',)
@@ -203,33 +201,14 @@ async def test_notes_fetch(client, config_conn):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_file_fetch(client, config_conn, monkeypatch): async def test_file_fetch(client, config_conn):
"""Test the data-fetch route.""" """Test the data-fetch route."""
_ = config_conn _ = config_conn
assert Config.log_path == 'app/tests/log/' assert Config.log_path == 'app/tests/log/'
def my_stat1(*arg):
stat = stat_result
stat.st_size = 20
stat.st_birthtime = datetime.datetime(2024, 1, 31, 10, 30, 15)
stat.st_mtime = datetime.datetime(2024, 1, 1, 1, 30, 15).timestamp()
return stat
monkeypatch.setattr(DirEntry, "stat", my_stat1)
response = await client.get('/file-fetch') response = await client.get('/file-fetch')
assert response.status_code == 200 assert response.status_code == 200
def my_stat2(*arg):
stat = stat_result
stat.st_size = 20
stat.st_mtime = datetime.datetime(2024, 1, 1, 1, 30, 15).timestamp()
return stat
monkeypatch.setattr(DirEntry, "stat", my_stat2)
monkeypatch.delattr(stat_result, "st_birthtime")
response = await client.get('/file-fetch')
assert response.status_code == 200
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_send_file(client, config_conn): async def test_send_file(client, config_conn):
"""Test the send-file route.""" """Test the send-file route."""

View File

@@ -13,7 +13,7 @@
# 1 Build Base Image # # 1 Build Base Image #
###################### ######################
ARG BUILD_FROM="ghcr.io/hassio-addons/base:17.2.5" ARG BUILD_FROM="ghcr.io/hassio-addons/base:17.2.4"
# hadolint ignore=DL3006 # hadolint ignore=DL3006
FROM $BUILD_FROM AS base FROM $BUILD_FROM AS base