| 1 | """Tests for aiopegelonline.""" |
| 2 | from __future__scip-python python python-stdlib 3.11 __future__/__init__: import annotationsscip-python python python-stdlib 3.11 __future__/annotations.annotations. |
| 3 | |
| 4 | import pytestscip-python python pytest 9.0.3 pytest/__init__: |
| 5 | from aiohttpscip-python python aiohttp 3.14.1 aiohttp/__init__: import ClientErrorscip-python python aiopegelonline 0.1.2 `aiohttp.client_exceptions`/ClientError# |
| 6 | |
| 7 | from aiopegelonline.exceptionsscip-python python aiopegelonline 0.1.2 `aiopegelonline.exceptions`/__init__: import PegelonlineDataErrorscip-python python aiopegelonline 0.1.2 `aiopegelonline.exceptions`/PegelonlineDataError# |
| 8 | from aiopegelonline.modelsscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/__init__: import Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#, StationMeasurementsscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements# |
| 9 | |
| 10 | |
| 11 | async def test_get_all_stationsscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_all_stations().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_all_stations().(mock_pegelonline_with_data)): |
| 12 | """Test async_get_all_stations.""" |
| 13 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_all_stations().(mock_pegelonline_with_data)() |
| 14 | stations = await api.async_get_all_stations() |
| 15 | assert len(stations) == 2 |
| 16 | |
| 17 | station = stations["70272185-xxxx-xxxx-xxxx-43bea330dcae"] |
| 18 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 19 | assert station.as_dictscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#as_dict().() == { |
| 20 | "uuid": "70272185-xxxx-xxxx-xxxx-43bea330dcae", |
| 21 | "name": "DRESDEN", |
| 22 | "agency": "STANDORT DRESDEN", |
| 23 | "river_kilometer": 55.63, |
| 24 | "longitude": 13.738831783620384, |
| 25 | "latitude": 51.054459765598125, |
| 26 | "water_name": "ELBE", |
| 27 | "base_data_url": "https://www.pegelonline.wsv.de/gast/stammdaten?pegelnr=501060", |
| 28 | } |
| 29 | |
| 30 | station = stations["915d76e1-xxxx-xxxx-xxxx-4d144cd771cc"] |
| 31 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 32 | assert station.uuidscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#uuid. == "915d76e1-xxxx-xxxx-xxxx-4d144cd771cc" |
| 33 | assert station.namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#name. == "WÜRZBURG" |
| 34 | assert station.agencyscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#agency. == "SCHWEINFURT" |
| 35 | assert station.river_kilometerscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#river_kilometer. == 251.97 |
| 36 | assert station.longitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#longitude. == 9.925968763247354 |
| 37 | assert station.latitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#latitude. == 49.79620901036012 |
| 38 | assert station.water_namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#water_name. == "MAIN" |
| 39 | assert ( |
| 40 | station.base_data_urlscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#base_data_url. |
| 41 | == "https://www.pegelonline.wsv.de/gast/stammdaten?pegelnr=24300600" |
| 42 | ) |
| 43 | |
| 44 | |
| 45 | async def test_get_nearby_stationsscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations().(mock_pegelonline_with_data)): |
| 46 | """Test async_get_nearby_stations.""" |
| 47 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations().(mock_pegelonline_with_data)() |
| 48 | stations = await api.async_get_nearby_stations(13, 51, 25) |
| 49 | assert len(stations) == 1 |
| 50 | |
| 51 | station = stations["70272185-xxxx-xxxx-xxxx-43bea330dcae"] |
| 52 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 53 | assert station.uuidscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#uuid. == "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 54 | assert station.namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#name. == "DRESDEN" |
| 55 | assert station.agencyscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#agency. == "STANDORT DRESDEN" |
| 56 | assert station.river_kilometerscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#river_kilometer. == 55.63 |
| 57 | assert station.longitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#longitude. == 13.738831783620384 |
| 58 | assert station.latitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#latitude. == 51.054459765598125 |
| 59 | assert station.water_namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#water_name. == "ELBE" |
| 60 | assert ( |
| 61 | station.base_data_urlscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#base_data_url. |
| 62 | == "https://www.pegelonline.wsv.de/gast/stammdaten?pegelnr=501060" |
| 63 | ) |
| 64 | |
| 65 | |
| 66 | async def test_get_nearby_stations_no_stationsscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations_no_stations().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations_no_stations().(mock_pegelonline_with_data)): |
| 67 | """Test async_get_nearby_stations.""" |
| 68 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_nearby_stations_no_stations().(mock_pegelonline_with_data)() |
| 69 | stations = await api.async_get_nearby_stations(10, 45, 25) |
| 70 | assert len(stations) == 0 |
| 71 | |
| 72 | |
| 73 | async def test_get_station_detailsscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details().(mock_pegelonline_with_data)): |
| 74 | """Test async_get_station_details.""" |
| 75 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details().(mock_pegelonline_with_data)() |
| 76 | station = await api.async_get_station_details( |
| 77 | "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 78 | ) |
| 79 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 80 | assert station.uuidscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#uuid. == "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 81 | assert station.namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#name. == "DRESDEN" |
| 82 | assert station.agencyscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#agency. == "STANDORT DRESDEN" |
| 83 | assert station.river_kilometerscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#river_kilometer. == 55.63 |
| 84 | assert station.longitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#longitude. == 13.738831783620384 |
| 85 | assert station.latitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#latitude. == 51.054459765598125 |
| 86 | assert station.water_namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#water_name. == "ELBE" |
| 87 | assert ( |
| 88 | station.base_data_urlscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#base_data_url. |
| 89 | == "https://www.pegelonline.wsv.de/gast/stammdaten?pegelnr=501060" |
| 90 | ) |
| 91 | |
| 92 | |
| 93 | async def test_get_station_details_invalidscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_invalid().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_invalid().(mock_pegelonline_with_data)): |
| 94 | """Test async_get_station_details with invalid uuid.""" |
| 95 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_invalid().(mock_pegelonline_with_data)() |
| 96 | with pytestscip-python python pytest 9.0.3 pytest/__init__:.raises(PegelonlineDataErrorscip-python python aiopegelonline 0.1.2 `aiopegelonline.exceptions`/PegelonlineDataError#): |
| 97 | await api.async_get_station_details("INVALID_UUID") |
| 98 | |
| 99 | |
| 100 | async def test_get_station_details_connection_errorscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_connection_error().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_connection_error().(mock_pegelonline_with_data)): |
| 101 | """Test async_get_station_details with connection error.""" |
| 102 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_connection_error().(mock_pegelonline_with_data)() |
| 103 | with pytestscip-python python pytest 9.0.3 pytest/__init__:.raises(ClientErrorscip-python python aiopegelonline 0.1.2 `aiohttp.client_exceptions`/ClientError#): |
| 104 | await api.async_get_station_details("CONNECT_ERROR") |
| 105 | |
| 106 | |
| 107 | async def test_get_station_measurementsscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_measurements().(mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_measurements().(mock_pegelonline_with_data)): |
| 108 | """Test async_get_station_measurements.""" |
| 109 | api = await mock_pegelonline_with_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_measurements().(mock_pegelonline_with_data)() |
| 110 | measurement = await api.async_get_station_measurements( |
| 111 | "915d76e1-xxxx-xxxx-xxxx-4d144cd771cc" |
| 112 | ) |
| 113 | assert isinstance(measurement, StationMeasurementsscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#) |
| 114 | assert measurement.air_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#air_temperature. is not None |
| 115 | assert measurement.air_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#air_temperature..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "°C" |
| 116 | assert measurement.air_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#air_temperature..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 21.2 |
| 117 | assert measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height. is None |
| 118 | assert measurement.oxygen_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#oxygen_level. is not None |
| 119 | assert measurement.oxygen_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#oxygen_level..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "mg/l" |
| 120 | assert measurement.oxygen_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#oxygen_level..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 8.4 |
| 121 | assert measurement.ph_valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#ph_value. is not None |
| 122 | assert measurement.ph_valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#ph_value..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "--" |
| 123 | assert measurement.ph_valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#ph_value..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 8.1 |
| 124 | assert measurement.water_speedscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_speed. is not None |
| 125 | assert measurement.water_speedscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_speed..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "m/s" |
| 126 | assert measurement.water_speedscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_speed..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 0.58 |
| 127 | assert measurement.water_flowscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_flow. is not None |
| 128 | assert measurement.water_flowscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_flow..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "m³/s" |
| 129 | assert measurement.water_flowscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_flow..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 102 |
| 130 | assert measurement.water_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_level. is not None |
| 131 | assert measurement.water_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_level..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "cm" |
| 132 | assert measurement.water_levelscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_level..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 159 |
| 133 | assert measurement.water_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_temperature. is not None |
| 134 | assert measurement.water_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_temperature..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "°C" |
| 135 | assert measurement.water_temperaturescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#water_temperature..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 22.1 |
| 136 | |
| 137 | measurement = await api.async_get_station_measurements( |
| 138 | "07374faf-xxxx-xxxx-xxxx-adc0e0784c4b" |
| 139 | ) |
| 140 | assert isinstance(measurement, StationMeasurementsscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#) |
| 141 | assert measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height. is not None |
| 142 | assert measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height..uomscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#uom. == "cm" |
| 143 | assert measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height..valuescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#value. == 715 |
| 144 | assert measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height..as_dictscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/CurrentMeasurement#as_dict().() == { |
| 145 | "uom": "cm", |
| 146 | "value": 715, |
| 147 | } |
| 148 | assert measurement.as_dictscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#as_dict().() == { |
| 149 | "air_temperature": None, |
| 150 | "clearance_height": measurement.clearance_heightscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/StationMeasurements#clearance_height., |
| 151 | "oxygen_level": None, |
| 152 | "ph_value": None, |
| 153 | "water_speed": None, |
| 154 | "water_flow": None, |
| 155 | "water_level": None, |
| 156 | "water_temperature": None, |
| 157 | } |
| 158 | |
| 159 | |
| 160 | async def test_get_station_details_cachedscip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_cached().(mock_pegelonline_with_cached_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_cached().(mock_pegelonline_with_cached_data)): |
| 161 | """Test response cache.""" |
| 162 | api = await mock_pegelonline_with_cached_datascip-python python aiopegelonline 0.1.2 `tests.test_aiopegelonline`/test_get_station_details_cached().(mock_pegelonline_with_cached_data)() |
| 163 | station = await api.async_get_station_details( |
| 164 | "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 165 | ) |
| 166 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 167 | assert station.uuidscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#uuid. == "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 168 | assert station.namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#name. == "DRESDEN" |
| 169 | assert station.agencyscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#agency. == "STANDORT DRESDEN" |
| 170 | assert station.river_kilometerscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#river_kilometer. == 55.63 |
| 171 | assert station.longitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#longitude. == 13.738831783620384 |
| 172 | assert station.latitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#latitude. == 51.054459765598125 |
| 173 | assert station.water_namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#water_name. == "ELBE" |
| 174 | |
| 175 | station = await api.async_get_station_details( |
| 176 | "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 177 | ) |
| 178 | assert isinstance(station, Stationscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#) |
| 179 | assert station.uuidscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#uuid. == "70272185-xxxx-xxxx-xxxx-43bea330dcae" |
| 180 | assert station.namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#name. == "DRESDEN" |
| 181 | assert station.agencyscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#agency. == "STANDORT DRESDEN" |
| 182 | assert station.river_kilometerscip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#river_kilometer. == 55.63 |
| 183 | assert station.longitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#longitude. == 13.738831783620384 |
| 184 | assert station.latitudescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#latitude. == 51.054459765598125 |
| 185 | assert station.water_namescip-python python aiopegelonline 0.1.2 `aiopegelonline.models`/Station#water_name. == "ELBE" |