Пример #1
0
def test_validate_get_composite_profile_payload():
    """" Test if payloads with floats are validated correctly.

    This test uses the value of 15.2, which is internally represented as
    15.19999999999999857891452847979962825775146484375.
    You can verify this using `decimal.Decimal(15.2)`
    """
    message = CallResult(unique_id="1234",
                         action="GetCompositeSchedule",
                         payload={
                             'status': 'Accepted',
                             'connectorId': 1,
                             'scheduleStart': '2021-06-15T14:01:32Z',
                             'chargingSchedule': {
                                 'duration':
                                 60,
                                 'chargingRateUnit':
                                 'A',
                                 'chargingSchedulePeriod': [{
                                     'startPeriod': 0,
                                     'limit': 15.2
                                 }]
                             }
                         })

    validate_payload(message, ocpp_version="1.6")
Пример #2
0
def test_call_result_representation():
    call = CallResult(
        unique_id="1", action=Action.Authorize, payload={"status": "Accepted"}
    )

    assert str(call) == \
        "<CallResult - unique_id=1, action=Authorize, payload={'status': " \
        "'Accepted'}>"
Пример #3
0
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)
Пример #4
0
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")
Пример #5
0
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")
Пример #6
0
def test_validate_payload_with_invalid_additional_properties_payload():
    """
    Test if validate_payload raises FormatViolationError when validation of
    payload with unrequested properties fails.
    """
    message = CallResult(
        unique_id="1234",
        action="Heartbeat",
        payload={'invalid_key': True},
    )

    with pytest.raises(FormatViolationError):
        validate_payload(message, ocpp_version="1.6")
Пример #7
0
def test_create_call_error_invalid():
    payload = asdict(call_result_v16.StatusNotificationPayload())
    call_result: CallResult = CallResult(unique_id=123, payload=payload)
    message = call_result.to_json()
    with pytest.raises(ValueError):
        create_call_error(message)