File: test_info.py

package info (click to toggle)
python-vehicle 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: python: 395; makefile: 8; sh: 5
file content (71 lines) | stat: -rw-r--r-- 1,836 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Tests for the vehicle Library."""

import aiohttp
import pytest
from aresponses import ResponsesMockServer
from syrupy import SnapshotAssertion

from vehicle import (
    RDW,
    RDWError,
    RDWUnknownLicensePlateError,
    Vehicle,
)

from . import load_fixture


@pytest.mark.parametrize(
    "license_plate",
    [
        "11ZKZ3",
        "0001TJ",
        "VXJ99N",
    ],
)
async def test_vehicle_data(
    aresponses: ResponsesMockServer,
    license_plate: str,
    snapshot: SnapshotAssertion,
) -> None:
    """Test getting Vehicle information."""
    aresponses.add(
        "opendata.rdw.nl",
        "/resource/m9d7-ebf2.json",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture(f"{license_plate}.json"),
        ),
    )
    async with aiohttp.ClientSession() as session:
        rdw = RDW(session=session)
        vehicle: Vehicle = await rdw.vehicle(license_plate)
        assert vehicle == snapshot
        assert vehicle.to_json() == snapshot


async def test_no_vehicle(aresponses: ResponsesMockServer) -> None:
    """Test getting non-existing Vehicle."""
    aresponses.add(
        "opendata.rdw.nl",
        "/resource/m9d7-ebf2.json",
        "GET",
        aresponses.Response(
            status=200,
            headers={"Content-Type": "application/json"},
            text=load_fixture("no_vehicles.json"),
        ),
    )
    async with aiohttp.ClientSession() as session:
        rdw = RDW(session=session)
        with pytest.raises(RDWUnknownLicensePlateError):
            await rdw.vehicle("00-00-00")


async def test_no_license_plate_provided() -> None:
    """Test getting Vehicle without license plate."""
    rdw = RDW()
    with pytest.raises(RDWError):
        await rdw.vehicle()