89 lines
2.1 KiB
Python
89 lines
2.1 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from control_backend.schemas.ri_message import GestureCommand, RIEndpoint, RIMessage, SpeechCommand
|
|
|
|
|
|
def valid_command_1():
|
|
return SpeechCommand(data="Hallo?")
|
|
|
|
|
|
def valid_command_2():
|
|
return GestureCommand(endpoint=RIEndpoint.GESTURE_TAG, data="happy")
|
|
|
|
|
|
def valid_command_3():
|
|
return GestureCommand(endpoint=RIEndpoint.GESTURE_SINGLE, data="happy_1")
|
|
|
|
|
|
def invalid_command_1():
|
|
return RIMessage(endpoint=RIEndpoint.PING, data="Hello again.")
|
|
|
|
|
|
def invalid_command_2():
|
|
return RIMessage(endpoint=RIEndpoint.PING, data="Hey!")
|
|
|
|
|
|
def invalid_command_3():
|
|
return RIMessage(endpoint=RIEndpoint.GESTURE_SINGLE, data={1, 2, 3})
|
|
|
|
|
|
def invalid_command_4():
|
|
test: RIMessage = GestureCommand(endpoint=RIEndpoint.GESTURE_SINGLE, data="asdsad")
|
|
|
|
def change_endpoint(msg: RIMessage):
|
|
msg.endpoint = RIEndpoint.PING
|
|
|
|
change_endpoint(test)
|
|
return test
|
|
|
|
|
|
def test_valid_speech_command_1():
|
|
command = valid_command_1()
|
|
RIMessage.model_validate(command)
|
|
SpeechCommand.model_validate(command)
|
|
|
|
|
|
def test_valid_gesture_command_1():
|
|
command = valid_command_2()
|
|
RIMessage.model_validate(command)
|
|
GestureCommand.model_validate(command)
|
|
|
|
|
|
def test_valid_gesture_command_2():
|
|
command = valid_command_3()
|
|
RIMessage.model_validate(command)
|
|
GestureCommand.model_validate(command)
|
|
|
|
|
|
def test_invalid_speech_command_1():
|
|
command = invalid_command_1()
|
|
RIMessage.model_validate(command)
|
|
|
|
with pytest.raises(ValidationError):
|
|
SpeechCommand.model_validate(command)
|
|
|
|
|
|
def test_invalid_gesture_command_1():
|
|
command = invalid_command_2()
|
|
RIMessage.model_validate(command)
|
|
|
|
with pytest.raises(ValidationError):
|
|
GestureCommand.model_validate(command)
|
|
|
|
|
|
def test_invalid_gesture_command_2():
|
|
command = invalid_command_3()
|
|
RIMessage.model_validate(command)
|
|
|
|
with pytest.raises(ValidationError):
|
|
GestureCommand.model_validate(command)
|
|
|
|
|
|
def test_invalid_gesture_command_3():
|
|
command = invalid_command_4()
|
|
RIMessage.model_validate(command)
|
|
|
|
with pytest.raises(ValidationError):
|
|
GestureCommand.model_validate(command)
|