error on invalid role

This commit is contained in:
Blake Blackshear 2021-08-28 08:16:25 -05:00
parent 0d352f3d8a
commit 11c425a7eb
2 changed files with 34 additions and 3 deletions

View File

@ -332,9 +332,15 @@ class FfmpegConfig(BaseModel):
) )
class CameraRoleEnum(str, Enum):
record = "record"
rtmp = "rtmp"
detect = "detect"
class CameraInput(BaseModel): class CameraInput(BaseModel):
path: str = Field(title="Camera input path.") path: str = Field(title="Camera input path.")
roles: List[str] = Field(title="Roles assigned to this input.") roles: List[CameraRoleEnum] = Field(title="Roles assigned to this input.")
global_args: Union[str, List[str]] = Field( global_args: Union[str, List[str]] = Field(
default_factory=list, title="FFmpeg global arguments." default_factory=list, title="FFmpeg global arguments."
) )

View File

@ -32,8 +32,8 @@ class TestConfig(unittest.TestCase):
assert self.minimal == frigate_config.dict(exclude_unset=True) assert self.minimal == frigate_config.dict(exclude_unset=True)
runtime_config = frigate_config.runtime_config runtime_config = frigate_config.runtime_config
assert "coral" in runtime_config.detectors.keys() assert "cpu" in runtime_config.detectors.keys()
assert runtime_config.detectors["coral"].type == DetectorTypeEnum.edgetpu assert runtime_config.detectors["cpu"].type == DetectorTypeEnum.cpu
def test_invalid_mqtt_config(self): def test_invalid_mqtt_config(self):
config = { config = {
@ -692,6 +692,31 @@ class TestConfig(unittest.TestCase):
runtime_config = frigate_config.runtime_config runtime_config = frigate_config.runtime_config
assert runtime_config.model.merged_labelmap[0] == "person" assert runtime_config.model.merged_labelmap[0] == "person"
def test_fails_on_invalid_role(self):
config = {
"mqtt": {"host": "mqtt"},
"cameras": {
"back": {
"ffmpeg": {
"inputs": [
{
"path": "rtsp://10.0.0.1:554/video",
"roles": ["detect", "clips"],
},
]
},
"detect": {
"height": 1080,
"width": 1920,
"fps": 5,
},
}
},
}
self.assertRaises(ValidationError, lambda: FrigateConfig(**config))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main(verbosity=2) unittest.main(verbosity=2)