""" Test alarm creation without duration Verify: 1. Alarm creation with duration_ms as None 2. last_frame_time should be None 3. first_frame_time should have value 4. alarm_status should be NEW 5. handle_status should be UNHANDLED """ import sys sys.path.insert(0, 'C:/Users/16337/PycharmProjects/service') from app.services.alarm_event_service import AlarmEventService def test_create_alarm_no_duration(): """Test creating alarm without duration""" service = AlarmEventService() mqtt_data = { "alert_type": "leave_post", "camera_id": "cam001", "roi_id": "roi001", "timestamp": "2026-02-12 14:30:00", "first_frame_time": "2026-02-12 14:23:00", "message": "Leave post alarm", "confidence": 0.95, # No longer sending duration_minutes } print("Creating alarm test...") alarm = service.create_from_mqtt(mqtt_data) # Verify assert alarm is not None, "Alarm creation failed" assert alarm.alarm_status == "NEW", f"Status should be NEW, but got {alarm.alarm_status}" assert alarm.handle_status == "UNHANDLED", f"Handle status should be UNHANDLED, but got {alarm.handle_status}" assert alarm.duration_ms is None, f"duration_ms should be None, but got {alarm.duration_ms}" assert alarm.last_frame_time is None, f"last_frame_time should be None, but got {alarm.last_frame_time}" assert alarm.first_frame_time is not None, "first_frame_time should have value" assert alarm.alarm_level == 2, f"alarm_level should be 2 (general level), but got {alarm.alarm_level}" print("[PASS] Test passed: Alarm created without duration") print(f" alarm_id: {alarm.alarm_id}") print(f" alarm_type: {alarm.alarm_type}") print(f" alarm_status: {alarm.alarm_status}") print(f" alarm_level: {alarm.alarm_level}") print(f" duration_ms: {alarm.duration_ms}") print(f" first_frame_time: {alarm.first_frame_time}") print(f" last_frame_time: {alarm.last_frame_time}") print(f" event_time: {alarm.event_time}") if __name__ == "__main__": test_create_alarm_no_duration()