@@ -19,3 +19,189 @@ def maybe_raise(r=False):
19
19
match = 'oops' ,
20
20
):
21
21
maybe_raise (True )
22
+
23
+
24
+ def test_client_set_capabilies_with_invalid_capabilities_type ():
25
+ with pytest .raises (
26
+ RuntimeError ,
27
+ match = 'Capabilities type must be dictionary' ,
28
+ ):
29
+ client = aonvif .ONVIFCamera (
30
+ 'testhost' ,
31
+ 80 ,
32
+ 'username' ,
33
+ 'password' ,
34
+ )
35
+ client .set_capabilities (
36
+ capabilities = [
37
+ {
38
+ 'Media' : {
39
+ 'XAddr' : 'http://localhost/path' ,
40
+ },
41
+ },
42
+ ],
43
+ )
44
+
45
+
46
+ def test_client_set_capabilities_with_invalid_capabilities_key_type ():
47
+ with pytest .raises (
48
+ RuntimeError ,
49
+ match = 'Capabilities key type must be string' ,
50
+ ):
51
+ client = aonvif .ONVIFCamera (
52
+ 'testhost' ,
53
+ 80 ,
54
+ 'username' ,
55
+ 'password' ,
56
+ )
57
+ client .set_capabilities (
58
+ capabilities = {
59
+ tuple ('Media' ): {
60
+ 'XAddr' : 'http://localhost/path' ,
61
+ },
62
+ },
63
+ )
64
+
65
+
66
+ def test_client_set_capabilities_with_invalid_capability_type ():
67
+ with pytest .raises (
68
+ RuntimeError ,
69
+ match = 'Capability type must be dictionary' ,
70
+ ):
71
+ client = aonvif .ONVIFCamera (
72
+ 'testhost' ,
73
+ 80 ,
74
+ 'username' ,
75
+ 'password' ,
76
+ )
77
+ client .set_capabilities (
78
+ capabilities = {
79
+ 'Media' : ['XAddr' , 'http://localhost/path' ],
80
+ },
81
+ )
82
+
83
+
84
+ def test_client_set_capabilities_with_missing_xaddr ():
85
+ with pytest .raises (
86
+ RuntimeError ,
87
+ match = 'Capability XAddr is missing' ,
88
+ ):
89
+ client = aonvif .ONVIFCamera (
90
+ 'testhost' ,
91
+ 80 ,
92
+ 'username' ,
93
+ 'password' ,
94
+ )
95
+ client .set_capabilities (
96
+ capabilities = {
97
+ 'Media' : {
98
+ 'RTPMulticast' : True ,
99
+ },
100
+ },
101
+ )
102
+
103
+
104
+ def test_client_set_capabilities_with_invalid_xaddr_type ():
105
+ with pytest .raises (
106
+ RuntimeError ,
107
+ match = 'Capability XAddr type must be string' ,
108
+ ):
109
+ client = aonvif .ONVIFCamera (
110
+ 'testhost' ,
111
+ 80 ,
112
+ 'username' ,
113
+ 'password' ,
114
+ )
115
+ client .set_capabilities (
116
+ capabilities = {
117
+ 'Media' : {
118
+ 'XAddr' : True ,
119
+ },
120
+ },
121
+ )
122
+
123
+
124
+ @pytest .fixture
125
+ def mocked_device_mgmt_service (mocker ):
126
+ mocked_service = mocker .AsyncMock ()
127
+ mocked_service .GetCapabilities .return_value = {
128
+ 'Analytics' : {
129
+ 'XAddr' : 'http://testhost/onvif/analytics_service' ,
130
+ 'RuleSupport' : True ,
131
+ 'AnalyticsModuleSupport' : True ,
132
+ '_value_1' : None ,
133
+ '_attr_1' : None ,
134
+ },
135
+ 'Events' : {
136
+ 'XAddr' : 'http://testhost/onvif/event_service' ,
137
+ 'WSSubscriptionPolicySupport' : True ,
138
+ 'WSPullPointSupport' : True ,
139
+ 'WSPausableSubscriptionManagerInterfaceSupport' : False ,
140
+ '_value_1' : None ,
141
+ '_attr_1' : None ,
142
+ },
143
+ 'PTZ' : {
144
+ 'XAddr' : 'http://testhost/onvif/ptz_service' ,
145
+ '_value_1' : None ,
146
+ '_attr_1' : None ,
147
+ },
148
+ }
149
+
150
+ return mocked_service
151
+
152
+
153
+ @pytest .mark .asyncio
154
+ async def test_client_update_xaddrs (mocker , mocked_device_mgmt_service ):
155
+ client = aonvif .ONVIFCamera (
156
+ 'testhost' ,
157
+ 80 ,
158
+ 'username' ,
159
+ 'password' ,
160
+ )
161
+ mocker .patch .object (
162
+ client ,
163
+ 'create_devicemgmt_service' ,
164
+ return_value = mocked_device_mgmt_service ,
165
+ )
166
+
167
+ await client .update_xaddrs ()
168
+
169
+ assert client ._xaddrs == {
170
+ 'http://www.onvif.org/ver20/ptz/wsdl' : 'http://testhost/onvif/ptz_service' ,
171
+ 'http://www.onvif.org/ver10/events/wsdl' : 'http://testhost/onvif/event_service' ,
172
+ 'http://www.onvif.org/ver20/analytics/wsdl' : 'http://testhost/onvif/analytics_service' ,
173
+ }
174
+ mocked_device_mgmt_service .GetCapabilities .assert_awaited_once_with ({'Category' : 'All' })
175
+
176
+
177
+ @pytest .mark .asyncio
178
+ async def test_client_update_xaddrs_with_custom_capabilities (
179
+ mocker ,
180
+ mocked_device_mgmt_service ,
181
+ ):
182
+ client = aonvif .ONVIFCamera (
183
+ 'testhost' ,
184
+ 80 ,
185
+ 'username' ,
186
+ 'password' ,
187
+ )
188
+ client .set_capabilities (
189
+ capabilities = {
190
+ 'Imaging' : {
191
+ 'XAddr' : 'http://testhost/onvif/imaging_service' ,
192
+ },
193
+ },
194
+ )
195
+
196
+ mocker .patch .object (
197
+ client ,
198
+ 'create_devicemgmt_service' ,
199
+ return_value = mocked_device_mgmt_service ,
200
+ )
201
+
202
+ await client .update_xaddrs ()
203
+
204
+ assert client ._xaddrs == {
205
+ 'http://www.onvif.org/ver20/imaging/wsdl' : 'http://testhost/onvif/imaging_service' ,
206
+ }
207
+ mocked_device_mgmt_service .GetCapabilities .assert_not_awaited ()
0 commit comments