Spaces:
Sleeping

entri-proctor-api / test_ai_engine.py
DhyandevP's picture
Update proctoring API without hardcoded secrets
1adec4d
Raw History Blame Contribute Delete
1.35 kB
import os
import sys
import unittest
import cv2
import numpy as np
# Ensure midend_api path is importable
sys.path.insert(0, os.path.dirname(__file__))
from ai_engine import AIEngine
class TestAIEngine(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.engine = AIEngine()
def _encode_frame(self, frame: np.ndarray) -> bytes:
ok, buf = cv2.imencode(".jpg", frame)
self.assertTrue(ok, "Failed to encode test frame")
return buf.tobytes()
def test_engine_init(self):
self.assertIsNotNone(self.engine.face_detector)
def test_blank_image(self):
# Plain black background - should report no face
blank = np.zeros((320, 320, 3), dtype=np.uint8)
result = self.engine.analyze(self._encode_frame(blank))
self.assertFalse(result["face_detected"])
self.assertFalse(result["multiple_faces_detected"])
self.assertFalse(result["partial_face_detected"])
self.assertFalse(result["forbidden_objects"])
def test_invalid_inputs(self):
# Empty byte stream
with self.assertRaises(ValueError):
self.engine.analyze(b"")
# Corrupted non-image bytes
with self.assertRaises(ValueError):
self.engine.analyze(b"not_an_image_buffer")
if __name__ == "__main__":
unittest.main()