TST+ENH: Move testcases to part of fail2ban module

This allows fail2ban-testcases to be run on an installed fail2ban
instance.
TODO: Fix tests requiring config files
pull/165/head
Steven Hiscocks 2013-04-01 11:22:40 +01:00
parent e53bfafd6a
commit e3bd2042eb
36 changed files with 45 additions and 35 deletions

View File

@ -42,20 +42,21 @@ fail2ban/server/banmanager.py
fail2ban/server/datetemplate.py
fail2ban/server/mytime.py
fail2ban/server/failregex.py
testcases/files/testcase-usedns.log
testcases/banmanagertestcase.py
testcases/failmanagertestcase.py
testcases/clientreadertestcase.py
testcases/filtertestcase.py
testcases/__init__.py
testcases/datedetectortestcase.py
testcases/actiontestcase.py
testcases/servertestcase.py
testcases/sockettestcase.py
testcases/files/testcase01.log
testcases/files/testcase02.log
testcases/files/testcase03.log
testcases/files/testcase04.log
fail2ban/tests/banmanagertestcase.py
fail2ban/tests/failmanagertestcase.py
fail2ban/tests/clientreadertestcase.py
fail2ban/tests/filtertestcase.py
fail2ban/tests/__init__.py
fail2ban/tests/datedetectortestcase.py
fail2ban/tests/actiontestcase.py
fail2ban/tests/servertestcase.py
fail2ban/tests/sockettestcase.py
fail2ban/tests/utils.py
fail2ban/tests/files/testcase01.log
fail2ban/tests/files/testcase02.log
fail2ban/tests/files/testcase03.log
fail2ban/tests/files/testcase04.log
fail2ban/tests/files/testcase-usedns.log
setup.py
setup.cfg
fail2ban/__init__.py

View File

@ -28,16 +28,16 @@ __license__ = "GPL"
import unittest, logging, sys, time, os
from fail2ban.version import version
from testcases import banmanagertestcase
from testcases import clientreadertestcase
from testcases import failmanagertestcase
from testcases import filtertestcase
from testcases import servertestcase
from testcases import datedetectortestcase
from testcases import actiontestcase
from testcases import sockettestcase
from fail2ban.tests import banmanagertestcase
from fail2ban.tests import clientreadertestcase
from fail2ban.tests import failmanagertestcase
from fail2ban.tests import filtertestcase
from fail2ban.tests import servertestcase
from fail2ban.tests import datedetectortestcase
from fail2ban.tests import actiontestcase
from fail2ban.tests import sockettestcase
from testcases.utils import FormatterWithTraceBack
from fail2ban.tests.utils import FormatterWithTraceBack
from fail2ban.server.mytime import MyTime
from optparse import OptionParser, Option

View File

@ -35,6 +35,8 @@ from fail2ban.server.filter import FileFilter, DNSUtils
from fail2ban.server.failmanager import FailManager
from fail2ban.server.failmanager import FailManagerEmpty
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
#
# Useful helpers
#
@ -182,7 +184,7 @@ class IgnoreIP(unittest.TestCase):
class LogFile(unittest.TestCase):
FILENAME = "testcases/files/testcase01.log"
FILENAME = os.path.join(TEST_FILES_DIR, "testcase01.log")
def setUp(self):
"""Call before every test case."""
@ -522,11 +524,11 @@ def get_monitor_failures_testcase(Filter_):
class GetFailures(unittest.TestCase):
FILENAME_01 = "testcases/files/testcase01.log"
FILENAME_02 = "testcases/files/testcase02.log"
FILENAME_03 = "testcases/files/testcase03.log"
FILENAME_04 = "testcases/files/testcase04.log"
FILENAME_USEDNS = "testcases/files/testcase-usedns.log"
FILENAME_01 = os.path.join(TEST_FILES_DIR, "testcase01.log")
FILENAME_02 = os.path.join(TEST_FILES_DIR, "testcase02.log")
FILENAME_03 = os.path.join(TEST_FILES_DIR, "testcase03.log")
FILENAME_04 = os.path.join(TEST_FILES_DIR, "testcase04.log")
FILENAME_USEDNS = os.path.join(TEST_FILES_DIR, "testcase-usedns.log")
# so that they could be reused by other tests
FAILURES_01 = ('193.168.0.128', 3, 1124013599.0,

View File

@ -32,6 +32,8 @@ import unittest, socket, time, tempfile, os
from fail2ban.server.server import Server
from fail2ban.exceptions import UnknownJailException
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), "files")
class StartStop(unittest.TestCase):
def setUp(self):
@ -273,14 +275,14 @@ class Transmitter(TransmitterBase):
self.jailAddDelTest(
"logpath",
[
"testcases/files/testcase01.log",
"testcases/files/testcase02.log",
"testcases/files/testcase03.log",
os.path.join(TEST_FILES_DIR, "testcase01.log"),
os.path.join(TEST_FILES_DIR, "testcase02.log"),
os.path.join(TEST_FILES_DIR, "testcase03.log"),
],
self.jailName
)
# Try duplicates
value = "testcases/files/testcase04.log"
value = os.path.join(TEST_FILES_DIR, "testcase04.log")
self.assertEqual(
self.transm.proceed(["set", self.jailName, "addlogpath", value]),
(0, [value]))

View File

@ -49,13 +49,18 @@ setup(
scripts = [
'fail2ban-client',
'fail2ban-server',
'fail2ban-regex'
'fail2ban-regex',
'fail2ban-testcases',
],
packages = [
'fail2ban',
'fail2ban.client',
'fail2ban.server'
'fail2ban.server',
'fail2ban.tests',
],
package_data = {
'fail2ban.tests': ['files/*.log'],
},
data_files = [
('/etc/fail2ban',
glob("config/*.conf")