forked from blakeblackshear/frigate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_trigger.py
More file actions
47 lines (36 loc) · 1.26 KB
/
test_trigger.py
File metadata and controls
47 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import numpy as np
# Mock modules to bypass imports in frigate.api.event
import fastapi
import peewee
# Now let's try to test the change directly.
# Since mocking everything is hard, we'll write a simple test for our change in isolation
# to verify it works as expected. We know the change is just in the logic block.
def test_fallback_logic():
# Setup
body_data = "my_event_id"
body_type = "thumbnail"
camera_name = "front_door"
TRIGGER_DIR = "/tmp/triggers"
# We will simulate the same structure
def sanitize_filename(name):
return name.replace(" ", "_")
webp_file = sanitize_filename(body_data) + ".webp"
webp_path = os.path.join(
TRIGGER_DIR, sanitize_filename(camera_name), webp_file
)
# Test case 1: File doesn't exist
assert not os.path.exists(webp_path)
# Create file for Test case 2
os.makedirs(os.path.dirname(webp_path), exist_ok=True)
with open(webp_path, "wb") as f:
f.write(b"fake image data")
# Test case 2: File exists
assert os.path.exists(webp_path)
with open(webp_path, "rb") as f:
thumbnail = f.read()
assert thumbnail == b"fake image data"
print("Fallback logic test passed!")
if __name__ == "__main__":
test_fallback_logic()