-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_pyawair_devices.py
420 lines (353 loc) · 15.1 KB
/
test_pyawair_devices.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# -*- coding: utf-8 -*-
"""
This module is used for testing the functions within the pyawair.devices module.
"""
from unittest import TestCase
from pyawair.devices import *
from pyawair.auth import AwairAuth
from pyawair.devices import get_all_devices
from nose.plugins.skip import SkipTest
hobbiest = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiRFVNTVktSE9CQllJU1QifQ.hzjhIpGljqCZ8vCrOr89POy_ENDPYQXsnzGslP01krI'
small_dev = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiRFVNTVktU01BTExfREVWRUxPUEVSIn0.amOu5uy-0UeBDRLd6uhqsbkUEyx13-4QdBrV1S3z2W8'
large_dev = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiRFVNTVktTEFSR0VfREVWRUxPUEVSIn0.JmP9a0eGjgYRlmri5BjNj4h1hlAZ-7yFOjcIZjyzypA'
enterprise_dev = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiRFVNTVktRU5URVJQUklTRSJ9.bOM9rcABF9HKFHtxzF9kx8h9fv3CfvUIzveLFDRGrXs'
auth = AwairAuth(hobbiest)
dev1 = get_all_devices(auth)[0]
dev2 = get_all_devices(auth)[1]
all_devs_hob = get_all_devices(auth)
# TODO Remarked out failing tests
class TestGetUserData(TestCase):
"""
Test Case for pyawair.devices get_user_data function
"""
def test_get_user_data(self):
"""
"""
#breaking changes in the Awair API
raise SkipTest
user_data = get_user_data(auth)
self.assertIs(type(user_data['dobDay']), int)
self.assertIs(type(user_data['dobMonth']), int)
self.assertIs(type(user_data['dobYear']), int)
self.assertIs(type(user_data['email']), str)
self.assertIs(type(user_data['firstName']), str)
self.assertIs(type(user_data['lastName']), str)
self.assertIs(type(user_data['id']), str)
class TestGetAllDevices(TestCase):
"""
Test Case for pyawair.devices get_all_devices function
"""
def test_get_all_devices(self):
"""
"""
all_devices = get_all_devices(auth)
self.assertIs(type(all_devices[0]['deviceId']), int)
self.assertIs(type(all_devices[0]['deviceType']), str)
self.assertIs(type(all_devices[0]['latitude']), float)
self.assertIs(type(all_devices[0]['locationName']), str)
self.assertIs(type(all_devices[0]['longitude']), float)
self.assertIs(type(all_devices[0]['name']), str)
class TestGetDevDetails(TestCase):
"""
Test Case for pyawair.devices get_device_details function for a single
device name "Bedroom_Awair"
"""
def test_get_dev_details_name_pos(self):
"""
Positive Test Case
"""
single_device = get_dev_details(auth, device_name=dev1['name'])
self.assertIs(type(single_device['deviceId']), int)
self.assertIs(type(single_device['deviceType']), str)
self.assertIs(type(single_device['latitude']), float)
self.assertIs(type(single_device['locationName']), str)
self.assertIs(type(single_device['longitude']), float)
self.assertIs(type(single_device['name']), str)
def test_get_dev_details_name_neg(self):
"""
Negative Test case
:return:
"""
single_device = get_dev_details(auth, device_name="Doesn't Exist")
self.assertEqual(single_device, 'Device not found')
class TestGetDevLEDMode(TestCase):
"""
Test Case for pyawair.devices get_dev_led_mode function for a single
device name "Bedroom_Awair"
"""
def test_get_dev_led_mode_id_pos(self):
"""
Positive Test case
"""
led_mode = get_dev_led_mode(auth,device_type=dev1['deviceType'], device_id=dev1['deviceId'])
modes=["sleep", "on", "dim"]
self.assertIn(led_mode['mode'].lower(), modes)
def test_get_dev_led_mode_name_pos(self):
"""
Positive Test case
"""
led_mode = get_dev_led_mode(auth, device_name=dev1['name'])
modes=["sleep", "on", "dim"]
self.assertIn(led_mode['mode'].lower(), modes)
def test_get_dev_led_mode__name_neg(self):
"""
Negative Test case
:return:
"""
led_mode = get_dev_led_mode(auth, device_name ="Doesn't Exist")
self.assertEqual(led_mode, 'Device not found')
class TestGetDevTimeZone(TestCase):
"""
Test Case for pyawair.devices get_dev_timezone function for a single
device name "Bedroom_Awair"
"""
def test_get_dev_timezone_id_pos(self):
"""
Positive Test case
"""
timezone = get_dev_timezone(auth,device_type=dev1['deviceType'], device_id=dev1['deviceId'])
expected_timezone = {'timezone': 'US/Pacific'}
self.assertIs(type(timezone['timezone']), str)
self.assertEqual(timezone, expected_timezone)
def test_get_dev_timezone_name_pos(self):
"""
Positive Test case
"""
timezone = get_dev_timezone(auth, device_name=dev1['name'])
expected_timezone = {'timezone': 'US/Pacific'}
self.assertIs(type(timezone['timezone']), str)
self.assertEqual(timezone, expected_timezone)
def test_get_dev_timezone_neg(self):
"""
Negative Test case
:return:
"""
timezone = get_dev_timezone(auth, device_name="Doesn't Exist")
self.assertEqual(timezone, 'Device not found')
class TestGetDevDisplayMode(TestCase):
"""
Test Case for pyawair.devices get_dev_display_mode function for a single
device name "Bedroom_Awair"
"""
def test_get_dev_display_mode_id_pos(self):
"""
Positive Test case
"""
display_mode = get_dev_display_mode(auth,device_type=dev1['deviceType'], device_id=dev1['deviceId'])
modes = ["default", "score", "clock", "off", "nightlight", "temp", "humid",
"co2", "voc", "pm25", "temp_humid_celsius", "temp_humid_fahrenheit"]
self.assertIn(display_mode['mode'].lower(), modes)
def test_get_dev_display_mode_name_pos(self):
"""
Positive Test case
"""
display_mode = get_dev_display_mode(auth, device_name=dev1['name'])
modes=["default", "score", "clock" ,"off" ,"nightlight", "temp", "humid",
"co2", "voc", "pm25", "temp_humid_celsius", "temp_humid_fahrenheit"]
self.assertIn(display_mode['mode'].lower(), modes)
def test_get_dev_display_mode_name_neg(self):
"""
Negative Test case
:return:
"""
display_mode = get_dev_display_mode(auth, device_name="Doesn't Exist")
self.assertEqual(display_mode, 'Device not found')
#TODO Get Dev Power TEST FAILING
class TestGetDevPowerStatus(TestCase):
"""
Test Case for pyawair.devices get_dev_power_status function for a single
device name "Bedroom_Awair"
"""
def test_get_dev_power_status_id_post(self):
#skipping test as API isn't testable with current Awair Mock API
raise SkipTest
power_status = get_dev_power_status(auth,device_type=dev1['deviceType'], device_id=dev1['deviceId'])
# self.assertIs(type(power_status['message']), str)
def test_get_dev_power_status_pos(self):
"""
Positive Test case
"""
# skipping test as API isn't testable with current Awair Mock API
raise SkipTest
power_status = get_dev_power_status(auth, device_name=dev1['name'])
#self.assertIs(type(power_status['message']), str)
def test_get_dev_power_status_neg(self):
"""
Negative Test case
:return:
"""
# skipping test as API isn't testable with current Awair Mock API
raise SkipTest
#power_status = get_dev_power_status(auth, device_name="Doesn't Exist")
#self.assertEqual(power_status, 'Device not found')
#TODO All Set Device Preference Tests Failing
class TestSetDevicePreference(TestCase):
"""
Test Case for pyawair.devices set_dev_preference function for a single
device name "Bedroom_Awair"
['general', 'productivity', 'sleep', 'allergy', 'baby']
"""
def test_set_dev_preference_pos_id_post(self):
mode = 'general'
preference = set_device_preference(auth, mode, device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
# self.assertIs(type(preference['message']), str)
# self.assertEquals(preference['message'],"success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEqual(dev_details['preference'].lower(), mode)
def test_set_dev_preference_id_bad_mode_neg(self):
"""
Negative Test case
:return:
"""
mode = 'banana'
preference = set_device_preference(auth, mode, device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
self.assertEqual(preference, 'mode setting not valid')
def test_set_dev_preference_pos_general(self):
"""
Positive Test case
"""
mode = 'general'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
#self.assertIs(type(preference['message']), str)
#self.assertEquals(preference['message'],"success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEqual(dev_details['preference'].lower(), mode )
def test_set_dev_preference_no_device_neg(self):
"""
Negative Test case
:return:
"""
mode = 'general'
preference = set_device_preference(auth, mode, device_name="Doesn't Exist")
self.assertEqual(preference, 'Device not found')
def test_set_dev_preference_bad_mode_neg(self):
"""
Negative Test case
:return:
"""
mode = 'banana'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
self.assertEqual(preference, 'mode setting not valid')
'''
def test_set_dev_preference_pos_sleep(self):
"""
Positive Test case
"""
mode = 'sleep'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
self.assertIs(type(preference['message']), str)
self.assertEquals(preference['message'], "success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEquals(dev_details['preference'].lower(), mode)
def test_set_dev_preference_pos_productivity(self):
"""
Positive Test case
"""
mode = 'productivity'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
self.assertIs(type(preference['message']), str)
self.assertEquals(preference['message'], "success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEquals(dev_details['preference'].lower(), mode)
def test_set_dev_preference_pos_baby(self):
"""
Positive Test case
"""
mode = 'baby'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
self.assertIs(type(preference['message']), str)
self.assertEquals(preference['message'], "success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEquals(dev_details['preference'].lower(), mode)
def test_set_dev_preference_pos_allergy(self):
"""
Positive Test case
"""
mode = 'allergy'
preference = set_device_preference(auth, mode, device_name=dev1['name'])
self.assertIs(type(preference['message']), str)
self.assertEquals(preference['message'], "success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEquals(dev_details['preference'].lower(), mode)
'''
class TestSetDeviceTimezone(TestCase):
"""
Test Case for pyawair.devices set_dev_timezone function for a single
device name "Bedroom_Awair"
['general', 'productivity', 'sleep', 'allergy', 'baby']
"""
def test_set_dev_timezone_pos_id_post(self):
raise SkipTest
# skipping test as API was removed from Awair API
new_timezone = 'us/pacific'
timezone = set_device_timezone(auth, new_timezone,device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
self.assertIs(type(timezone['message']), str)
self.assertEqual(timezone['message'], "success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEqual(dev_details['timezone'].lower(), new_timezone.lower())
def test_set_dev_timezone_pos(self):
"""
Positive Test case
"""
raise SkipTest
# skipping test as API was removed from Awair API
new_timezone = 'us/pacific'
timezone = set_device_timezone(auth, new_timezone, device_name=dev1['name'])
self.assertIs(type(timezone['message']), str)
self.assertEqual(timezone['message'],"success")
dev_details = get_dev_details(auth, device_name=dev1['name'])
self.assertEqual(dev_details['timezone'].lower(), new_timezone.lower() )
def test_set_dev_timezone_neg(self):
"""
Negative Test case
:return:
"""
raise SkipTest
# skipping test as API was removed from Awair API
new_timezone = "America/Montreal"
timezone = set_device_timezone(auth, new_timezone, device_name="Doesn't Exist")
self.assertEqual(timezone, 'Device not found')
class TestSetDeviceLED(TestCase):
"""
Test Case for pyawair.devices set_dev_timezone function for a single
device name "Bedroom_Awair"
['general', 'productivity', 'sleep', 'allergy', 'baby']
"""
def test_set_device_led_id_pos(self):
raise SkipTest
# skipping test as API was removed from Awair API
led_mode = 'dim'
new_mode = set_device_led(auth, led_mode,device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
check_mode = get_dev_led_mode(auth, device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
self.assertEqual(check_mode, {'mode': 'on'})
def test_set_device_led_mode_id_neg(self):
raise SkipTest
# skipping test as API was removed from Awair API
led_mode = 'banana'
new_mode = set_device_led(auth, led_mode, device_type=dev1['deviceType'],
device_id=dev1['deviceId'])
self.assertEqual(new_mode, 'mode setting not valid')
def test_set_device_led_name_pos(self):
raise SkipTest
# skipping test as API was removed from Awair API
led_mode = 'dim'
new_mode = set_device_led(auth, led_mode,device_name=dev1['name'])
check_mode = get_dev_led_mode(auth, device_name=dev1['name'])
self.assertEqual(check_mode, {'mode': 'on'})
def test_set_device_led_name_neg(self):
raise SkipTest
# skipping test as API was removed from Awair API
led_mode = 'dim'
new_mode = set_device_led(auth, led_mode,device_name='Doesnt exist')
self.assertEqual(new_mode, 'Device not found')
def test_set_device_led_mode_name_neg(self):
raise SkipTest
# skipping test as API was removed from Awair API
led_mode = 'banana'
new_mode = set_device_led(auth, led_mode,device_name=dev1['name'])
self.assertEqual(new_mode, 'mode setting not valid')