File: test_client.py

package info (click to toggle)
python-ttn-client 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 224 kB
  • sloc: python: 493; sh: 13; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download
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()