Skip to content

Commit

Permalink
test: Add logging to test github runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-bozbei-ew committed Sep 26, 2023
1 parent bb8be9a commit 6f89603
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from fastapi import APIRouter, Depends, Response, Request

from py_ocpi.modules.versions.enums import VersionNumber
Expand All @@ -23,6 +25,7 @@ async def get_cdrs(
filters: dict = Depends(pagination_filters),
):
auth_token = get_auth_token_from_header(request)
logging.info(f"AUTH TOKEN - {auth_token}")

data_list = await get_list(
response,
Expand All @@ -33,10 +36,15 @@ async def get_cdrs(
crud,
auth_token=auth_token,
)
logging.info(f"DATA - list - {data_list}")

cdrs = []
for data in data_list:
logging.info(
f"Adapter - {adapter.cdr_adapter(data, VersionNumber.v_2_1_1).dict()}"
)
cdrs.append(adapter.cdr_adapter(data, VersionNumber.v_2_1_1).dict())
logging.info(f"CDRS - {cdrs}")
return OCPIResponse(
data=cdrs,
**status.OCPI_1000_GENERIC_SUCESS_CODE,
Expand Down
14 changes: 14 additions & 0 deletions py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from fastapi import APIRouter, Depends, Request, Response

from py_ocpi.modules.cdrs.v_2_1_1.schemas import Cdr
Expand Down Expand Up @@ -25,6 +27,7 @@ async def get_cdr(
adapter: Adapter = Depends(get_adapter),
):
auth_token = get_auth_token_from_header(request)
logging.info(f"AUTH TOKEN - {auth_token}")

data = await crud.get(
ModuleID.cdrs,
Expand All @@ -33,6 +36,11 @@ async def get_cdr(
auth_token=auth_token,
version=VersionNumber.v_2_1_1,
)
logging.info(f"DATA - {data}")

logging.info(
f"Adapter - {adapter.cdr_adapter(data, VersionNumber.v_2_1_1).dict()}"
)
return OCPIResponse(
data=[adapter.cdr_adapter(data, VersionNumber.v_2_1_1).dict()],
**status.OCPI_1000_GENERIC_SUCESS_CODE,
Expand All @@ -48,6 +56,7 @@ async def add_cdr(
adapter: Adapter = Depends(get_adapter),
):
auth_token = get_auth_token_from_header(request)
logging.info(f"AUTH TOKEN - {auth_token}")

data = await crud.create(
ModuleID.cdrs,
Expand All @@ -56,14 +65,19 @@ async def add_cdr(
auth_token=auth_token,
version=VersionNumber.v_2_1_1,
)
logging.info(f"Data - {data}")

cdr_data = adapter.cdr_adapter(data, VersionNumber.v_2_1_1)
logging.info(f"CDR data - {cdr_data}")
cdr_url = (
f"https://{settings.OCPI_HOST}/{settings.OCPI_PREFIX}/emsp"
f"/{VersionNumber.v_2_1_1}/{ModuleID.cdrs}/{cdr_data.id}"
)
logging.info(f"CDR url - {cdr_url}")
response.headers.append("Location", cdr_url)

logging.info(f"CDR dict - {cdr_data.dict()}")

return OCPIResponse(
data=[cdr_data.dict()],
**status.OCPI_1000_GENERIC_SUCESS_CODE,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_modules/test_v_2_1_1/test_cdrs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from uuid import uuid4

from fastapi.testclient import TestClient
Expand Down Expand Up @@ -89,6 +91,8 @@ def test_cpo_get_cdrs_v_2_1_1():
client = TestClient(app)
response = client.get("/ocpi/cpo/2.1.1/cdrs")

logging.info(f"{response.status_code} - {response.json()}")

assert response.status_code == 200
assert len(response.json()["data"]) == 1
assert response.json()["data"][0]["id"] == CDRS[0]["id"]
Expand All @@ -105,6 +109,8 @@ def test_emsp_get_cdr_v_2_1_1():
client = TestClient(app)
response = client.get(f'/ocpi/emsp/2.1.1/cdrs/{CDRS[0]["id"]}')

logging.info(f"{response.status_code} - {response.json()}")

assert response.status_code == 200
assert response.json()["data"][0]["id"] == CDRS[0]["id"]

Expand All @@ -122,6 +128,8 @@ def test_emsp_add_cdr_v_2_1_1():
client = TestClient(app)
response = client.post("/ocpi/emsp/2.1.1/cdrs/", json=data)

logging.info(f"{response.status_code} - {response.json()}")

assert response.status_code == 200
assert response.json()["data"][0]["id"] == CDRS[0]["id"]
assert response.headers["Location"] is not None

0 comments on commit 6f89603

Please sign in to comment.