Skip to content

Commit

Permalink
E2E tests: use Python client for agency test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed May 3, 2024
1 parent 4d1e180 commit c2402e4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
30 changes: 27 additions & 3 deletions tests/endtoend/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ class System(ApiType):
routes: ChildResources


@dataclasses.dataclass
class Agency(ApiType):
id: str
# todo: system, resource
name: str
url: str
timezone: str
language: str
phone: str
fareUrl: str
email: str
# todo: routes


@dataclasses.dataclass
class Transfer(ApiType):
id: str
Expand Down Expand Up @@ -93,6 +107,11 @@ class ListStopsResponse(ApiType):
stops: typing.List[Stop]


@dataclasses.dataclass
class ListAgenciesResponse(ApiType):
agencies: typing.List[Agency]


@dataclasses.dataclass
class ListTransfersResponse(ApiType):
transfers: typing.List[Transfer]
Expand All @@ -108,13 +127,18 @@ def __init__(self, transiter_host):
self._transiter_host = transiter_host

def _get(self, cls: ApiType, relative_url: str, params={}):
return cls.from_api(
requests.get(f"{self._transiter_host}/{relative_url}", params=params).json()
)
j = requests.get(f"{self._transiter_host}/{relative_url}", params=params).json()
return cls.from_api(j)

def get_system(self, system_id: str) -> System:
return self._get(System, f"systems/{system_id}")

def list_agencies(self, system_id: str) -> ListAgenciesResponse:
return self._get(ListAgenciesResponse, f"systems/{system_id}/agencies")

def get_agency(self, system_id: str, agency_id: str) -> Agency:
return self._get(Agency, f"systems/{system_id}/agencies/{agency_id}")

def list_stops(self, system_id: str, params={}) -> ListStopsResponse:
return self._get(ListStopsResponse, f"systems/{system_id}/stops", params)

Expand Down
24 changes: 24 additions & 0 deletions tests/endtoend/test_agencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from . import client


def test_agencies(
system_id, install_system_1, transiter_client: client.TransiterClient
):
install_system_1(system_id)

want_agency = client.Agency(
id="AgencyId",
name="AgencyName",
url="AgencyUrl",
timezone="AgencyTimezone",
language="AgencyLanguage",
phone="AgencyPhone",
fareUrl="AgencyFareUrl",
email="AgencyEmail",
)

got_agencies = transiter_client.list_agencies(system_id)
assert got_agencies.agencies == [want_agency]

got_agency = transiter_client.get_agency(system_id, "AgencyId")
assert got_agency == want_agency
21 changes: 0 additions & 21 deletions tests/endtoend/test_installsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,6 @@ def test_install_system__service_map_route(system_id, install_system_1, transite
assert usual_stops == actual_stops


def test_install_system__agency(system_id, install_system_1, transiter_host):
install_system_1(system_id)

agencies_response = requests.get(
transiter_host + "/systems/" + system_id + "/agencies"
).json()["agencies"]
assert 1 == len(agencies_response)

agency_response = requests.get(
transiter_host + "/systems/" + system_id + "/agencies/AgencyId"
).json()
assert "AgencyId" == agency_response["id"]
assert "AgencyName" == agency_response["name"]
assert "AgencyUrl" == agency_response["url"]
assert "AgencyTimezone" == agency_response["timezone"]
assert "AgencyLanguage" == agency_response["language"]
assert "AgencyPhone" == agency_response["phone"]
assert "AgencyFareUrl" == agency_response["fareUrl"]
assert "AgencyEmail" == agency_response["email"]


def _test_install_system__bad_config(system_id, install_system, transiter_host):
install_system(
system_id,
Expand Down

0 comments on commit c2402e4

Please sign in to comment.