From 8df911248700f6b46b9cbb3889f6e8621bb112fd Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 27 Dec 2013 12:54:59 +0000 Subject: [PATCH] TST: get StartStop test case closer to something usable (not there yet however) --- fail2ban/tests/servertestcase.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index a9016737..dd9fd6d9 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -29,6 +29,8 @@ import unittest, socket, time, tempfile, os, locale, sys, logging from fail2ban.server.server import Server from fail2ban.server.jail import Jail from fail2ban.exceptions import UnknownJailException +from fail2ban.tests.utils import LogCaptureTestCase +#from bin.fail2ban-client import Fail2banClient try: from fail2ban.server import filtersystemd except ImportError: # pragma: no cover @@ -36,24 +38,36 @@ except ImportError: # pragma: no cover TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files") -class StartStop(unittest.TestCase): +class StartStop(LogCaptureTestCase): def setUp(self): - """Call before every test case.""" - self.__server = Server() - self.__server.setLogLevel(0) - self.__server.start(False) + self.client = Fail2banClient() + LogCaptureTestCase.setUp(self) + sock_fd, sock_name = tempfile.mkstemp('fail2ban.sock', 'transmitter') + os.close(sock_fd) + os.remove(sock_name) + pidfile_fd, pidfile_name = tempfile.mkstemp( + 'fail2ban.pid', 'transmitter') + os.close(pidfile_fd) + os.remove(pidfile_name) + self.client.__getCmdLineOptions([ + ('-c', os.path.join('fail2ban', 'tests', 'config')), + ('-s', sock_name), + ('-p', pidfile_name)]) + self.client.__startServerAsync(sock_name, pidfile_name, False) + self.client.__waitOnServer() def tearDown(self): - """Call after every test case.""" self.__server.quit() + LogCaptureTestCase.tearDown(self) def testStartStopJail(self): name = "TestCase" - self.__server.addJail(name) + self.__server.addJail(name, "auto") self.__server.startJail(name) time.sleep(1) self.__server.stopJail(name) + self.printLog() class TestServer(Server): def setLogLevel(self, *args, **kwargs):