Skip to content

Commit 7395da7

Browse files
committed
Add additional test
1 parent cc66080 commit 7395da7

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

tests/test_data.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""Test the interaction with the Luftdaten API."""
2+
import pytest
3+
from pytest_httpx import HTTPXMock
4+
5+
from luftdaten import Luftdaten
6+
7+
import httpx
8+
9+
SENSOR_ID = 1
10+
11+
RESPONSE_VALID = [
12+
{
13+
"sensor": {
14+
"sensor_type": {
15+
"manufacturer": "various",
16+
"name": "DHT22",
17+
"id": 9
18+
},
19+
"pin": "7",
20+
"id": 152
21+
},
22+
"timestamp": "2021-11-07 11:16:45",
23+
"sampling_rate": None,
24+
"sensordatavalues": [
25+
{
26+
"value": "10.50",
27+
"id": 16932663249,
28+
"value_type": "temperature"
29+
},
30+
{
31+
"value": "79.30",
32+
"id": 16932663267,
33+
"value_type": "humidity"
34+
}
35+
],
36+
"id": 7706863277,
37+
"location": {
38+
"country": "DE",
39+
"latitude": "48.792",
40+
"exact_location": 0,
41+
"altitude": "326.9",
42+
"longitude": "9.164",
43+
"indoor": 0,
44+
"id": 68
45+
}
46+
},
47+
{
48+
"sensor": {
49+
"sensor_type": {
50+
"manufacturer": "various",
51+
"name": "DHT22",
52+
"id": 9
53+
},
54+
"pin": "7",
55+
"id": 152
56+
},
57+
"timestamp": "2021-11-07 11:14:13",
58+
"sampling_rate": None,
59+
"sensordatavalues": [
60+
{
61+
"value": "10.50",
62+
"id": 16932614294,
63+
"value_type": "temperature"
64+
},
65+
{
66+
"value": "80.60",
67+
"id": 16932614337,
68+
"value_type": "humidity"
69+
}
70+
],
71+
"id": 7706841422,
72+
"location": {
73+
"country": "DE",
74+
"latitude": "48.792",
75+
"exact_location": 0,
76+
"altitude": "326.9",
77+
"longitude": "9.164",
78+
"indoor": 0,
79+
"id": 68
80+
}
81+
}
82+
]
83+
84+
85+
@pytest.mark.asyncio
86+
async def test_sensor_values(httpx_mock: HTTPXMock):
87+
"""Test the sensor values."""
88+
httpx_mock.add_response(json=RESPONSE_VALID)
89+
90+
client = Luftdaten(SENSOR_ID)
91+
await client.get_data()
92+
93+
assert client.values == {'temperature': 10.5, 'humidity': 79.3}
94+
95+
@pytest.mark.asyncio
96+
async def test_meta(httpx_mock: HTTPXMock):
97+
"""Test the meta information."""
98+
httpx_mock.add_response(json=RESPONSE_VALID)
99+
100+
client = Luftdaten(SENSOR_ID)
101+
await client.get_data()
102+
103+
assert client.meta["sensor_id"] == 1
104+
assert client.meta["latitude"] == 48.792
105+
assert client.meta["longitude"] == 9.164
106+
assert client.meta["altitude"] == 326.9

0 commit comments

Comments
 (0)