Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_call_result_representation():
call = CallResult(
unique_id="1", action=Action.Authorize, payload={"status": "Accepted"}
)
assert str(call) == \
""
def test_validate_payload_with_invalid_payload():
"""
Test if validate_payload raises ValidationError when validation of
payload failes.
"""
message = CallResult(
unique_id="1234",
action="Heartbeat",
payload={'invalid_key': True},
)
with pytest.raises(ValidationError):
validate_payload(message, ocpp_version="1.6")
def test_validate_payload_with_non_existing_schema():
"""
Test if correct exception is raised when a validation schema cannot be
found.
"""
message = CallResult(
unique_id="1234",
action="MagicSpell",
payload={'invalid_key': True},
)
with pytest.raises(ValidationError):
validate_payload(message, ocpp_version="1.6")
def test_validate_payload_with_valid_payload(ocpp_version):
"""
Test if validate_payload doesn't return any exceptions when it's
validating a valid payload.
"""
message = CallResult(
unique_id="1234",
action="Heartbeat",
payload={'currentTime': datetime.now().isoformat()}
)
validate_payload(message, ocpp_version=ocpp_version)
def create_call_result(self, payload):
call_result = CallResult(self.unique_id, payload)
call_result.action = self.action
return call_result