-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin_tests.py
98 lines (84 loc) · 4.42 KB
/
plugin_tests.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
import unittest
import logging
import plugin
from tests.devicelist import *
from tests.devicelistWeb import *
from tests.eventsLocal import *
from tests.eventsWeb import *
from tests.command import *
from utils import *
from tests.params import *
from tahoma_local import SomfyBox
from tahoma import Tahoma
class PluginTestsLocal(unittest.TestCase):
"""test cases for local API"""
def setUp(self):
self.thePlug=plugin.BasePlugin()
self.thePlug.local = True
self.thePlug.tahoma = SomfyBox(p_pin, p_port)
logging.info("===start unit test case===")
def test_createDevices(self):
"""test create devices for local API"""
logging.info("test start: test_createDevices Local")
self.assertEqual(self.thePlug.create_devices(filter_devices(deviceList)), (3,3))
logging.info("test end: test_createDevices Local")
def test_UpdateDevicesFromState(self):
"""test update devices status from setup for local API"""
logging.info("test start: test_UpdateDevicesFromState Local")
self.assertEqual(self.thePlug.update_devices_status(filter_states(deviceList)), 0) # should return 18 but this fails because there are no devices registered in fake domoticz
logging.info("test end: test_UpdateDevicesFromState Local")
def test_updateDevicesFromEvents(self):
"""test update devices from device changed events for local API"""
logging.info("test start: test_updateDevicesFromEvents Local")
self.assertEqual(self.thePlug.update_devices_status(eventsLocal), 0)
logging.info("test end: test_updateDevicesFromEvents Local")
@unittest.skip("creating devices not working yet")
def test_OnCommand(self):
"""test building command local"""
logging.info("test start: test_OnCommand Local")
Devices = self.thePlug.create_devices(filter_devices(deviceList))
self.thePlug.Devices = Devices
print("len(self.thePlug.Devices): "+str(len(self.thePlug.Devices)))
self.assertEqual(self.thePlug.onCommand(commandOn["DeviceId"], commandOn["Unit"], commandOn["Command"], commandOn["Level"], commandOn["Hue"]), True)
logging.info("test end: test_OnCommand Local")
def test_OnStart(self):
"""test running onStart local"""
logging.info("test start: test_OnStart Local")
print("test start: test_OnStart Local")
self.assertEqual(self.thePlug.onStart(), False)
logging.info("test end: test_OnStart Local")
def test_onHeartbeat(self):
"""test running onStart local"""
logging.info("test start: test_onHeartbeat Local")
print("test start: test_onHeartbeat Local")
self.thePlug.enabled = True
self.assertEqual(self.thePlug.onHeartbeat(), False)
logging.info("test end: test_onHeartbeat Local")
class PluginTestsWeb(unittest.TestCase):
"""test cases for web API"""
def setUp(self):
self.thePlug=plugin.BasePlugin()
self.thePlug.local = False
self.thePlug.tahoma = Tahoma()
logging.info("===start unit test case===")
def test_createDevices(self):
"""test create devices for web API"""
logging.info("test start: test_createDevices Web")
self.assertEqual(self.thePlug.create_devices(filter_devices(deviceListWeb)), (3,3))
logging.info("test end: test_createDevices Web")
def test_UpdateDevicesFromState(self):
"""test update devices status from setup for Web API"""
logging.info("test start: test_UpdateDevicesFromState Web")
self.assertEqual(self.thePlug.update_devices_status(filter_states(deviceListWeb)), 0) # should return 2 but this fails because there are no devices registered in fake domoticz
logging.info("test end: test_UpdateDevicesFromState Web")
def test_updateDevicesFromEvents(self):
"""test update devices from device changed events for web API"""
logging.info("test start: test_updateDevicesFromEvents Web")
self.assertEqual(self.thePlug.update_devices_status(eventsWeb), 0)
logging.info("test end: test_updateDevicesFromEvents Web")
def main():
logging.basicConfig(format='%(asctime)s - %(levelname)-8s - %(filename)-18s - %(message)s', filename="somfy_unit_test.log",level=logging.DEBUG)
logging.info("====== start unit test run ======")
unittest.main()
if __name__ == "__main__":
main()