forked from barde/wsnserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControllerTest.py
69 lines (55 loc) · 2.37 KB
/
ControllerTest.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
'''
Name: ControllerTest
Purpose: This class is used to test the controller
Created on 02.08.2011
@author: Kamil Wozniak
'''
import unittest
import Controller
import DataRepository
class ControllerTest(unittest.TestCase):
'''
Create new instance of the controller and the datarepository for the tests.
Only one instance of each class is needed, so they are outside the setUp method.
'''
controller = Controller.Controller()
dataRepository = DataRepository.DataRepository()
def setUp(self):
'''
DataRepository is directly used for fixtures.
'''
self.dataRepository.saveData("wsn01", "10")
def testReadCMDAction(self):
pass
def testSaveCMDAction(self):
pass
def testSaveDeviceAction(self):
self.controller.saveDeviceAction("wsn01", "0xACE", "5")
self.assertEqual(1, len(self.dataRepository.readDeviceList()), "Saving the devices failed.")
def testSaveDeviceActionWithEmptyParams(self):
self.controller.saveDeviceAction("", "", "")
self.assertEqual(0, len(self.dataRepository.readDeviceList()), "Parameters have not been recognized.")
def testReadDeviceList(self):
self.controller.saveDeviceAction("wsn01", "0xACE", "5")
devices = self.controller.readDeviceList()
self.assertEqual("wsn01", devices[0][0], "Devices on the list failed.")
def testSaveDataAction(self):
self.controller.saveDataAction("wsn01", "15")
''' Must be equal 2 because one dataset is being added by the setUp method. '''
self.assertEqual(2, len(self.dataRepository.readAllData("wsn01")), "SaveDataAction failed.")
def testReadAllAction(self):
pass
def testReadLeatestAction(self):
self.controller.readLeatestAction("wsn01")
def testRemoveAllDataAction(self):
self.controller.removeAllDataAction()
self.assertEqual(0, len(self.dataRepository.readAllData("wsn01")),
"RemoveAllAction does not work properly.")
def tearDown(self):
''' Remove all data/devices/cmds from db before next test. '''
self.dataRepository.removeAllData()
self.dataRepository.removeAllDevices()
self.dataRepository.removeAllCMD()
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()