File: test_renault_client.py

package info (click to toggle)
python-renault-api 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,696 kB
  • sloc: python: 7,804; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (2)
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
61
62
63
64
"""Test cases for the Renault client API keys."""

import aiohttp
import pytest
from aioresponses import aioresponses

from tests import fixtures
from tests.const import TEST_ACCOUNT_ID
from tests.const import TEST_COUNTRY
from tests.const import TEST_LOCALE_DETAILS
from tests.test_credential_store import get_logged_in_credential_store
from tests.test_renault_session import get_logged_in_session

from renault_api.renault_client import RenaultClient


@pytest.fixture
def client(websession: aiohttp.ClientSession) -> RenaultClient:
    """Fixture for testing RenaultClient."""
    return RenaultClient(
        session=get_logged_in_session(websession),
    )


def test_init(websession: aiohttp.ClientSession) -> None:
    """Test RenaultClient initialisation."""
    assert RenaultClient(
        session=get_logged_in_session(websession),
    )

    assert RenaultClient(
        websession=websession,
        country=TEST_COUNTRY,
        locale_details=TEST_LOCALE_DETAILS,
        credential_store=get_logged_in_credential_store(),
    )


@pytest.mark.asyncio
async def test_get_person(
    client: RenaultClient, mocked_responses: aioresponses
) -> None:
    """Test get_person."""
    fixtures.inject_get_person(mocked_responses)
    person = await client.get_person()
    assert person.accounts is not None
    assert len(person.accounts) == 2


@pytest.mark.asyncio
async def test_get_api_accounts(
    client: RenaultClient, mocked_responses: aioresponses
) -> None:
    """Test get_api_accounts."""
    fixtures.inject_get_person(mocked_responses)
    accounts = await client.get_api_accounts()
    assert len(accounts) == 2


@pytest.mark.asyncio
async def test_get_api_account(client: RenaultClient) -> None:
    """Test get_api_account."""
    account = await client.get_api_account(TEST_ACCOUNT_ID)
    assert account._account_id == TEST_ACCOUNT_ID