fix unit test, increase coverage

This commit is contained in:
Stefan Allius
2025-04-29 00:02:20 +02:00
parent 81745313b7
commit bd31dfc15d

View File

@@ -1,13 +1,19 @@
# test_with_pytest.py
import pytest
from server import app
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
pytest_plugins = ('pytest_asyncio',)
@pytest.fixture(scope="session")
def client():
app.secret_key = 'super secret key'
Web(app, '../transfer', False)
return app.test_client()
@pytest.fixture
def create_inverter(config_conn):
_ = config_conn
@@ -36,58 +42,59 @@ def create_inverter_client(config_conn):
return inv
@pytest.mark.asyncio
async def test_home():
async def test_home(client):
"""Test the home route."""
client = app.test_client()
response = await client.get('/')
assert response.status_code == 200
assert response.mimetype == 'text/html'
@pytest.mark.asyncio
async def test_page():
async def test_page(client):
"""Test the empty page route."""
client = app.test_client()
response = await client.get('/page')
assert response.status_code == 200
assert response.mimetype == 'text/html'
@pytest.mark.asyncio
async def test_rel_page(client):
"""Test the empty page route."""
web.build_relative_urls = True
response = await client.get('/page')
assert response.status_code == 200
assert response.mimetype == 'text/html'
web.build_relative_urls = False
@pytest.mark.asyncio
async def test_favicon96():
async def test_favicon96(client):
"""Test the favicon-96x96.png route."""
client = app.test_client()
response = await client.get('/favicon-96x96.png')
assert response.status_code == 200
assert response.mimetype == 'image/png'
@pytest.mark.asyncio
async def test_favicon():
async def test_favicon(client):
"""Test the favicon.ico route."""
client = app.test_client()
response = await client.get('/favicon.ico')
assert response.status_code == 200
assert response.mimetype == 'image/x-icon'
@pytest.mark.asyncio
async def test_favicon_svg():
async def test_favicon_svg(client):
"""Test the favicon.svg route."""
client = app.test_client()
response = await client.get('/favicon.svg')
assert response.status_code == 200
assert response.mimetype == 'image/svg+xml'
@pytest.mark.asyncio
async def test_apple_touch_icon():
async def test_apple_touch_icon(client):
"""Test the apple-touch-icon.png route."""
client = app.test_client()
response = await client.get('/apple-touch-icon.png')
assert response.status_code == 200
assert response.mimetype == 'image/png'
@pytest.mark.asyncio
async def test_manifest():
async def test_manifest(client):
"""Test the site.webmanifest route."""
client = app.test_client()
response = await client.get('/site.webmanifest')
assert response.status_code == 200
assert response.mimetype == 'application/manifest+json'
@@ -125,11 +132,6 @@ async def test_data_fetch2(create_inverter_client):
response = await client.get('/data-fetch')
assert response.status_code == 200
@pytest.fixture
def client():
app.secret_key = 'super secret key'
return app.test_client()
@pytest.mark.asyncio
async def test_language_en(client):
"""Test the language/en route."""