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_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_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_invalid_message_type_id():
"""
Test if validate_payload raises ValidationError when it is called with
a message type id other than 2, Call, or 3, CallError.
"""
with pytest.raises(ValidationError):
validate_payload(dict(), 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)
'stackLevel': 0,
'chargingProfilePurpose': 'TxProfile',
'chargingProfileKind': 'Relative',
'chargingSchedule': {
'chargingRateUnit': 'A',
'chargingSchedulePeriod': [{
'startPeriod': 0,
'limit': 21.4
}]
},
'transactionId': 123456789,
}
}
)
validate_payload(message, ocpp_version="1.6")
def test_call_result_representation():
call = CallResult(
unique_id="1", action=Action.Authorize, payload={"status": "Accepted"}
)
assert str(call) == \
""
@after(Action.BootNotification)
def after_boot_notification(charge_point_model, charge_point_vendor,
**kwargs): # noqa
assert charge_point_vendor == "Alfen BV"
assert charge_point_model == "ICU Eve Mini"
@on(Action.Heartbeat, skip_schema_validation=True)
def on_heartbeat(self):
pass
def test_call_representation():
call = Call(unique_id="1", action=Action.Heartbeat, payload={})
assert str(call) == ""
def meter_values(self):
pass
def undecorated(self):
pass
cp = ChargePoint()
route_map = create_route_map(cp)
assert route_map == {
Action.Heartbeat: {
'_on_action': cp.on_heartbeat,
'_after_action': cp.after_heartbeat,
'_skip_schema_validation': True,
},
Action.MeterValues: {
'_on_action': cp.meter_values,
'_skip_schema_validation': False,
},