diff --git a/tests/conftest.py b/tests/conftest.py index 0326524..9b18b60 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,18 +3,16 @@ import json -import aiohttp import pytest from aioresponses import aioresponses -from aiopegelonline import PegelOnline from aiopegelonline.const import BASE_URL from .const import MOCK_DATA @pytest.fixture() -def mock_pegelonline(): +def mock_response(): """Fixture that the PegelOnline is used with mocked response.""" with aioresponses() as mock_resp: for path, data in MOCK_DATA.items(): @@ -24,4 +22,4 @@ def mock_pegelonline(): body=json.dumps(data["body"]), exception=data.get("exception"), ) - yield PegelOnline(aiohttp.ClientSession()) + yield mock_resp diff --git a/tests/test_aiopegelonline.py b/tests/test_aiopegelonline.py index b3135ff..64fd4b8 100644 --- a/tests/test_aiopegelonline.py +++ b/tests/test_aiopegelonline.py @@ -2,17 +2,17 @@ from __future__ import annotations import pytest -from aiohttp import ClientError +from aiohttp import ClientError, ClientSession +from aiopegelonline import PegelOnline from aiopegelonline.exceptions import PegelonlineDataError from aiopegelonline.models import Station, StationMeasurements @pytest.mark.asyncio -async def test_get_all_stations(mock_pegelonline): +async def test_get_all_stations(mock_response): """Test async_get_all_stations.""" - # with mock_response: - stations = await mock_pegelonline.async_get_all_stations() + stations = await PegelOnline(ClientSession()).async_get_all_stations() assert len(stations) == 2 station = stations["70272185-xxxx-xxxx-xxxx-43bea330dcae"] @@ -44,9 +44,9 @@ async def test_get_all_stations(mock_pegelonline): @pytest.mark.asyncio -async def test_get_nearby_stations(mock_pegelonline): +async def test_get_nearby_stations(mock_response): """Test async_get_nearby_stations.""" - stations = await mock_pegelonline.async_get_nearby_stations(13, 51, 25) + stations = await PegelOnline(ClientSession()).async_get_nearby_stations(13, 51, 25) assert len(stations) == 1 station = stations["70272185-xxxx-xxxx-xxxx-43bea330dcae"] @@ -65,16 +65,16 @@ async def test_get_nearby_stations(mock_pegelonline): @pytest.mark.asyncio -async def test_get_nearby_stations_no_stations(mock_pegelonline): +async def test_get_nearby_stations_no_stations(mock_response): """Test async_get_nearby_stations.""" - stations = await mock_pegelonline.async_get_nearby_stations(10, 45, 25) + stations = await PegelOnline(ClientSession()).async_get_nearby_stations(10, 45, 25) assert len(stations) == 0 @pytest.mark.asyncio -async def test_get_station_details(mock_pegelonline): +async def test_get_station_details(mock_response): """Test async_get_station_details.""" - station = await mock_pegelonline.async_get_station_details( + station = await PegelOnline(ClientSession()).async_get_station_details( "70272185-xxxx-xxxx-xxxx-43bea330dcae" ) assert isinstance(station, Station) @@ -92,23 +92,24 @@ async def test_get_station_details(mock_pegelonline): @pytest.mark.asyncio -async def test_get_station_details_invalid(mock_pegelonline): +async def test_get_station_details_invalid(mock_response): """Test async_get_station_details with invalid uuid.""" with pytest.raises(PegelonlineDataError): - await mock_pegelonline.async_get_station_details("INVALID_UUID") + await PegelOnline(ClientSession()).async_get_station_details("INVALID_UUID") @pytest.mark.asyncio -async def test_get_station_details_connection_error(mock_pegelonline): +async def test_get_station_details_connection_error(mock_response): """Test async_get_station_details with connection error.""" with pytest.raises(ClientError): - await mock_pegelonline.async_get_station_details("CONNECT_ERROR") + await PegelOnline(ClientSession()).async_get_station_details("CONNECT_ERROR") @pytest.mark.asyncio -async def test_get_station_measurements(mock_pegelonline): +async def test_get_station_measurements(mock_response): """Test async_get_station_measurements.""" - measurement = await mock_pegelonline.async_get_station_measurements( + api = PegelOnline(ClientSession()) + measurement = await api.async_get_station_measurements( "915d76e1-xxxx-xxxx-xxxx-4d144cd771cc" ) assert isinstance(measurement, StationMeasurements) @@ -135,7 +136,7 @@ async def test_get_station_measurements(mock_pegelonline): assert measurement.water_temperature.uom == "°C" assert measurement.water_temperature.value == 22.1 - measurement = await mock_pegelonline.async_get_station_measurements( + measurement = await api.async_get_station_measurements( "07374faf-xxxx-xxxx-xxxx-adc0e0784c4b" ) assert isinstance(measurement, StationMeasurements)