Fix tests

This commit is contained in:
Nicolas Mowen 2024-02-21 07:04:04 -07:00
parent 15895058ac
commit dfb62af531

View File

@ -3,7 +3,7 @@ import json
import logging import logging
import os import os
import unittest import unittest
from unittest.mock import patch from unittest.mock import Mock
from peewee_migrate import Router from peewee_migrate import Router
from playhouse.shortcuts import model_to_dict from playhouse.shortcuts import model_to_dict
@ -14,6 +14,7 @@ from frigate.config import FrigateConfig
from frigate.http import create_app from frigate.http import create_app
from frigate.models import Event, Recordings from frigate.models import Event, Recordings
from frigate.plus import PlusApi from frigate.plus import PlusApi
from frigate.stats.emitter import StatsEmitter
from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS
@ -119,8 +120,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
id2 = "7890.random" id2 = "7890.random"
@ -155,8 +156,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
@ -176,8 +177,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
bad_id = "654321.other" bad_id = "654321.other"
@ -196,8 +197,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
@ -218,8 +219,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
@ -244,8 +245,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
morning_id = "123456.random" morning_id = "123456.random"
evening_id = "654321.random" evening_id = "654321.random"
@ -282,8 +283,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
sub_label = "sub" sub_label = "sub"
@ -317,8 +318,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
sub_label = "sub" sub_label = "sub"
@ -342,8 +343,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
with app.test_client() as client: with app.test_client() as client:
@ -359,8 +360,8 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
None,
) )
id = "123456.random" id = "123456.random"
@ -370,8 +371,9 @@ class TestHttp(unittest.TestCase):
assert recording assert recording
assert recording[0]["id"] == id assert recording[0]["id"] == id
@patch("frigate.http.stats_snapshot") def test_stats(self):
def test_stats(self, mock_stats): stats = Mock(spec=StatsEmitter)
stats.get_latest_stats.return_value = self.test_stats
app = create_app( app = create_app(
FrigateConfig(**self.minimal_config).runtime_config(), FrigateConfig(**self.minimal_config).runtime_config(),
self.db, self.db,
@ -379,14 +381,13 @@ class TestHttp(unittest.TestCase):
None, None,
None, None,
None, None,
None,
PlusApi(), PlusApi(),
stats,
) )
mock_stats.return_value = self.test_stats
with app.test_client() as client: with app.test_client() as client:
stats = client.get("/stats").json full_stats = client.get("/stats").json
assert stats == self.test_stats assert full_stats == self.test_stats
def _insert_mock_event( def _insert_mock_event(