-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_client.py
More file actions
44 lines (30 loc) · 1.23 KB
/
test_client.py
File metadata and controls
44 lines (30 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Test TTN client."""
import pytest
import ttn_client
pytest_plugins = "pytest_asyncio"
@pytest.mark.asyncio
async def test_mocked_connection(dummy_client, mock_aiohttp_client_session_get):
"""Test client with mocked data."""
with mock_aiohttp_client_session_get(
{"result": {"end_device_ids": {"device_id": "dummy"}, "uplink_message": {}}},
200,
):
await dummy_client.fetch_data()
with mock_aiohttp_client_session_get({}, 200):
await dummy_client.fetch_data()
@pytest.mark.asyncio
async def test_connection_auth_error(dummy_client):
"""Test that dummy credentials fail."""
with pytest.raises(ttn_client.TTNAuthError):
await dummy_client.fetch_data()
@pytest.mark.asyncio
async def test_invalid_get_status(dummy_client, mock_aiohttp_client_session_get):
"""Test client with mocked data."""
with mock_aiohttp_client_session_get({}, 500):
with pytest.raises(RuntimeError):
await dummy_client.fetch_data()
@pytest.mark.asyncio
async def test_missing_result(dummy_client, mock_aiohttp_client_session_get):
"""Test client with mocked data."""
with mock_aiohttp_client_session_get({"missing_result": {}}, 200):
await dummy_client.fetch_data()