From 719aa7a8bab8ffeecf2c083c3b348c2ce8ca1512 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Fri, 17 Dec 2021 22:47:08 +0100 Subject: [PATCH] Add extra tests --- pyproject.toml | 2 +- tests/test_omnik.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 98f7b08d..3a957134 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,5 +120,5 @@ paths = ["omnikinverter"] verbose = true [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["setuptools","poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/tests/test_omnik.py b/tests/test_omnik.py index 72f1985f..c4551fc0 100644 --- a/tests/test_omnik.py +++ b/tests/test_omnik.py @@ -15,6 +15,42 @@ from . import load_fixtures +@pytest.mark.asyncio +async def test_json_request(aresponses): + """Test JSON response is handled correctly.""" + aresponses.add( + "example.com", + "/test", + "GET", + aresponses.Response( + status=200, + headers={"Content-Type": "application/json"}, + text='{"status": "ok"}', + ), + ) + async with aiohttp.ClientSession() as session: + omnik_inverter = OmnikInverter("example.com", session=session) + await omnik_inverter.request("test") + await omnik_inverter.close() + + +@pytest.mark.asyncio +async def test_internal_session(aresponses): + """Test JSON response is handled correctly.""" + aresponses.add( + "example.com", + "/test", + "GET", + aresponses.Response( + status=200, + headers={"Content-Type": "application/json"}, + text='{"status": "ok"}', + ), + ) + async with OmnikInverter("example.com") as omnik_inverter: + await omnik_inverter.request("test") + + @pytest.mark.asyncio async def test_wrong_js_source(aresponses): """Test on wrong data source error raise."""