From 6f89603dc750eb0af8ad00b319bd62af4ba867c7 Mon Sep 17 00:00:00 2001 From: Oleksandr Bozbei Date: Tue, 26 Sep 2023 16:32:13 +0300 Subject: [PATCH] test: Add logging to test github runner. --- py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py | 8 ++++++++ py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py | 14 ++++++++++++++ tests/test_modules/test_v_2_1_1/test_cdrs.py | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py b/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py index 3022e12..d5c135d 100644 --- a/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py +++ b/py_ocpi/modules/cdrs/v_2_1_1/api/cpo.py @@ -1,3 +1,5 @@ +import logging + from fastapi import APIRouter, Depends, Response, Request from py_ocpi.modules.versions.enums import VersionNumber @@ -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, @@ -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, diff --git a/py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py b/py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py index 29f3964..bf2b27c 100644 --- a/py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py +++ b/py_ocpi/modules/cdrs/v_2_1_1/api/emsp.py @@ -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 @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/test_modules/test_v_2_1_1/test_cdrs.py b/tests/test_modules/test_v_2_1_1/test_cdrs.py index 2147d67..dd1f846 100644 --- a/tests/test_modules/test_v_2_1_1/test_cdrs.py +++ b/tests/test_modules/test_v_2_1_1/test_cdrs.py @@ -1,3 +1,5 @@ +import logging + from uuid import uuid4 from fastapi.testclient import TestClient @@ -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"] @@ -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"] @@ -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