How to use the ocpp.exceptions.ValidationError function in ocpp

To help you get started, we’ve selected a few ocpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mobilityhouse / ocpp / tests / test_messages.py View on Github external
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")
github mobilityhouse / ocpp / tests / test_messages.py View on Github external
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")
github mobilityhouse / ocpp / ocpp / messages.py View on Github external
message.action == ['GetCompositeSchedule'])
        ):
            schema = get_schema(
                message.message_type_id, message.action,
                ocpp_version, parse_float=decimal.Decimal
            )

            message.payload = json.loads(
                json.dumps(message.payload), parse_float=decimal.Decimal
            )
        else:
            schema = get_schema(
                message.message_type_id, message.action, ocpp_version
            )
    except (OSError, json.JSONDecodeError) as e:
        raise ValidationError("Failed to load validation schema for action "
                              f"'{message.action}': {e}")

    try:
        validate(message.payload, schema)
    except SchemaValidationError as e:
        raise ValidationError(f"Payload '{message.payload} for action "
                              f"'{message.action}' is not valid: {e}")