Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hhuseyinpay committed Sep 22, 2024
2 parents 33e4512 + d59ecf1 commit 7d69976
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change log

## 2.0.0-rc.2 (2024-06-18)

- [#315](https://github.com/mobilityhouse/ocpp/pull/315) Allow to skip schema validation in `ChargePoint.call()`. Thanks [@esiebert](https://github.com/esiebert)!

## 2.0.0-rc.1 (2024-06-01)

## BREAKING ##
- [#642](https://github.com/mobilityhouse/ocpp/pull/642) Fix serializing of "ocpp_csms_url".

## 2.0.0-rc.0 (2024-05-22)

- [#631](https://github.com/mobilityhouse/ocpp/pull/631) Fix publishing to Pypi.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Auke Willem Oosterhoff"

# The full version, including alpha/beta/rc tags
release = "2.0.0-rc.0"
release = "2.0.0-rc.2"


# -- General configuration ---------------------------------------------------
Expand Down
20 changes: 14 additions & 6 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def camel_to_snake_case(data):
if isinstance(data, dict):
snake_case_dict = {}
for key, value in data.items():
key = key.replace("ocppCSMS", "ocpp_csms")
key = key.replace("V2X", "_v2x")
key = key.replace("ocppCSMSURL", "ocpp_csms_url")
key = key.replace("V2X", "_v2x").replace("V2G", "_v2g")
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", key)
key = re.sub("([a-z0-9])([A-Z])(?=\\S)", r"\1_\2", s1).lower()
Expand Down Expand Up @@ -57,7 +56,10 @@ def snake_to_camel_case(data):
for key, value in data.items():
key = key.replace("soc", "SoC")
key = key.replace("_v2x", "V2X")
key = key.replace("ocpp_csms", "ocppCSMS")
# The spec uses inconsent casing for "csms" and "url".
# E.g. "OcppCsmsUrl" vs "ResponderURL" and "CSMSRootCertificate"
key = key.replace("ocpp_csms_url", "ocppCsmsUrl")
key = key.replace("csms", "CSMS")
key = key.replace("_url", "URL")
key = key.replace("soc", "SoC").replace("_SoCket", "Socket")
key = key.replace("_v2x", "V2X")
Expand Down Expand Up @@ -363,7 +365,9 @@ async def _handle_call(self, msg):
pass
return response

async def call(self, payload, suppress=True, unique_id=None):
async def call(
self, payload, suppress=True, unique_id=None, skip_schema_validation=False
):
"""
Send Call message to client and return payload of response.
Expand All @@ -384,6 +388,9 @@ async def call(self, payload, suppress=True, unique_id=None):
set to False, an exception will be raised for users to handle this
CallError.
Schema validation can be skipped for the request and the response
for this call by setting `skip_schema_validation` to `True`.
"""
camel_case_payload = snake_to_camel_case(serialize_as_dict(payload))

Expand All @@ -402,7 +409,8 @@ async def call(self, payload, suppress=True, unique_id=None):
payload=remove_nones(camel_case_payload),
)

validate_payload(call, self._ocpp_version)
if not skip_schema_validation:
validate_payload(call, self._ocpp_version)

# Use a lock to prevent make sure that only 1 message can be send at a
# a time.
Expand All @@ -423,7 +431,7 @@ async def call(self, payload, suppress=True, unique_id=None):
if suppress:
return
raise response.to_exception()
else:
elif not skip_schema_validation:
response.action = call.action
validate_payload(response, self._ocpp_version)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ocpp"
version = "2.0.0-rc.0"
version = "2.0.0-rc.2"
description = "Python package implementing the JSON version of the Open Charge Point Protocol (OCPP)."
authors = [
"André Duarte <andre15x@gmail.com>",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def heartbeat(self, **kwargs):
({"responderURL": "foo.com"}, {"responder_url": "foo.com"}),
({"url": "foo.com"}, {"url": "foo.com"}),
({"ocppCSMSURL": "foo.com"}, {"ocpp_csms_url": "foo.com"}),
({"CSMSRootCertificate": "foo.com"}, {"csms_root_certificate": "foo.com"}),
({"InvalidURL": "foo.com"}, {"invalid_url": "foo.com"}),
({"evMinV2XEnergyRequest": 200}, {"ev_min_v2x_energy_request": 200}),
({"v2xChargingCtrlr": 200}, {"v2x_charging_ctrlr": 200}),
Expand All @@ -95,7 +96,8 @@ def test_camel_to_snake_case(test_input, expected):
({"v2x_charging_ctrlr": 200}, {"v2xChargingCtrlr": 200}),
({"responder_url": "foo.com"}, {"responderURL": "foo.com"}),
({"url": "foo.com"}, {"url": "foo.com"}),
({"ocpp_csms_url": "foo.com"}, {"ocppCSMSURL": "foo.com"}),
({"ocpp_csms_url": "foo.com"}, {"ocppCsmsUrl": "foo.com"}),
({"csms_root_certificate": "foo.com"}, {"CSMSRootCertificate": "foo.com"}),
({"invalid_url": "foo.com"}, {"invalidURL": "foo.com"}),
({"web_socket_ping_interval": 200}, {"webSocketPingInterval": 200}),
({"sign_v2g_certificate": 200}, {"signV2GCertificate": 200}),
Expand Down
10 changes: 10 additions & 0 deletions tests/v16/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from unittest.mock import AsyncMock

import pytest
Expand Down Expand Up @@ -50,6 +51,15 @@ def mock_boot_request():
)


@pytest.fixture
def mock_invalid_boot_request():
@dataclass
class BootNotification:
custom_field: str

return BootNotification(custom_field="custom_field")


@pytest.fixture
def mock_base_central_system(base_central_system):
mock_result_call = CallResult(
Expand Down
26 changes: 26 additions & 0 deletions tests/v16/test_v16_charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,29 @@ async def test_call_without_unique_id_should_return_a_random_value(
) = mock_base_central_system._get_specific_response.call_args_list[0][0]
# Check the actual unique id is equals to the one internally generated
assert actual_unique_id == expected_unique_id


@pytest.mark.asyncio
async def test_call_skip_schema_validation(
mock_invalid_boot_request, mock_base_central_system
):
"""
Test that schema validation is skipped for an invalid boot notification request.
"""

expected_unique_id = "12345"
# Call the method being tested with an invalid boot notification request
# and a unique_id as a parameter
await mock_base_central_system.call(
mock_invalid_boot_request,
unique_id=expected_unique_id,
skip_schema_validation=True,
)
(
actual_unique_id,
_,
) = mock_base_central_system._get_specific_response.call_args_list[0][0]

# Check the actual unique id is equals to the one passed to the call method
assert actual_unique_id == expected_unique_id

0 comments on commit 7d69976

Please sign in to comment.