S allius/issue394 (#400)
* store logging path in Config class * rename template files and page files * jump to referer page - after changing the language, we jump to the referer page, if the attribute exists * build and send list of log-files * rename Download page into Log files * initialize log-path in test config * improve dashboard unit tests - add log file tests - check content-languages after language switch * initialize config structure for log-file tests * add test log file to project * add sub_dir to test log path - non files must be skipped. To test this we add a sub directory to the test log directory * add german translations * set quart debug flag for debug versions * update changelog
This commit is contained in:
0
app/tests/log/sub_dir/not_reachable.txt
Normal file
0
app/tests/log/sub_dir/not_reachable.txt
Normal file
19
app/tests/log/test.txt
Normal file
19
app/tests/log/test.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
2025-04-30 00:01:23 INFO | root | Server "proxy - unknown" will be started
|
||||
2025-04-30 00:01:23 INFO | root | current dir: /Users/sallius/tsun/tsun-gen3-proxy
|
||||
2025-04-30 00:01:23 INFO | root | config_path: ./config/
|
||||
2025-04-30 00:01:23 INFO | root | json_config: None
|
||||
2025-04-30 00:01:23 INFO | root | toml_config: None
|
||||
2025-04-30 00:01:23 INFO | root | trans_path: ../translations/
|
||||
2025-04-30 00:01:23 INFO | root | rel_urls: False
|
||||
2025-04-30 00:01:23 INFO | root | log_path: ./log/
|
||||
2025-04-30 00:01:23 INFO | root | log_backups: unlimited
|
||||
2025-04-30 00:01:23 INFO | root | LOG_LVL : None
|
||||
2025-04-30 00:01:23 INFO | root | ******
|
||||
2025-04-30 00:01:23 INFO | root | Read from /Users/sallius/tsun/tsun-gen3-proxy/app/src/cnf/default_config.toml => ok
|
||||
2025-04-30 00:01:23 INFO | root | Read from environment => ok
|
||||
2025-04-30 00:01:23 INFO | root | Read from ./config/config.json => n/a
|
||||
2025-04-30 00:01:23 INFO | root | Read from ./config/config.toml => n/a
|
||||
2025-04-30 00:01:23 INFO | root | ******
|
||||
2025-04-30 00:01:23 INFO | root | listen on port: 5005 for inverters
|
||||
2025-04-30 00:01:23 INFO | root | listen on port: 10000 for inverters
|
||||
2025-04-30 00:01:23 INFO | root | Start Quart
|
||||
@@ -37,6 +37,7 @@ def config_conn():
|
||||
},
|
||||
'solarman':{'enabled': True, 'host': 'test_cloud.local', 'port': 1234}, 'inverters':{'allow_all':True}
|
||||
}
|
||||
Config.log_path='app/tests/log/'
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def module_init():
|
||||
|
||||
@@ -5,6 +5,7 @@ from web import Web, web
|
||||
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
|
||||
|
||||
pytest_plugins = ('pytest_asyncio',)
|
||||
|
||||
@@ -64,6 +65,13 @@ async def test_rel_page(client):
|
||||
assert response.mimetype == 'text/html'
|
||||
web.build_relative_urls = False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_logging(client):
|
||||
"""Test the logging page route."""
|
||||
response = await client.get('/logging')
|
||||
assert response.status_code == 200
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_favicon96(client):
|
||||
"""Test the favicon-96x96.png route."""
|
||||
@@ -101,7 +109,7 @@ async def test_manifest(client):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_data_fetch(create_inverter):
|
||||
"""Test the healthy route."""
|
||||
"""Test the data-fetch route."""
|
||||
_ = create_inverter
|
||||
client = app.test_client()
|
||||
response = await client.get('/data-fetch')
|
||||
@@ -112,7 +120,7 @@ async def test_data_fetch(create_inverter):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_data_fetch1(create_inverter_server):
|
||||
"""Test the healthy route."""
|
||||
"""Test the data-fetch route with server connection."""
|
||||
_ = create_inverter_server
|
||||
client = app.test_client()
|
||||
response = await client.get('/data-fetch')
|
||||
@@ -123,7 +131,7 @@ async def test_data_fetch1(create_inverter_server):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_data_fetch2(create_inverter_client):
|
||||
"""Test the healthy route."""
|
||||
"""Test the data-fetch route with client connection."""
|
||||
_ = create_inverter_client
|
||||
client = app.test_client()
|
||||
response = await client.get('/data-fetch')
|
||||
@@ -134,9 +142,11 @@ async def test_data_fetch2(create_inverter_client):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_language_en(client):
|
||||
"""Test the language/en route."""
|
||||
response = await client.get('/language/en')
|
||||
"""Test the language/en route and cookie."""
|
||||
response = await client.get('/language/en', headers={'referer': '/index'})
|
||||
assert response.status_code == 302
|
||||
assert response.content_language.pop() == 'en'
|
||||
assert response.location == '/index'
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
client.set_cookie('test', key='language', value='de')
|
||||
@@ -146,14 +156,53 @@ async def test_language_en(client):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_language_de(client):
|
||||
"""Test the language/en route."""
|
||||
response = await client.get('/language/de')
|
||||
"""Test the language/de route."""
|
||||
response = await client.get('/language/de', headers={'referer': '/'})
|
||||
assert response.status_code == 302
|
||||
assert response.content_language.pop() == 'de'
|
||||
assert response.location == '/'
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_language_unknown(client):
|
||||
"""Test the language/en route."""
|
||||
response = await client.get('/language/unknonw')
|
||||
"""Test the language/unknown route."""
|
||||
response = await client.get('/language/unknown')
|
||||
assert response.status_code == 404
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_file_fetch(client, config_conn):
|
||||
"""Test the data-fetch route."""
|
||||
_ = config_conn
|
||||
assert Config.log_path == 'app/tests/log/'
|
||||
response = await client.get('/file-fetch')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_file(client, config_conn):
|
||||
"""Test the send-file route."""
|
||||
_ = config_conn
|
||||
assert Config.log_path == 'app/tests/log/'
|
||||
response = await client.get('/send-file/test.txt')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_missing_send_file(client, config_conn):
|
||||
"""Test the send-file route (file not found)."""
|
||||
_ = config_conn
|
||||
assert Config.log_path == 'app/tests/log/'
|
||||
response = await client.get('/send-file/no_file.log')
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_send_file(client, config_conn):
|
||||
"""Test the send-file route (invalid filename)."""
|
||||
_ = config_conn
|
||||
assert Config.log_path == 'app/tests/log/'
|
||||
response = await client.get('/send-file/../test_web_route.py')
|
||||
assert response.status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user