Subversion Repositories HomeAutomation

Rev

Rev 747 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

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