1+ # tests/conftest.py
2+
3+ import pytest
4+ from unittest .mock import Mock , MagicMock , patch
5+ from onvif import ONVIFClient , CacheMode
6+
7+
8+ @pytest .fixture
9+ def mock_device_response ():
10+ """Mock device information response"""
11+ mock_device = Mock ()
12+ mock_device .Manufacturer = "Test Manufacturer"
13+ mock_device .Model = "Test Model"
14+ mock_device .FirmwareVersion = "1.0.0"
15+ mock_device .SerialNumber = "TEST123456"
16+ mock_device .HardwareId = "TEST_HW_001"
17+ return mock_device
18+
19+
20+ @pytest .fixture
21+ def mock_capabilities ():
22+ """Mock capabilities response"""
23+ mock_caps = Mock ()
24+
25+ # Media capabilities
26+ mock_caps .Media = Mock ()
27+ mock_caps .Media .XAddr = "http://192.168.1.17:8000/onvif/Media"
28+
29+ # PTZ capabilities
30+ mock_caps .PTZ = Mock ()
31+ mock_caps .PTZ .XAddr = "http://192.168.1.17:8000/onvif/PTZ"
32+
33+ # Extension capabilities
34+ mock_caps .Extension = Mock ()
35+ mock_caps .Extension .DeviceIO = Mock ()
36+ mock_caps .Extension .DeviceIO .XAddr = "http://192.168.1.17:8000/onvif/DeviceIO"
37+
38+ return mock_caps
39+
40+
41+ @pytest .fixture
42+ def mock_services ():
43+ """Mock GetServices response"""
44+ service1 = Mock ()
45+ service1 .Namespace = "http://www.onvif.org/ver10/media/wsdl"
46+ service1 .XAddr = "http://192.168.1.17:8000/onvif/Media"
47+
48+ service2 = Mock ()
49+ service2 .Namespace = "http://www.onvif.org/ver20/ptz/wsdl"
50+ service2 .XAddr = "http://192.168.1.17:8000/onvif/PTZ"
51+
52+ return [service1 , service2 ]
53+
54+
55+ @pytest .fixture
56+ def mock_onvif_client ():
57+ """Create a mocked ONVIF client for testing"""
58+ with patch ('onvif.client.Device' ) as mock_device_class :
59+ # Mock the Device class to avoid real network calls
60+ mock_device = Mock ()
61+ mock_device_class .return_value = mock_device
62+
63+ client = ONVIFClient (
64+ host = "192.168.1.17" ,
65+ port = 8000 ,
66+ username = "admin" ,
67+ password = "admin123" ,
68+ timeout = 5 ,
69+ cache = CacheMode .NONE # Disable caching for tests
70+ )
71+
72+ # Set up mock responses
73+ mock_device .GetDeviceInformation .return_value = Mock (
74+ Manufacturer = "Test Manufacturer" ,
75+ Model = "Test Model" ,
76+ FirmwareVersion = "1.0.0" ,
77+ SerialNumber = "TEST123456" ,
78+ HardwareId = "TEST_HW_001"
79+ )
80+
81+ # Create mock capabilities
82+ mock_caps = Mock ()
83+ mock_caps .Media = Mock ()
84+ mock_caps .Media .XAddr = "http://192.168.1.17:8000/onvif/Media"
85+ mock_caps .PTZ = Mock ()
86+ mock_caps .PTZ .XAddr = "http://192.168.1.17:8000/onvif/PTZ"
87+ mock_caps .Extension = Mock ()
88+ mock_caps .Extension .DeviceIO = Mock ()
89+ mock_caps .Extension .DeviceIO .XAddr = "http://192.168.1.17:8000/onvif/DeviceIO"
90+ mock_device .GetCapabilities .return_value = mock_caps
91+
92+ # Create mock services
93+ service1 = Mock ()
94+ service1 .Namespace = "http://www.onvif.org/ver10/media/wsdl"
95+ service1 .XAddr = "http://192.168.1.17:8000/onvif/Media"
96+ service2 = Mock ()
97+ service2 .Namespace = "http://www.onvif.org/ver20/ptz/wsdl"
98+ service2 .XAddr = "http://192.168.1.17:8000/onvif/PTZ"
99+ mock_device .GetServices .return_value = [service1 , service2 ]
100+
101+ client ._devicemgmt = mock_device
102+ yield client
103+
104+
105+ @pytest .fixture
106+ def sample_subscription_ref ():
107+ """Sample subscription reference for pullpoint tests"""
108+ return {
109+ "SubscriptionReference" : {
110+ "Address" : {
111+ "_value_1" : "http://192.168.1.17:8000/onvif/Subscription/12345"
112+ }
113+ }
114+ }
115+
116+
117+ @pytest .fixture
118+ def test_client_params ():
119+ """Standard test client parameters"""
120+ return {
121+ "host" : "192.168.1.17" ,
122+ "port" : 8000 ,
123+ "username" : "admin" ,
124+ "password" : "admin123" ,
125+ "timeout" : 5 ,
126+ "cache" : CacheMode .NONE
127+ }
0 commit comments