From efedb2533bdc5b0a5883c9616a47f0276806d56f Mon Sep 17 00:00:00 2001 From: profitroll Date: Fri, 24 Nov 2023 13:35:47 +0100 Subject: [PATCH] WIP: Automatic tests --- tests/conftest.py | 21 ++++++++++++++ tests/test_client.py | 67 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8fff836..53a6c4c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ from os import environ +from typing import List import pytest @@ -13,3 +14,23 @@ def api_token() -> str: @pytest.fixture() def api_client(api_token: str) -> Client: return Client(api_token) + + +@pytest.fixture() +def sample_stop_id() -> str: + return "A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@" + + +@pytest.fixture() +def sample_journey_id() -> str: + return "2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#" + + +@pytest.fixture() +def sample_origin() -> List[str]: + return ["50.084659", "8.785948"] + + +@pytest.fixture() +def sample_destination() -> List[float]: + return [50.1233048, 8.6129742] diff --git a/tests/test_client.py b/tests/test_client.py index 071a465..4f5a7b1 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,7 +1,70 @@ +from datetime import datetime, timedelta +from typing import List + import pytest -from pyrmv import Client -from pyrmv.classes import Stop +from pyrmv import Client, enums +from pyrmv.classes import Journey, Message, Stop, Trip +from pyrmv.classes.board import BoardArrival, BoardDeparture + + +def test_board_arrival(api_client: Client, sample_stop_id: str): + assert isinstance( + api_client.board_arrival(id=sample_stop_id, journeys_max=3), BoardArrival + ) + + +def test_board_departure(api_client: Client, sample_stop_id: str): + assert isinstance( + api_client.board_departure(id=sample_stop_id, journeys_max=3), BoardDeparture + ) + + +def test_him_search(api_client: Client): + assert isinstance( + api_client.him_search(date_end=datetime.now() + timedelta(days=10))[0], Message + ) + + +# Does not work as it should yet +# def test_journey_detail(api_client: Client, sample_journey_id: str): +# assert ( +# api_client.journey_detail( +# sample_journey_id, +# real_time_mode=enums.RealTimeMode.FULL, +# ), +# Journey, +# ) + + +def test_stop_by_coords(api_client: Client, sample_origin: List[str]): + assert isinstance( + api_client.stop_by_coords(sample_origin[0], sample_origin[1], max_number=3)[0], Stop + ) + + +def test_stop_by_id(api_client: Client, sample_stop_id: str): + assert isinstance(api_client.stop_by_id(sample_stop_id), Stop) + + +def test_trip_find( + api_client: Client, sample_origin: List[str], sample_destination: List[float] +): + assert isinstance( + api_client.trip_find( + origin_coord_lat=sample_origin[0], + origin_coord_lon=sample_origin[1], + destination_coord_lat=sample_destination[0], + destination_coord_lon=sample_destination[1], + messages=True, + )[0], + Trip, + ) + + +# Does not work as it should yet +# def test_trip_recon(api_client: Client): +# assert api_client.trip_recon() def test_stop_by_name(api_client: Client):