4
4
from unittest import mock
5
5
from blinkpy import LOGIN_URL
6
6
from blinkpy import BASE_URL
7
+ import test_const as const
7
8
8
9
def mocked_requests_post (* args , ** kwargs ):
9
10
class MockPostResponse :
@@ -14,7 +15,7 @@ def json(self):
14
15
return self .json_data
15
16
16
17
if args [0 ] == LOGIN_URL :
17
- return MockPostResponse ({"region" :{"test" : "Notacountry" }, "authtoken" :{"authtoken" :"abcd1234" }}, 200 )
18
+ return MockPostResponse ({"region" :{const . REGION_ID : const . REGION }, "authtoken" :{"authtoken" :const . TOKEN }}, 200 )
18
19
elif args [0 ].split ("/" )[- 1 ] == 'arm' :
19
20
return MockPostResponse ({"armed" :True }, 200 )
20
21
elif args [0 ].split ("/" )[- 1 ] == 'disarm' :
@@ -33,20 +34,9 @@ def json(self):
33
34
return self .json_data
34
35
35
36
if args [0 ] == BASE_URL + '/networks' :
36
- return MockGetResponse ({'networks' :[{"id" :7777 ,"account_id" :3333 },{"nothing" :"nothing" }]}, 200 )
37
+ return MockGetResponse ({'networks' :[{"id" :const . NETWORK_ID ,"account_id" :const . ACCOUNT_ID },{"nothing" :"nothing" }]}, 200 )
37
38
else :
38
- return MockGetResponse ({'devices' :[{'device_type' :'camera' ,'name' :'test' ,'device_id' :123 ,'armed' :False ,'thumbnail' :'/some/url' ,'temp' :65 ,'battery' :3 ,'notifications' :1 },
39
- {'device_type' :'camera' ,'name' :'test2' ,'device_id' :321 ,'armed' :True ,'thumbnail' :'/some/new/url' ,'temp' :56 ,'battery' :5 ,'notifications' :0 },
40
- {'device_type' :'None' }
41
- ],
42
- 'events' :[{'camera_id' :123 , 'type' :'motion' , 'video_url' :'/some/dumb/location.mp4' , 'created_at' :'2017-01-01' },
43
- {'camera_id' :321 , 'type' :'None' }
44
- ],
45
- 'syncmodule' :{'name' :'SyncName' , 'status' :'online' },
46
- 'network' :{'name' :'Sync' ,'armed' :True , 'notifications' :4 }
47
- },
48
- 200
49
- )
39
+ return MockGetResponse (const .response , 200 )
50
40
51
41
52
42
return MockGetResponse ({'message' :'ERROR' ,'code' :404 }, 404 )
@@ -58,12 +48,12 @@ def test_blink_setup(self, mock_get, mock_post):
58
48
blink = blinkpy .Blink (username = 'user' ,password = 'password' )
59
49
blink .setup_system ()
60
50
61
- self .assertEqual (blink .network_id , '7777' )
62
- self .assertEqual (blink .account_id , '3333' )
63
- self .assertEqual (blink .region , 'Notacountry' )
64
- self .assertEqual (blink .region_id , 'test' )
65
- self .assertEqual (blink .online , True )
66
- self .assertEqual (blink .arm , True )
51
+ self .assertEqual (blink .network_id , str ( const . NETWORK_ID ) )
52
+ self .assertEqual (blink .account_id , str ( const . ACCOUNT_ID ) )
53
+ self .assertEqual (blink .region , const . REGION )
54
+ self .assertEqual (blink .region_id , const . REGION_ID )
55
+ self .assertEqual (blink .online , const . ISONLINE )
56
+ self .assertEqual (blink .arm , const . ARMED )
67
57
68
58
@mock .patch ('blinkpy.requests.post' , side_effect = mocked_requests_post )
69
59
@mock .patch ('blinkpy.requests.get' , side_effect = mocked_requests_get )
@@ -72,14 +62,39 @@ def test_blink_camera_setup_and_motion(self, mock_get, mock_post):
72
62
blink .setup_system ()
73
63
blink .last_motion ()
74
64
for name , camera in blink .cameras .items ():
75
- if camera .id == '123' :
76
- self .assertEqual (name , 'test' )
77
- self .assertEqual (camera .armed , False )
78
- self .assertEqual (camera .motion ['video' ], BASE_URL + '/some/dumb/location .mp4' )
79
- elif camera .id == '321' :
80
- self .assertEqual (name , 'test2' )
81
- self .assertEqual (camera .armed , True )
65
+ if camera .id == str ( const . DEVICE_ID ) :
66
+ self .assertEqual (name , const . CAMERA_NAME )
67
+ self .assertEqual (camera .armed , const . ARMED )
68
+ self .assertEqual (camera .motion ['video' ], BASE_URL + const . THUMB + ' .mp4' )
69
+ elif camera .id == str ( const . DEVICE_ID2 ) :
70
+ self .assertEqual (name , const . CAMERA_NAME2 )
71
+ self .assertEqual (camera .armed , const . ARMED2 )
82
72
self .assertEqual (len (camera .motion .keys ()), 0 )
83
73
else :
84
74
assert False is True
75
+
76
+ @mock .patch ('blinkpy.requests.post' , side_effect = mocked_requests_post )
77
+ @mock .patch ('blinkpy.requests.get' , side_effect = mocked_requests_get )
78
+ def test_blink_refresh (self , mock_get , mock_post ):
79
+ blink = blinkpy .Blink (username = 'user' ,password = 'password' )
80
+ blink .setup_system ()
81
+ const .response ['devices' ][0 ]['thumbnail' ] = const .THUMB + const .THUMB2
82
+ blink .refresh ()
83
+ for name , camera in blink .cameras .items ():
84
+ if camera .id == str (const .DEVICE_ID ):
85
+ self .assertEqual (camera .thumbnail , BASE_URL + const .THUMB + const .THUMB2 + '.jpg' )
86
+ elif camera .id == str (const .DEVICE_ID2 ):
87
+ pass
88
+ else :
89
+ assert False is True
90
+
91
+ const .response ['devices' ][0 ]['thumbnail' ] = 'new'
92
+ blink .cameras [const .CAMERA_NAME ].image_refresh ()
93
+ for name , camera in blink .cameras .items ():
94
+ if camera .id == str (const .DEVICE_ID ):
95
+ self .assertEqual (camera .thumbnail , BASE_URL + 'new' + '.jpg' )
96
+ elif camera .id == str (const .DEVICE_ID2 ):
97
+ pass
98
+ else :
99
+ assert False is True
85
100
0 commit comments