mirror of https://github.com/fail2ban/fail2ban
Merge pull request #479 from grooverdan/tst-CustomDateFormatsTest
TST: missed including testcases CustomDateFormatsTestpull/492/head
commit
051c2a5f50
|
@ -41,7 +41,7 @@ __all__ = ["parse_date", "ParseError"]
|
||||||
# Adapted from http://delete.me.uk/2005/03/iso8601.html
|
# Adapted from http://delete.me.uk/2005/03/iso8601.html
|
||||||
ISO8601_REGEX_RAW = "(?P<year>[0-9]{4})-(?P<month>[0-9]{1,2})-(?P<day>[0-9]{1,2})" \
|
ISO8601_REGEX_RAW = "(?P<year>[0-9]{4})-(?P<month>[0-9]{1,2})-(?P<day>[0-9]{1,2})" \
|
||||||
"T(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?" \
|
"T(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?" \
|
||||||
"(?P<timezone>Z|(([-+])([0-9]{2}):([0-9]{2})))?"
|
"(?P<timezone>Z|[-+][0-9]{2}(:?[0-9]{2})?)?"
|
||||||
ISO8601_REGEX = re.compile(ISO8601_REGEX_RAW)
|
ISO8601_REGEX = re.compile(ISO8601_REGEX_RAW)
|
||||||
TIMEZONE_REGEX = re.compile("(?P<prefix>[+-])(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})?")
|
TIMEZONE_REGEX = re.compile("(?P<prefix>[+-])(?P<hours>[0-9]{2}):?(?P<minutes>[0-9]{2})?")
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,7 @@ class TestsUtilsTest(unittest.TestCase):
|
||||||
|
|
||||||
from fail2ban.server import iso8601
|
from fail2ban.server import iso8601
|
||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
class CustomDateFormatsTest(unittest.TestCase):
|
class CustomDateFormatsTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -190,8 +191,25 @@ class CustomDateFormatsTest(unittest.TestCase):
|
||||||
iso8601.parse_date, "2007-01-01T120:00:00Z")
|
iso8601.parse_date, "2007-01-01T120:00:00Z")
|
||||||
self.assertRaises(iso8601.ParseError,
|
self.assertRaises(iso8601.ParseError,
|
||||||
iso8601.parse_date, "2007-13-01T12:00:00Z")
|
iso8601.parse_date, "2007-13-01T12:00:00Z")
|
||||||
|
date = iso8601.parse_date("2007-01-25T12:00:00+0400")
|
||||||
|
self.assertEqual(
|
||||||
|
date,
|
||||||
|
datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc()))
|
||||||
|
date = iso8601.parse_date("2007-01-25T12:00:00+04:00")
|
||||||
|
self.assertEqual(
|
||||||
|
date,
|
||||||
|
datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc()))
|
||||||
|
date = iso8601.parse_date("2007-01-25T12:00:00-0400")
|
||||||
|
self.assertEqual(
|
||||||
|
date,
|
||||||
|
datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc()))
|
||||||
|
date = iso8601.parse_date("2007-01-25T12:00:00-04")
|
||||||
|
self.assertEqual(
|
||||||
|
date,
|
||||||
|
datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc()))
|
||||||
|
|
||||||
def testTimeZone(self):
|
def testTimeZone(self):
|
||||||
# Just verify consistent operation and improve coverage ;)
|
# Just verify consistent operation and improve coverage ;)
|
||||||
self.assertEqual(iso8601.parse_timezone(None), iso8601.UTC)
|
self.assertEqual((iso8601.parse_timezone(None).tzname(False), iso8601.parse_timezone(None).tzname(True)), time.tzname)
|
||||||
self.assertEqual(iso8601.parse_timezone('Z'), iso8601.UTC)
|
self.assertEqual(iso8601.parse_timezone('Z').tzname(True), "UTC")
|
||||||
|
self.assertEqual(iso8601.parse_timezone('Z').dst(True), datetime.timedelta(0))
|
||||||
|
|
|
@ -184,6 +184,7 @@ def gatherTests(regexps=None, no_network=False):
|
||||||
tests.addTest(unittest.makeSuite(misctestcase.HelpersTest))
|
tests.addTest(unittest.makeSuite(misctestcase.HelpersTest))
|
||||||
tests.addTest(unittest.makeSuite(misctestcase.SetupTest))
|
tests.addTest(unittest.makeSuite(misctestcase.SetupTest))
|
||||||
tests.addTest(unittest.makeSuite(misctestcase.TestsUtilsTest))
|
tests.addTest(unittest.makeSuite(misctestcase.TestsUtilsTest))
|
||||||
|
tests.addTest(unittest.makeSuite(misctestcase.CustomDateFormatsTest))
|
||||||
|
|
||||||
# Filter
|
# Filter
|
||||||
if not no_network:
|
if not no_network:
|
||||||
|
|
Loading…
Reference in New Issue