S allius/issue395 (#399)
* add button for languages setting * build a web module for the dashboard - load all python module from local dir - initialize Blueprint and Babel * set a default key for secure cookies * add translations to docker container * improve translation build - clean target erases the *.pot - don't modify the resurt of url_for() calls - don't translate the language description * translate connection table, fix icon * build relative urls for HA ingress * fix unit test, increase coverage
This commit is contained in:
@@ -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'
|
||||
@@ -124,3 +131,29 @@ async def test_data_fetch2(create_inverter_client):
|
||||
|
||||
response = await client.get('/data-fetch')
|
||||
assert response.status_code == 200
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_language_en(client):
|
||||
"""Test the language/en route."""
|
||||
response = await client.get('/language/en')
|
||||
assert response.status_code == 302
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
client.set_cookie('test', key='language', value='de')
|
||||
response = await client.get('/page')
|
||||
assert response.status_code == 200
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_language_de(client):
|
||||
"""Test the language/en route."""
|
||||
response = await client.get('/language/de')
|
||||
assert response.status_code == 302
|
||||
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')
|
||||
assert response.status_code == 404
|
||||
assert response.mimetype == 'text/html'
|
||||
|
||||
Reference in New Issue
Block a user