forked from keredson/blink
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unittests.py
131 lines (113 loc) · 4.63 KB
/
unittests.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import sys, json, unittest
import blink
from blink import Blink
###############################################################################
## Unittests for Blink Client APIs
###############################################################################
class TestBlink(unittest.TestCase):
email = ""
password = ""
def setUp(self):
self.b = Blink(self.email, self.password)
self.b.login()
###############################################################################
## Highlighted Client APIs
###############################################################################
def test_login(self):
self.assertTrue(self.b.connected)
def test_homescreen(self):
data = self.b.homescreen()
self.assertTrue(data['account'] is not None)
self.assertTrue(data['network'] is not None)
for device in data['devices']:
if device['device_type'] is not None and device['device_type'] == "camera":
content,filename = self.b.download_thumbnail_home_v2(device)
blink.save_to_file(content, "home_"+filename)
def test_events_v2(self):
events = self.b.eventsv2()
self.assertEqual(type(events), list)
def test_video_count(self):
count = self.b.get_video_count()
print("video count = " + str(count))
def test_events_v2_download(self):
events = self.b.eventsv2()
if len(events) == 0:
return ;
event = events[0]
content = self.b.download_video_v2(event)
filename = self.b.get_event_name_v2(event)
blink.save_to_file(content, "event_"+filename)
def test_thumbnail_event_v2_download(self):
events = self.b.eventsv2()
if len(events) == 0:
return ;
event = events[0]
content = self.b.download_thumbnail_event_v2(event)
filename = self.b.get_thumbnail_name_event(event, "event")
f = open(filename, 'wb')
f.write(content)
f.close()
print('Save downloaded image to ' + filename)
###############################################################################
## Wrapped Functions
###############################################################################
def test_list_network_ids(self):
ids = self.b.list_network_ids()
self.assertEqual(type(ids), list)
def test_list_camera_ids(self):
ids = self.b.list_camera_ids()
self.assertEqual(type(ids), list)
def test_events_from_camera(self):
ids = self.b.list_camera_ids()
if len(ids) > 0:
id = ids[0]
events = self.b.events_from_camera(id, 1)
if len(events) > 0:
event = events[0]
content = self.b.download_video_v2(event)
filename = self.b.get_event_name_v2(event)
blink.save_to_file(content, "event_camera_"+filename)
def test_refresh_all_cameras_thumbnail(self):
self.b.refresh_all_cameras_thumbnail()
data = self.b.homescreen()
for device in data['devices']:
if device['device_type'] is not None and device['device_type'] == "camera":
content,filename = self.b.download_thumbnail_home_v2(device)
filename = "test_refresh_" + filename
blink.save_to_file(content, filename)
print("Download latest thumbnails to " + filename)
###############################################################################
## Other Client APIs
###############################################################################
def test_cameras(self):
cameras = self.b.cameras(self.b.networks[0])
self.assertEqual(type(cameras), list)
def test_clients(self):
clients = self.b.clients()
self.assertTrue(clients['clients'] is not None)
print(clients)
def test_sync_modules(self):
sync_modules = self.b.sync_modules(self.b.networks[0])
print(sync_modules)
def test_regions(self):
regions = self.b.regions()
print(regions)
def test_get_video_info(self):
events = self.b.eventsv2()
if len(events) == 0:
return ;
event = events[0]
eventinfo = self.b.get_video_info(event.id)
print("eventinfo:" + str(eventinfo))
def test_delete_video(self):
events = self.b.eventsv2(1000)
if len(events) == 0:
return ;
event = events[len(events)-1]
suc = self.b.delete_video(event.id)
self.assertTrue(suc)
if __name__ == '__main__':
if len(sys.argv) > 1:
TestBlink.password = sys.argv.pop()
TestBlink.email = sys.argv.pop()
unittest.main()