From 2d688a5a03ce9f76827a2694e56fbae7680412b0 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 22 Dec 2013 07:47:24 +0000 Subject: [PATCH 1/3] TST: improve polling test case to ensure isModified only returns True once (file static) --- testcases/filtertestcase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 7b18c4bf..8c706d58 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -234,6 +234,7 @@ class LogFile(unittest.TestCase): def testIsModified(self): self.assertTrue(self.filter.isModified(LogFile.FILENAME)) + self.assertFalse(self.filter.isModified(LogFile.FILENAME)) class LogFileMonitor(LogCaptureTestCase): From 2a67ef519c3a28b64b5b1096173b6bf8090d066d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 22 Dec 2013 08:43:57 +0000 Subject: [PATCH 2/3] TST: missing logpath raises IOError --- fail2ban-testcases | 1 + testcases/filtertestcase.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fail2ban-testcases b/fail2ban-testcases index 21b8fda4..c1191d0e 100755 --- a/fail2ban-testcases +++ b/fail2ban-testcases @@ -177,6 +177,7 @@ if not opts.no_network: tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP)) tests.addTest(unittest.makeSuite(filtertestcase.BasicFilter)) tests.addTest(unittest.makeSuite(filtertestcase.LogFile)) +tests.addTest(unittest.makeSuite(filtertestcase.LogFileFilterPoll)) tests.addTest(unittest.makeSuite(filtertestcase.LogFileMonitor)) if not opts.no_network: tests.addTest(unittest.makeSuite(filtertestcase.GetFailures)) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 8c706d58..8111bcd4 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -215,15 +215,28 @@ class IgnoreIPDNS(IgnoreIP): self.assertFalse(self.filter.inIgnoreIPList("128.178.50.11")) self.assertFalse(self.filter.inIgnoreIPList("128.178.50.13")) +class LogFile(LogCaptureTestCase): -class LogFile(unittest.TestCase): + MISSING = 'testcases/missingLogFile' + + def setUp(self): + LogCaptureTestCase.setUp(self) + + def tearDown(self): + LogCaptureTestCase.tearDown(self) + + def testMissingLogFiles(self): + self.filter = FilterPoll(None) + self.assertRaises(IOError, self.filter.addLogPath, LogFile.MISSING) + +class LogFileFilterPoll(unittest.TestCase): FILENAME = "testcases/files/testcase01.log" def setUp(self): """Call before every test case.""" self.filter = FilterPoll(None) - self.filter.addLogPath(LogFile.FILENAME) + self.filter.addLogPath(LogFileFilterPoll.FILENAME) def tearDown(self): """Call after every test case.""" @@ -233,8 +246,8 @@ class LogFile(unittest.TestCase): # self.filter.openLogFile(LogFile.FILENAME) def testIsModified(self): - self.assertTrue(self.filter.isModified(LogFile.FILENAME)) - self.assertFalse(self.filter.isModified(LogFile.FILENAME)) + self.assertTrue(self.filter.isModified(LogFileFilterPoll.FILENAME)) + self.assertFalse(self.filter.isModified(LogFileFilterPoll.FILENAME)) class LogFileMonitor(LogCaptureTestCase): From 7a9252bd0e3773246d40ec13ca87c6088177aada Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 22 Dec 2013 12:08:10 +0000 Subject: [PATCH 3/3] TST BF: local defination --- testcases/filtertestcase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testcases/filtertestcase.py b/testcases/filtertestcase.py index 8111bcd4..90f0f28a 100644 --- a/testcases/filtertestcase.py +++ b/testcases/filtertestcase.py @@ -618,11 +618,11 @@ class GetFailures(unittest.TestCase): """Call after every test case.""" def testTail(self): - self.filter.addLogPath(LogFile.FILENAME, tail=True) + self.filter.addLogPath(GetFailures.FILENAME_01, tail=True) self.assertEqual(self.filter.getLogPath()[-1].getPos(), 1653) self.filter.getLogPath()[-1].close() self.assertEqual(self.filter.getLogPath()[-1].readline(), "") - self.filter.delLogPath(LogFile.FILENAME) + self.filter.delLogPath(GetFailures.FILENAME_01) self.assertEqual(self.filter.getLogPath(),[]) def testGetFailures01(self, filename=None, failures=None):