S allius/issue391 (#392)
* design counter on connection board * display time of last update and add reload button * chance `Updated` field to a real button * Provide counter values for the dashboard * change background color ot the top branch - use dark-grey instead of black to reduce the contrast * change color of counter tiles * test proxy connection counter handling * prepare conn-table and notes list building * remove obsolete menue points * store client mode for dashboard * store inverters serial number for the dashboard * store inverters serial number * build connection table for dashboard * add connection table to dashboard * fix responsiveness of the tiles * adapt unit tests * remove test fake code * increase test coverage, remove obsolete if statement
This commit is contained in:
@@ -8,6 +8,7 @@ from infos import Infos
|
||||
from inverter_base import InverterBase
|
||||
from async_stream import AsyncStreamServer, AsyncStreamClient, StreamPtr
|
||||
from messages import Message
|
||||
from mock import patch, call
|
||||
|
||||
from test_modbus_tcp import FakeReader, FakeWriter
|
||||
from test_inverter_base import config_conn, patch_open_connection
|
||||
@@ -74,6 +75,13 @@ def test_health():
|
||||
cnt += 1
|
||||
assert cnt == 0
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def spy_inc_cnt():
|
||||
with patch.object(Infos, 'inc_counter', wraps=Infos.inc_counter) as infos:
|
||||
yield infos
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close_cb():
|
||||
assert asyncio.get_running_loop()
|
||||
@@ -529,9 +537,10 @@ async def test_forward_runtime_error2():
|
||||
del ifc
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_forward_runtime_error3():
|
||||
async def test_forward_runtime_error3(spy_inc_cnt):
|
||||
assert asyncio.get_running_loop()
|
||||
remote = StreamPtr(None)
|
||||
spy = spy_inc_cnt
|
||||
cnt = 0
|
||||
|
||||
async def _create_remote():
|
||||
@@ -543,13 +552,17 @@ async def test_forward_runtime_error3():
|
||||
ifc = AsyncStreamServer(fake_reader_fwd(), FakeWriter(), None, _create_remote, remote)
|
||||
ifc.fwd_add(b'test-forward_msg')
|
||||
await ifc.server_loop()
|
||||
spy.assert_has_calls([call('Inverter_Cnt'), call('ServerMode_Cnt')])
|
||||
assert Infos.get_counter('Inverter_Cnt') == 0
|
||||
assert Infos.get_counter('ServerMode_Cnt') == 0
|
||||
assert cnt == 1
|
||||
del ifc
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_forward_resp():
|
||||
async def test_forward_resp(spy_inc_cnt):
|
||||
assert asyncio.get_running_loop()
|
||||
remote = StreamPtr(None)
|
||||
spy = spy_inc_cnt
|
||||
cnt = 0
|
||||
|
||||
def _close_cb():
|
||||
@@ -557,27 +570,35 @@ async def test_forward_resp():
|
||||
cnt += 1
|
||||
|
||||
cnt = 0
|
||||
ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), remote, _close_cb)
|
||||
ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), remote, _close_cb, use_emu = True)
|
||||
create_remote(remote, TestType.FWD_NO_EXCPT)
|
||||
ifc.fwd_add(b'test-forward_msg')
|
||||
await ifc.client_loop('')
|
||||
spy.assert_has_calls([call('Cloud_Conn_Cnt'), call('EmuMode_Cnt')])
|
||||
assert Infos.get_counter('Cloud_Conn_Cnt') == 0
|
||||
assert Infos.get_counter('EmuMode_Cnt') == 0
|
||||
assert cnt == 1
|
||||
del ifc
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_forward_resp2():
|
||||
async def test_forward_resp2(spy_inc_cnt):
|
||||
assert asyncio.get_running_loop()
|
||||
remote = StreamPtr(None)
|
||||
spy = spy_inc_cnt
|
||||
cnt = 0
|
||||
def _close_cb():
|
||||
nonlocal cnt
|
||||
cnt += 1
|
||||
|
||||
cnt = 0
|
||||
ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), None, _close_cb)
|
||||
ifc = AsyncStreamClient(fake_reader_fwd(), FakeWriter(), None, _close_cb, use_emu = False)
|
||||
create_remote(remote, TestType.FWD_NO_EXCPT)
|
||||
ifc.fwd_add(b'test-forward_msg')
|
||||
await ifc.client_loop('')
|
||||
spy.assert_has_calls([call('Cloud_Conn_Cnt'), call('ProxyMode_Cnt'), call('SW_Exception')])
|
||||
assert Infos.get_counter('Cloud_Conn_Cnt') == 0
|
||||
assert Infos.get_counter('ProxyMode_Cnt') == 0
|
||||
assert cnt == 1
|
||||
del ifc
|
||||
|
||||
@@ -2,8 +2,38 @@
|
||||
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(config_conn):
|
||||
_ = config_conn
|
||||
inv = InverterG3P(FakeReader(), FakeWriter(), client_mode=False)
|
||||
|
||||
return inv
|
||||
|
||||
@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 +93,31 @@ async def test_manifest():
|
||||
assert response.mimetype == 'application/manifest+json'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_data_fetch():
|
||||
async def test_data_fetch(create_inverter):
|
||||
"""Test the healthy route."""
|
||||
_ = create_inverter
|
||||
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_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
|
||||
|
||||
Reference in New Issue
Block a user