Skip to content

Commit a99e73c

Browse files
Raise maxLength violation as ocpp error (mobilityhouse#312)
According to ocpp-j-1.6-specification , section "4.2.3 CallError", a unique identifier that is too long is a reason for a call error of type TypeConstraintViolationError
1 parent 0d185a1 commit a99e73c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ocpp/messages.py

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ def validate_payload(message, ocpp_version):
197197
raise FormatViolationError(details={"cause": e.message})
198198
elif (e.validator == SchemaValidators.required.__name__):
199199
raise ProtocolError(details={"cause": e.message})
200+
elif e.validator == "maxLength":
201+
raise TypeConstraintViolationError(
202+
details={"cause": e.message}) from e
200203
else:
201204
raise ValidationError(f"Payload '{message.payload} for action "
202205
f"'{message.action}' is not valid: {e}")

tests/test_messages.py

+18
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,21 @@ def test_validate_meter_values_hertz():
328328
)
329329

330330
validate_payload(message, ocpp_version="1.6")
331+
332+
333+
def test_validate_set_maxlength_violation_payload():
334+
"""
335+
Test if payloads that violate maxLength raise a
336+
TypeConstraintViolationError
337+
"""
338+
message = Call(
339+
unique_id="1234",
340+
action="StartTransaction",
341+
payload={
342+
"idTag": "012345678901234567890",
343+
"connectorId": 1,
344+
},
345+
)
346+
347+
with pytest.raises(TypeConstraintViolationError):
348+
validate_payload(message, ocpp_version="1.6")

0 commit comments

Comments
 (0)