Skip to content

Commit

Permalink
Merge pull request #8 from extrawest/bugfix/show-needed-version-detai…
Browse files Browse the repository at this point in the history
…ls-endpoints

[bugfix] Hide unspecified endpoints
  • Loading branch information
andrewdubyniak authored Sep 27, 2023
2 parents 83fe400 + 5de8a35 commit de4218e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
8 changes: 4 additions & 4 deletions py_ocpi/core/endpoints/v_2_1_1/cpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)


ENDPOINTS_LIST = [
CREDENTIALS_AND_REGISTRATION,
LOCATIONS,
]
ENDPOINTS_LIST = {
ModuleID.credentials_and_registration: CREDENTIALS_AND_REGISTRATION,
ModuleID.locations: LOCATIONS,
}
8 changes: 4 additions & 4 deletions py_ocpi/core/endpoints/v_2_1_1/emsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
),
)

ENDPOINTS_LIST = [
CREDENTIALS_AND_REGISTRATION,
LOCATIONS,
]
ENDPOINTS_LIST = {
ModuleID.credentials_and_registration: CREDENTIALS_AND_REGISTRATION,
ModuleID.locations: LOCATIONS,
}
16 changes: 8 additions & 8 deletions py_ocpi/core/endpoints/v_2_2_1/cpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
),
)

ENDPOINTS_LIST = [
CREDENTIALS_AND_REGISTRATION,
LOCATIONS,
SESSIONS,
CDRS,
TARIFFS,
TOKENS,
]
ENDPOINTS_LIST = {
ModuleID.credentials_and_registration: CREDENTIALS_AND_REGISTRATION,
ModuleID.locations: LOCATIONS,
ModuleID.sessions: SESSIONS,
ModuleID.cdrs: CDRS,
ModuleID.tariffs: TARIFFS,
ModuleID.tokens: TOKENS,
}
18 changes: 9 additions & 9 deletions py_ocpi/core/endpoints/v_2_2_1/emsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@
),
)

ENDPOINTS_LIST = [
CREDENTIALS_AND_REGISTRATION,
LOCATIONS,
SESSIONS,
CDRS,
TARIFFS,
COMMANDS,
TOKENS,
]
ENDPOINTS_LIST = {
ModuleID.credentials_and_registration: CREDENTIALS_AND_REGISTRATION,
ModuleID.locations: LOCATIONS,
ModuleID.sessions: SESSIONS,
ModuleID.cdrs: CDRS,
ModuleID.tariffs: TARIFFS,
ModuleID.commands: COMMANDS,
ModuleID.tokens: TOKENS,
}
16 changes: 8 additions & 8 deletions py_ocpi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def get_application(
_app.include_router(
cpo_router,
prefix=f"/{settings.OCPI_PREFIX}/cpo/{version.value}",
tags=[f"CPO {version}"],
tags=[f"CPO {version.value}"],
)
version_endpoints[version] += ENDPOINTS[version][
RoleEnum.cpo
]
endpoint = ENDPOINTS[version][RoleEnum.cpo].get(module)
if endpoint:
version_endpoints[version].append(endpoint)

if RoleEnum.emsp in roles:
for module in modules:
Expand All @@ -140,11 +140,11 @@ def get_application(
_app.include_router(
emsp_router,
prefix=f"/{settings.OCPI_PREFIX}/emsp/{version.value}",
tags=[f"EMSP {version}"],
tags=[f"EMSP {version.value}"],
)
version_endpoints[version] += ENDPOINTS[version][
RoleEnum.emsp
]
endpoint = ENDPOINTS[version][RoleEnum.emsp].get(module)
if endpoint:
version_endpoints[version].append(endpoint)

def override_get_crud():
return crud
Expand Down
8 changes: 6 additions & 2 deletions tests/test_modules/mocks/async_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from py_ocpi.core.dependencies import get_versions
from py_ocpi.core.endpoints import ENDPOINTS
from py_ocpi.core.enums import RoleEnum
from py_ocpi.core.enums import RoleEnum, ModuleID
from py_ocpi.modules.versions.enums import VersionNumber
from py_ocpi.modules.versions.v_2_2_1.schemas import VersionDetail

fake_endpoints_data = {
"data": [
VersionDetail(
version=VersionNumber.v_2_2_1,
endpoints=ENDPOINTS[VersionNumber.v_2_2_1][RoleEnum.cpo],
endpoints=[
ENDPOINTS[VersionNumber.v_2_2_1][RoleEnum.cpo][
ModuleID.locations
]
],
).dict(),
],
}
Expand Down

0 comments on commit de4218e

Please sign in to comment.