-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathverify_backend.py
More file actions
82 lines (65 loc) · 2.86 KB
/
Copy pathverify_backend.py
File metadata and controls
82 lines (65 loc) · 2.86 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
import os
import cv2
import numpy as np
import base64
from unittest.mock import MagicMock
# Mock mediapipe before importing face_service
sys.modules['mediapipe'] = MagicMock()
sys.modules['mediapipe'].solutions = MagicMock()
sys.modules['mediapipe'].solutions.face_mesh = MagicMock()
sys.modules['mediapipe'].solutions.selfie_segmentation = MagicMock()
# Add backend to path
sys.path.append(os.path.join(os.getcwd(), 'backend'))
from face_service import face_service
def test_initialization():
print("Testing FaceService initialization...")
categories = face_service.get_categories()
print(f"Categories: {categories}")
if 'Male' in categories and 'Female' in categories:
print("PASS: Male and Female categories loaded.")
else:
print("FAIL: Male/Female categories missing.")
return False
male_assets = face_service.get_category_assets('Male')
print(f"Male assets count: {len(male_assets)}")
if len(male_assets) > 0:
asset = face_service.get_asset_by_id(male_assets[0]['id'])
print(f"First Male asset type: {asset.get('type')}")
if asset.get('type') == 'overlay':
print("PASS: Asset type is correctly set to 'overlay'.")
else:
print(f"FAIL: Asset type is {asset.get('type')}")
return False
return True
def test_process_frame():
print("\nTesting process_frame with overlay...")
# Create a dummy image with a face (using just a blank image for now,
# but face_service needs landmarks)
# Ideally we need a real image with a face to get landmarks.
# We can try to load one from assets if available, or just skip if no face found logic handles it gracefully?
# Actually, process_frame REQUIRES a face to be detected to do anything.
img = np.zeros((480, 640, 3), dtype=np.uint8)
cv2.circle(img, (320, 240), 100, (200, 200, 200), -1) # Pseudo face
# We can't easily mock MediaPipe results without a real face image.
# So we will skip the functional test of process_frame unless we have a face image.
# However, we can check if the function runs without crashing.
_, buffer = cv2.imencode('.jpg', img)
img_b64 = base64.b64encode(buffer).decode('utf-8')
# Pick an asset
male_assets = face_service.get_category_assets('Male')
if not male_assets:
print("No male assets to test.")
return
asset_id = male_assets[0]['id']
try:
result = face_service.process_frame(img_b64, asset_id)
if result:
print("PASS: process_frame executed (result returned).")
else:
print("INFO: process_frame returned None (expected if no face detected).")
except Exception as e:
print(f"FAIL: process_frame crashed: {e}")
if __name__ == "__main__":
if test_initialization():
test_process_frame()