TST: get StartStop test case closer to something usable (not there yet however)

pull/523/head
Daniel Black 11 years ago
parent 6aae276d2b
commit 8df9112487

@ -29,6 +29,8 @@ import unittest, socket, time, tempfile, os, locale, sys, logging
from fail2ban.server.server import Server from fail2ban.server.server import Server
from fail2ban.server.jail import Jail from fail2ban.server.jail import Jail
from fail2ban.exceptions import UnknownJailException from fail2ban.exceptions import UnknownJailException
from fail2ban.tests.utils import LogCaptureTestCase
#from bin.fail2ban-client import Fail2banClient
try: try:
from fail2ban.server import filtersystemd from fail2ban.server import filtersystemd
except ImportError: # pragma: no cover 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") TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
class StartStop(unittest.TestCase): class StartStop(LogCaptureTestCase):
def setUp(self): def setUp(self):
"""Call before every test case.""" self.client = Fail2banClient()
self.__server = Server() LogCaptureTestCase.setUp(self)
self.__server.setLogLevel(0) sock_fd, sock_name = tempfile.mkstemp('fail2ban.sock', 'transmitter')
self.__server.start(False) 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): def tearDown(self):
"""Call after every test case."""
self.__server.quit() self.__server.quit()
LogCaptureTestCase.tearDown(self)
def testStartStopJail(self): def testStartStopJail(self):
name = "TestCase" name = "TestCase"
self.__server.addJail(name) self.__server.addJail(name, "auto")
self.__server.startJail(name) self.__server.startJail(name)
time.sleep(1) time.sleep(1)
self.__server.stopJail(name) self.__server.stopJail(name)
self.printLog()
class TestServer(Server): class TestServer(Server):
def setLogLevel(self, *args, **kwargs): def setLogLevel(self, *args, **kwargs):

Loading…
Cancel
Save