mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 16:10:02 -06:00
ipatests: Cover DateTime in test_parameters.py
Adds tests for newly added DateTime parameter, focusing on conversion of accepted datetime formats. Part of: https://fedorahosted.org/freeipa/ticket/3306 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
parent
1df696f543
commit
ecaf87c007
@ -22,6 +22,7 @@
|
||||
Test the `ipalib.parameters` module.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import re
|
||||
import sys
|
||||
from types import NoneType
|
||||
@ -1580,3 +1581,48 @@ class test_IA5Str(ClassChecker):
|
||||
assert e.name == 'my_str'
|
||||
assert e.index is None
|
||||
assert_equal(e.error, "The character '\\xc3' is not allowed.")
|
||||
|
||||
|
||||
class test_DateTime(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.parameters.DateTime` class.
|
||||
"""
|
||||
_cls = parameters.DateTime
|
||||
|
||||
def test_init(self):
|
||||
"""
|
||||
Test the `ipalib.parameters.DateTime.__init__` method.
|
||||
"""
|
||||
|
||||
# Test with no kwargs:
|
||||
o = self.cls('my_datetime')
|
||||
assert o.type is datetime.datetime
|
||||
assert isinstance(o, parameters.DateTime)
|
||||
assert o.multivalue is False
|
||||
|
||||
# Check full time formats
|
||||
date = datetime.datetime(1991, 12, 7, 6, 30, 5)
|
||||
assert date == o.convert(u'19911207063005Z')
|
||||
assert date == o.convert(u'1991-12-07T06:30:05Z')
|
||||
assert date == o.convert(u'1991-12-07 06:30:05Z')
|
||||
|
||||
# Check time formats without seconds
|
||||
date = datetime.datetime(1991, 12, 7, 6, 30)
|
||||
assert date == o.convert(u'1991-12-07T06:30Z')
|
||||
assert date == o.convert(u'1991-12-07 06:30Z')
|
||||
|
||||
# Check date formats
|
||||
date = datetime.datetime(1991, 12, 7)
|
||||
assert date == o.convert(u'1991-12-07Z')
|
||||
|
||||
# Check some wrong formats
|
||||
for value in (u'19911207063005',
|
||||
u'1991-12-07T06:30:05',
|
||||
u'1991-12-07 06:30:05',
|
||||
u'1991-12-07T06:30',
|
||||
u'1991-12-07 06:30',
|
||||
u'1991-12-07',
|
||||
u'1991-31-12Z',
|
||||
u'1991-12-07T25:30:05Z',
|
||||
):
|
||||
raises(ConversionError, o.convert, value)
|
@ -21,6 +21,7 @@
|
||||
Base class for all XML-RPC tests
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import nose
|
||||
from ipatests.util import assert_deepequal, Fuzzy
|
||||
from ipalib import api, request, errors
|
||||
@ -86,7 +87,7 @@ fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=basestring)
|
||||
fuzzy_password = Fuzzy('^\S([\S ]*\S)*$')
|
||||
|
||||
# Matches generalized time value. Time format is: %Y%m%d%H%M%SZ
|
||||
fuzzy_dergeneralizedtime = Fuzzy('^[0-9]{14}Z$')
|
||||
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
|
||||
|
||||
# match any string
|
||||
fuzzy_string = Fuzzy(type=basestring)
|
||||
|
Loading…
Reference in New Issue
Block a user