From 04373c4fc6480e3e24c85fba4ef652fc41570642 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Mon, 24 Oct 2022 07:05:40 -0600 Subject: [PATCH] Fix tests --- frigate/config.py | 5 +++++ frigate/test/test_config.py | 22 ++++++++++++---------- test.db-journal | Bin 0 -> 29240 bytes web/config/handlers.js | 4 ++-- web/src/routes/Camera.jsx | 4 ++-- web/src/routes/__tests__/Camera.test.jsx | 8 ++++++-- 6 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 test.db-journal diff --git a/frigate/config.py b/frigate/config.py index a01df46c4..19fead137 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -590,12 +590,17 @@ class CameraConfig(FrigateBaseModel): # add roles to the input if there is only one if len(config["ffmpeg"]["inputs"]) == 1: + has_rtmp = "rtmp" in config["ffmpeg"]["inputs"][0]["roles"] + config["ffmpeg"]["inputs"][0]["roles"] = [ "record", "detect", "restream", ] + if has_rtmp: + config["ffmpeg"]["inputs"][0]["roles"].append("rtmp") + super().__init__(**config) @property diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py index 319ae1e3b..70b6ba03f 100644 --- a/frigate/test/test_config.py +++ b/frigate/test/test_config.py @@ -1181,7 +1181,7 @@ class TestConfig(unittest.TestCase): "inputs": [ { "path": "rtsp://10.0.0.1:554/video", - "roles": ["detect"], + "roles": ["detect", "rtmp"], }, ] }, @@ -1225,11 +1225,11 @@ class TestConfig(unittest.TestCase): runtime_config = frigate_config.runtime_config assert not runtime_config.cameras["back"].rtmp.enabled - def test_global_live(self): + def test_global_jsmpeg(self): config = { "mqtt": {"host": "mqtt"}, - "live": {"quality": 4}, + "restream": {"jsmpeg": {"quality": 4}}, "cameras": { "back": { "ffmpeg": { @@ -1247,7 +1247,7 @@ class TestConfig(unittest.TestCase): assert config == frigate_config.dict(exclude_unset=True) runtime_config = frigate_config.runtime_config - assert runtime_config.cameras["back"].live.quality == 4 + assert runtime_config.cameras["back"].restream.jsmpeg.quality == 4 def test_default_live(self): @@ -1270,13 +1270,13 @@ class TestConfig(unittest.TestCase): assert config == frigate_config.dict(exclude_unset=True) runtime_config = frigate_config.runtime_config - assert runtime_config.cameras["back"].live.quality == 8 + assert runtime_config.cameras["back"].restream.jsmpeg.quality == 8 def test_global_live_merge(self): config = { "mqtt": {"host": "mqtt"}, - "live": {"quality": 4, "height": 480}, + "restream": {"jsmpeg": {"quality": 4, "height": 480}}, "cameras": { "back": { "ffmpeg": { @@ -1287,8 +1287,10 @@ class TestConfig(unittest.TestCase): }, ] }, - "live": { - "quality": 7, + "restream": { + "jsmpeg": { + "quality": 7, + } }, } }, @@ -1297,8 +1299,8 @@ class TestConfig(unittest.TestCase): assert config == frigate_config.dict(exclude_unset=True) runtime_config = frigate_config.runtime_config - assert runtime_config.cameras["back"].live.quality == 7 - assert runtime_config.cameras["back"].live.height == 480 + assert runtime_config.cameras["back"].restream.jsmpeg.quality == 7 + assert runtime_config.cameras["back"].restream.jsmpeg.height == 480 def test_global_timestamp_style(self): diff --git a/test.db-journal b/test.db-journal new file mode 100644 index 0000000000000000000000000000000000000000..3649988aaf8590e0b99c00b63e90214a145aebbb GIT binary patch literal 29240 zcmeI5&u`mg7{~3zO`0@m1{YsAxE@2Z*w)0(kCthO&_yM*%UGJida|6vZOsz9i`{A4 z1$9H>I3e*5a7E%z;ItDr1R99zIB?n@up5tm#cASJMdEqsR3t zH_x9h=3Wcm_x@lQCjBb$>rZsfGfaX`7pUNP0|>BNcQy@27j~`DP;&%@R-R>t_EH zY5#DfIfiA50!?FcQqSsssrMXP6q>D0W4+O)u7;N1G^mjlerLqf*Sd8n#b4rC%P{-; zL;ZnnI;uZe?>ZTB4cFB0-#*Z)MbmOpQ9fB80t5{kPKm`(#RH z+7x$bBlT=B_I9gzXS+e*JuH!2^*zBQ6IHr+yn3m3A35Z^lnT2~)v@9F{%?UieS9&^^E~^_mKT#ev%Qa8FrOe2d3FCH2>G)dhpVX=6goy2&8EbW*Pk^A zQ8;m|1J$O8N`Y%S`0Q!}TUQS(+i;8rBo89aWPEyTnL0(MPq)Zd!?@~px_>zAnwl{X zg-+uxh1($Hl4xJE)!x83i0#f5+NO43?^{l6gOR@H#mVUbyVk>5E3}bL@jS-rk?v@Q zsk#oiYnT+i29ILf*@sD17VthV59RN5_9l9CwG~!q6|K zEu6YBnRH`1`OXt`*;h3pHgoHdUL{_1$o1W4eD`pl>F21p&-qCzI6wddKmY_l00ck) z1V8`;KmY_l00hnvf$;s0tUD*X{&9|07E=KM5C8!X009sH0T2KI5C8!X0D)No!9GCF zeeoar0JD5h0|Fob0w4eaAOHd&00JNY0w4ea=ZQeD55VDlfb+Dfm9ny^Auvfmp@LmvLdg@%Jme-tdnZh zQ}wf=s9MiWRiFlGQ(~3n@@l2HGRHA>Qm&{&?Vdi)K%$z51Ny@MfgYz>uGQqyYL(-d z8>CtGhV4?~0o6}Rpt|V>V)aTDxma9H`ZHD39<`&4DN%k3)k`A~r>a!SN?B1798;qq sWp79~dBQkJLab78MXppUEXQ0YrBXPamx{tZc`Uh7tW{TEC4N)>0q|*!i2wiq literal 0 HcmV?d00001 diff --git a/web/config/handlers.js b/web/config/handlers.js index 0166d0c3a..c24fcd8d2 100644 --- a/web/config/handlers.js +++ b/web/config/handlers.js @@ -19,7 +19,7 @@ export const handlers = [ record: { enabled: true }, detect: { width: 1280, height: 720 }, snapshots: {}, - live: { height: 720 }, + restream: { enabled: true, jsmpeg: { height: 720 } }, ui: { dashboard: true, order: 0 }, }, side: { @@ -28,7 +28,7 @@ export const handlers = [ record: { enabled: false }, detect: { width: 1280, height: 720 }, snapshots: {}, - live: { height: 720 }, + restream: { enabled: true, jsmpeg: { height: 720 } }, ui: { dashboard: true, order: 1 }, }, }, diff --git a/web/src/routes/Camera.jsx b/web/src/routes/Camera.jsx index 9a1ba03d1..08545db57 100644 --- a/web/src/routes/Camera.jsx +++ b/web/src/routes/Camera.jsx @@ -29,7 +29,7 @@ export default function Camera({ camera }) { ? Math.round(cameraConfig.restream.jsmpeg.height * (cameraConfig.detect.width / cameraConfig.detect.height)) : 0; const [viewSource, setViewSource] = usePersistence(`${camera}-source`, 'jsmpeg'); - const sourceValues = cameraConfig.restream.enabled ? ['jsmpeg', 'mp4', 'webrtc'] : ['jsmpeg']; + const sourceValues = (cameraConfig && cameraConfig.restream.enabled) ? ['jsmpeg', 'mp4', 'webrtc'] : ['jsmpeg']; const [options, setOptions] = usePersistence(`${camera}-feed`, emptyObject); const handleSetOption = useCallback( @@ -100,7 +100,7 @@ export default function Camera({ camera }) { if (viewSource == 'mp4') { player = ( -
+
{ test('updates camera feed options to persistence', async () => { mockUsePersistence + .mockReturnValueOnce([{}, mockSetOptions]) + .mockReturnValueOnce([{}, mockSetOptions]) + .mockReturnValueOnce([{}, mockSetOptions]) + .mockReturnValueOnce([{}, mockSetOptions]) + .mockReturnValueOnce([{}, mockSetOptions]) .mockReturnValueOnce([{}, mockSetOptions]) .mockReturnValueOnce([{}, mockSetOptions]) .mockReturnValueOnce([{}, mockSetOptions]) @@ -63,9 +68,8 @@ describe('Camera Route', () => { fireEvent.change(screen.queryByTestId('timestamp-input'), { target: { checked: true } }); fireEvent.click(screen.queryByText('Hide Options')); - expect(mockUsePersistence).toHaveBeenCalledTimes(5); + expect(mockUsePersistence).toHaveBeenCalledTimes(10); expect(mockSetOptions).toHaveBeenCalledTimes(2); - expect(mockSetOptions).toHaveBeenCalledWith({ bbox: true, timestamp: true }); expect(screen.queryByTestId('mock-image')).toHaveTextContent('bbox=1×tamp=1'); }); });