forked from calmh/unifi-api
-
Notifications
You must be signed in to change notification settings - Fork 99
/
test_pyunifi.py
42 lines (33 loc) · 1.29 KB
/
test_pyunifi.py
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
from unittest import mock, TestCase, main
from pyunifi.controller import APIError, Controller
class testPyUnifi(TestCase):
def test_controller_args(self):
# Test for controller versions
self.assertRaises(APIError, Controller, 'host',
'username', 'password', version='v3')
# Test for missing arguments
self.assertRaises(TypeError, Controller, 'username', 'password')
@mock.patch('pyunifi.controller.Controller')
def test_pyunifi_switch_sites(self, MockPyUnifi):
controller = MockPyUnifi()
# Test function to switch sites
controller.switch_site.return_value = [True]
response = controller.switch_site('test1')
self.assertIsNotNone(response)
self.assertIsInstance(True, bool)
@mock.patch('pyunifi.controller.Controller')
def test_pyunifi_get_aps(self, MockPyUnifi):
controller = MockPyUnifi()
controller.get_aps.return_value = [
{
'_id': '11111',
'_uptime': '30506',
'adopted': True,
'ip': '192.168.1.5'
}
]
response = controller.get_aps()
self.assertIsNotNone(response)
self.assertIsInstance(response[0], dict)
if __name__ == '__main__':
main()