59 lines
1.4 KiB
Python
59 lines
1.4 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 GestureCommand(endpoint=RIEndpoint.PING, data="Hey!")
|
|
|
|
|
|
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)
|