Skip to content

Commit 0ed2bd0

Browse files
committed
Add initial tests
1 parent d3a7f42 commit 0ed2bd0

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

poetry.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ black = "^21.10b0"
2626
pytest = "^6.2.5"
2727
isort = "^5.10.0"
2828
pytest-httpx = "^0.14.0"
29+
pytest-asyncio = "^0.16.0"
2930

3031
[build-system]
3132
requires = ["poetry-core>=1.0.0"]

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for the Luftdaten API client."""

tests/test_timeout.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Test the interaction with the Luftdaten API."""
2+
import httpx
3+
import pytest
4+
from pytest_httpx import HTTPXMock
5+
6+
from luftdaten import Luftdaten
7+
8+
SENSOR_ID = 1
9+
10+
@pytest.mark.asyncio
11+
async def test_timeout(httpx_mock: HTTPXMock):
12+
"""Test if the connection is hitting the timeout."""
13+
14+
def raise_timeout(request, extensions: dict):
15+
"""Set the timeout for the requests."""
16+
raise httpx.ReadTimeout(
17+
f"Unable to read within {extensions['timeout']}", request=request
18+
)
19+
20+
httpx_mock.add_callback(raise_timeout)
21+
22+
with pytest.raises(httpx.ReadTimeout):
23+
client = Luftdaten(SENSOR_ID)
24+
await client.get_data()

0 commit comments

Comments
 (0)