TestHpingTest.py

Go to the documentation of this file.
00001 #
00002 # Test Environment for VoIP Networks (TestEnv)
00003 #
00004 # Copyright (C) 2008  Enrico Hartung <enrico@iptel.org>
00005 #
00006 # This program is free software: you can redistribute it and/or modify
00007 # it under the terms of the GNU General Public License as published by
00008 # the Free Software Foundation, either version 3 of the License, or
00009 # (at your option) any later version.
00010 #
00011 # This program is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 # GNU General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU General Public License
00017 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 from testenv.modules.HpingTest import HpingTest
00020 from testenv.core.TestResult import TestResult
00021 
00022 import lib.ModuleTest
00023 import unittest
00024 
00025 import os
00026 import time
00027 
00028 ##
00029 # 
00030 #       Test cases for testing functionallity of the HpingTest module.
00031 #       
00032 #       @author Enrico Hartung <enrico@iptel.org>
00033 #       @license GPL
00034 #       
00035 class TestHpingTest(unittest.TestCase):
00036         
00037         #storage for test result
00038         __result = None
00039         
00040         #path to store created log files
00041         __logFilePath = ""
00042         
00043         #set path to Protos - should be adapted to system
00044         __hpingPath = "tools"
00045         
00046         
00047         ##
00048         # 
00049         #               Dummy callback method (needed by test modules)
00050         #               
00051         #               @param result the result of the test (testenv.core.TestResult)
00052         #               
00053         def addResult(self, result):
00054                 assert isinstance(result, TestResult)
00055                 self.__result = result
00056                 
00057         
00058         ##
00059         # 
00060         #               Create temporary directory for storing created log files.
00061         #               
00062         def setUp(self):
00063                 self.__logFilePath = "logs/unittest"  + "_" + str(time.time())
00064                 os.makedirs(self.__logFilePath)
00065                 
00066                 
00067         ##
00068         # 
00069         #               Remove temporary log file directory including files stored in it.
00070         #               
00071         def tearDown(self):
00072                 for root, dirs, files in os.walk(self.__logFilePath, topdown=False):
00073                         for name in files:
00074                                 os.remove(os.path.join(root, name))
00075                 
00076                 os.rmdir(self.__logFilePath)
00077 
00078 
00079         ##
00080         # 
00081         #               Test initialization of HpingTest module.
00082         #               
00083         def testInit(self):
00084                 test = HpingTest("test", 0, self)
00085         
00086 
00087         ##
00088         # 
00089         #               Test running Hping with HpingTest module.
00090         #               
00091         def testRunTestModule(self):
00092                 test = HpingTest("test", 10, self)
00093                 
00094                 #set path to Hping
00095                 test.setParameter("configuration.local.modules.hping.path", self.__hpingPath)
00096 
00097                 test.set("logPath", self.__logFilePath)
00098                 
00099                 #assuming that TCP port 22 is open
00100                 test.set("arguments", ["-S", "-p", "22", "127.0.0.1", "-c", "1"])
00101                 
00102                 test.run()
00103                 
00104                 #assert that result of test is a TestResult
00105                 assert isinstance(self.__result, TestResult)
00106                 
00107                 #assert that port 22 is open and the TCP return code is 18
00108                 assert self.__result.get("resultCode") == 18
00109                 
00110                 #assert that test has been terminated
00111                 assert self.__result.get("terminationType") == "terminated"
00112                 
00113                 #set result to None for further tests
00114                 self.__result = None
00115         
00116         
00117         ##
00118         # 
00119         #               Test running Hping with HpingTest module.
00120         #               
00121         def testRunTestModuleWithError(self):
00122                 test = HpingTest("test", 10, self)
00123                 
00124                 #set path to Hping
00125                 test.setParameter("configuration.local.modules.hping.path", self.__hpingPath)
00126 
00127                 test.set("logPath", self.__logFilePath)
00128                 
00129                 #assuming that TCP port 66 is closed
00130                 test.set("arguments", ["-S", "-p", "66", "127.0.0.1", "-c", "1"])
00131                 
00132                 test.run()
00133                 
00134                 #assert that result of test is a TestResult
00135                 assert isinstance(self.__result, TestResult)
00136                 
00137                 #assert that port 66 is closed and the TCP return code is 20
00138                 assert self.__result.get("resultCode") == 20
00139                 
00140                 #assert that test has been terminated
00141                 assert self.__result.get("terminationType") == "terminated"
00142                 
00143                 #set result to None for further tests
00144                 self.__result = None
00145 
00146 

Generated on Mon Aug 11 17:28:19 2008 for TestEnv by  doxygen 1.5.5