fix unit test, increase coverage
This commit is contained in:
@@ -1,13 +1,19 @@
|
|||||||
# test_with_pytest.py
|
# test_with_pytest.py
|
||||||
import pytest
|
import pytest
|
||||||
from server import app
|
from server import app
|
||||||
|
from web import Web, web
|
||||||
from async_stream import AsyncStreamClient
|
from async_stream import AsyncStreamClient
|
||||||
from gen3plus.inverter_g3p import InverterG3P
|
from gen3plus.inverter_g3p import InverterG3P
|
||||||
from test_inverter_g3p import FakeReader, FakeWriter, config_conn
|
from test_inverter_g3p import FakeReader, FakeWriter, config_conn
|
||||||
|
|
||||||
pytest_plugins = ('pytest_asyncio',)
|
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
|
@pytest.fixture
|
||||||
def create_inverter(config_conn):
|
def create_inverter(config_conn):
|
||||||
_ = config_conn
|
_ = config_conn
|
||||||
@@ -36,58 +42,59 @@ def create_inverter_client(config_conn):
|
|||||||
return inv
|
return inv
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_home():
|
async def test_home(client):
|
||||||
"""Test the home route."""
|
"""Test the home route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/')
|
response = await client.get('/')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'text/html'
|
assert response.mimetype == 'text/html'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_page():
|
async def test_page(client):
|
||||||
"""Test the empty page route."""
|
"""Test the empty page route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/page')
|
response = await client.get('/page')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'text/html'
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_favicon96():
|
async def test_favicon96(client):
|
||||||
"""Test the favicon-96x96.png route."""
|
"""Test the favicon-96x96.png route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/favicon-96x96.png')
|
response = await client.get('/favicon-96x96.png')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'image/png'
|
assert response.mimetype == 'image/png'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_favicon():
|
async def test_favicon(client):
|
||||||
"""Test the favicon.ico route."""
|
"""Test the favicon.ico route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/favicon.ico')
|
response = await client.get('/favicon.ico')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'image/x-icon'
|
assert response.mimetype == 'image/x-icon'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_favicon_svg():
|
async def test_favicon_svg(client):
|
||||||
"""Test the favicon.svg route."""
|
"""Test the favicon.svg route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/favicon.svg')
|
response = await client.get('/favicon.svg')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'image/svg+xml'
|
assert response.mimetype == 'image/svg+xml'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_apple_touch_icon():
|
async def test_apple_touch_icon(client):
|
||||||
"""Test the apple-touch-icon.png route."""
|
"""Test the apple-touch-icon.png route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/apple-touch-icon.png')
|
response = await client.get('/apple-touch-icon.png')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'image/png'
|
assert response.mimetype == 'image/png'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_manifest():
|
async def test_manifest(client):
|
||||||
"""Test the site.webmanifest route."""
|
"""Test the site.webmanifest route."""
|
||||||
client = app.test_client()
|
|
||||||
response = await client.get('/site.webmanifest')
|
response = await client.get('/site.webmanifest')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.mimetype == 'application/manifest+json'
|
assert response.mimetype == 'application/manifest+json'
|
||||||
@@ -125,11 +132,6 @@ async def test_data_fetch2(create_inverter_client):
|
|||||||
response = await client.get('/data-fetch')
|
response = await client.get('/data-fetch')
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
app.secret_key = 'super secret key'
|
|
||||||
return app.test_client()
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_language_en(client):
|
async def test_language_en(client):
|
||||||
"""Test the language/en route."""
|
"""Test the language/en route."""
|
||||||
|
|||||||
Reference in New Issue
Block a user