From 503ca8719d06d72aa0b5af9e8c5c989b4739b6be Mon Sep 17 00:00:00 2001 From: Stefan Allius Date: Thu, 24 Apr 2025 22:32:57 +0200 Subject: [PATCH] adapt unit tests --- app/tests/test_web_route.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/tests/test_web_route.py b/app/tests/test_web_route.py index 537a0ad..89ec0a8 100644 --- a/app/tests/test_web_route.py +++ b/app/tests/test_web_route.py @@ -2,8 +2,31 @@ import pytest from server import app +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 +def create_inverter_server(config_conn): + _ = config_conn + inv = InverterG3P(FakeReader(), FakeWriter(), client_mode=False) + ifc = AsyncStreamClient(FakeReader(), FakeWriter(), inv.local, + None, inv.use_emulation) + inv.remote.ifc = ifc + + return inv + +@pytest.fixture +def create_inverter_client(config_conn): + _ = config_conn + inv = InverterG3P(FakeReader(), FakeWriter(), client_mode=True) + ifc = AsyncStreamClient(FakeReader(), FakeWriter(), inv.local, + None, inv.use_emulation) + inv.remote.ifc = ifc + + return inv @pytest.mark.asyncio async def test_home(): @@ -63,8 +86,20 @@ async def test_manifest(): assert response.mimetype == 'application/manifest+json' @pytest.mark.asyncio -async def test_data_fetch(): +async def test_data_fetch1(create_inverter_server): """Test the healthy route.""" + _ = create_inverter_server + client = app.test_client() + response = await client.get('/data-fetch') + assert response.status_code == 200 + + response = await client.get('/data-fetch') + assert response.status_code == 200 + +@pytest.mark.asyncio +async def test_data_fetch2(create_inverter_client): + """Test the healthy route.""" + _ = create_inverter_client client = app.test_client() response = await client.get('/data-fetch') assert response.status_code == 200