Subversion Repositories HomeAutomation

Rev

Rev 743 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 743 Rev 747
1
import logging as log
1
import logging as log
2
log.basicConfig(level=log.DEBUG,
2
log.basicConfig(level=log.DEBUG,
3
                format='%(asctime)s %(levelname)s %(message)s',
3
                format='%(asctime)s %(levelname)s %(message)s',
4
                filename=__name__ + '.log',
4
                filename=__name__ + '.log',
5
                filemode='w')
5
                filemode='w')
6
import unittest
6
import unittest
7
import sys
7
import sys
8
import os
8
import os
9
 
9
 
10
os.chdir(os.getcwd()[0:-6]) # ouch that hurts!
10
os.chdir(os.getcwd()[0:-6]) # ouch that hurts!
11
STDOUT_REDIRECT_FILE = 'tests/' + __name__ + '2.log'
11
STDOUT_REDIRECT_FILE = 'tests/' + __name__ + '2.log'
12
 
12
 
13
if os.path.exists(STDOUT_REDIRECT_FILE):
13
if os.path.exists(STDOUT_REDIRECT_FILE):
14
    os.remove(STDOUT_REDIRECT_FILE)
14
    os.remove(STDOUT_REDIRECT_FILE)
15
 
15
 
16
#--------------------------------------------------------------------------
16
#--------------------------------------------------------------------------
17
 
17
 
18
from Main import CanDaemon
18
from Main import CanDaemon
19
canDaemon = CanDaemon()
19
canDaemon = CanDaemon()
20
 
20
 
21
class MainCmdTests(unittest.TestCase):
21
class MainCmdTests(unittest.TestCase):
22
   
22
   
23
    def setUp(self):
23
    def setUp(self):
24
        """Call before every test case."""
24
        """Call before every test case."""
25
        sys.stdout = open(STDOUT_REDIRECT_FILE, 'a')
25
        sys.stdout = open(STDOUT_REDIRECT_FILE, 'a')
26
 
26
 
27
    def tearDown(self):
27
    def tearDown(self):
28
        """Call after every test case."""
28
        """Call after every test case."""
29
        sys.stdout = sys.__stdout__
29
        sys.stdout = sys.__stdout__
30
   
30
   
31
    def testA_CmdBasic(self):
31
    def testA_CmdBasic(self):
32
        log.debug('testCmdBasic')
32
        log.debug('testCmdBasic')
33
        canDaemon.parseCommand('hello')
33
        canDaemon.parseCommand('hello')
34
       
34
       
35
    def testB_CmdHelp(self):
35
    def testB_CmdHelp(self):
36
        log.debug('testCmdBasic')
36
        log.debug('testCmdBasic')
37
        canDaemon.parseCommand('help')
37
        canDaemon.parseCommand('help')
38
        canDaemon.parseCommand('help log')
38
        canDaemon.parseCommand('help log')
39
        canDaemon.parseCommand('help filter')
39
        canDaemon.parseCommand('help filter')
40
        canDaemon.parseCommand('help state')
40
        canDaemon.parseCommand('help state')
41
        canDaemon.parseCommand('help addif')
41
        canDaemon.parseCommand('help addif')
42
        canDaemon.parseCommand('help addbridge')
42
        canDaemon.parseCommand('help addbridge')
43
        canDaemon.parseCommand('help tcpd')
43
        canDaemon.parseCommand('help tcpd')
44
        canDaemon.parseCommand('help tlsd')
44
        canDaemon.parseCommand('help tlsd')
45
        canDaemon.parseCommand('help canctld')
45
        canDaemon.parseCommand('help canctld')
46
        canDaemon.parseCommand('help sim')
46
        canDaemon.parseCommand('help sim')
47
 
47
 
48
    def testC_ImportFilter(self):
48
    def testC_ImportFilter(self):
49
        log.debug('testImportFilter')
49
        log.debug('testImportFilter')
50
        canDaemon.parseCommand('filter add DefaultFilter')
50
        canDaemon.parseCommand('filter add DefaultFilter')
51
       
51
       
52
    def testD_RemoveFilter(self):
52
    def testD_RemoveFilter(self):
53
        log.debug('testRemoveFilter')
53
        log.debug('testRemoveFilter')
54
        canDaemon.parseCommand('filter rem DefaultFilter')
54
        canDaemon.parseCommand('filter rem DefaultFilter')
55
 
55
 
56
    def testE_ImportSpace(self):
56
    def testE_ImportSpace(self):
57
        log.debug('testImportSpace')
57
        log.debug('testImportSpace')
58
        canDaemon.parseCommand('state add DefaultStateSpace')
58
        canDaemon.parseCommand('state add DefaultStateSpace')
59
       
59
       
60
    def testF_RemoveSpace(self):
60
    def testF_RemoveSpace(self):
61
        log.debug('testRemoveSpace')
61
        log.debug('testRemoveSpace')
62
        canDaemon.parseCommand('state rem DefaultStateSpace')
62
        canDaemon.parseCommand('state rem DefaultStateSpace')
63
       
63
       
64
    def testG_AddCanStimIf(self):
64
    def testG_AddCanStimIf(self):
65
        log.debug('testAddCanStimIf')
65
        log.debug('testAddCanStimIf')
66
        canDaemon.parseCommand('addif stim0 stim')
66
        canDaemon.parseCommand('addif stim0 stim')
67
   
67
   
68
    def testH_RemCanStimIf(self):
68
    def testH_RemCanStimIf(self):
69
        log.debug('testRemCanStimIf')
69
        log.debug('testRemCanStimIf')
70
        canDaemon.parseCommand('remif stim0')
70
        canDaemon.parseCommand('remif stim0')
71
       
71
       
72
    def testI_AddUDPIf(self):
72
    def testI_AddUDPIf(self):
73
        log.debug('testAddUDPIf')
73
        log.debug('testAddUDPIf')
74
        canDaemon.parseCommand('addif udp0 udp host=192.168.10.2 port=1000')
74
        canDaemon.parseCommand('addif udp0 udp host=192.168.10.2 port=1000')
75
   
75
   
76
    def testJ_RemUDPIf(self):
76
    def testJ_RemUDPIf(self):
77
        log.debug('testRemUDPIf')
77
        log.debug('testRemUDPIf')
78
        canDaemon.parseCommand('remif udp0')
78
        canDaemon.parseCommand('remif udp0')
79
 
79
 
80
    def testK_AddTelnetIf(self):
80
    def testK_AddTCPIf(self):
81
        log.debug('testAddTelnetIf')
81
        log.debug('testAddTCPIf')
82
        canDaemon.parseCommand('addif telnet0 host=192.168.10.2 port=1000')
82
        canDaemon.parseCommand('addif telnet0 host=192.168.10.2 port=1000')
83
   
83
   
84
    def testL_RemTelnetIf(self):
84
    def testL_RemTCPIf(self):
85
        log.debug('testRemTelnetIf')
85
        log.debug('testRemTCPIf')
86
        canDaemon.parseCommand('remif telnet0')
86
        canDaemon.parseCommand('remif telnet0')
87
       
87
       
88
    def testM_AddTcpTlsIf(self):
88
    def testM_AddTcpTlsIf(self):
89
        log.debug('testAddTcpTlsIf')
89
        log.debug('testAddTcpTlsIf')
90
        canDaemon.parseCommand('addif tcptls0 tcptls host=192.168.10.2 port=1000 key=mykey.pub')
90
        canDaemon.parseCommand('addif tcptls0 tcptls host=192.168.10.2 port=1000 key=mykey.pub')
91
           
91
           
92
    def testN_RemTcpTlsIf(self):
92
    def testN_RemTcpTlsIf(self):
93
        log.debug('testRemTcpTlsIf')
93
        log.debug('testRemTcpTlsIf')
94
        canDaemon.parseCommand('remif tcptls0')
94
        canDaemon.parseCommand('remif tcptls0')
95
 
95
 
96
   
96