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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
"""Base client tests."""
import asyncio
import aiohttp
import pytest
from pytraccar import (
ApiClient,
TraccarAuthenticationException,
TraccarConnectionException,
TraccarException,
TraccarResponseException,
)
from tests.common import MockResponse
@pytest.mark.asyncio
async def test_base_api(api_client: ApiClient) -> None:
"""Test base API."""
response = await api_client.get_server()
assert response["bingKey"] == "string"
@pytest.mark.asyncio
async def test_base_api_unauthenticated(
api_client: ApiClient, mock_response: MockResponse
) -> None:
"""Test unauthenticated base API."""
mock_response.mock_status = 401
with pytest.raises(TraccarAuthenticationException):
await api_client.get_server()
@pytest.mark.asyncio
async def test_base_api_issue(
api_client: ApiClient, mock_response: MockResponse
) -> None:
"""Test API issue."""
mock_response.mock_status = 500
with pytest.raises(TraccarResponseException):
await api_client.get_server()
@pytest.mark.asyncio
async def test_base_api_timeout(
api_client: ApiClient, mock_response: MockResponse
) -> None:
"""Test API issue."""
mock_response.mock_raises = asyncio.TimeoutError
with pytest.raises(TraccarConnectionException):
await api_client.get_server()
mock_response.mock_raises = aiohttp.ClientError
with pytest.raises(TraccarConnectionException):
await api_client.get_server()
mock_response.mock_raises = TypeError
with pytest.raises(TraccarException):
await api_client.get_server()
|