summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorTomas Babej <tbabej@redhat.com>2014-04-29 16:03:25 +0200
committerAlexander Bokovoy <abokovoy@redhat.com>2014-05-05 18:57:29 +0300
commitecaf87c0070d8ea7164b4fb4610c68e1388f520e (patch)
tree0d1d6b9e23162d4799abbb86a18f215bfe90e94c /ipatests
parent1df696f5432a673a24ff5cb273fe068a7d88d6ea (diff)
downloadfreeipa-ecaf87c0070d8ea7164b4fb4610c68e1388f520e.tar.gz
freeipa-ecaf87c0070d8ea7164b4fb4610c68e1388f520e.tar.xz
freeipa-ecaf87c0070d8ea7164b4fb4610c68e1388f520e.zip
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>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_ipalib/test_parameters.py46
-rw-r--r--ipatests/test_xmlrpc/xmlrpc_test.py3
2 files changed, 48 insertions, 1 deletions
diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py
index 278e07165..ee0f49d06 100644
--- a/ipatests/test_ipalib/test_parameters.py
+++ b/ipatests/test_ipalib/test_parameters.py
@@ -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) \ No newline at end of file
diff --git a/ipatests/test_xmlrpc/xmlrpc_test.py b/ipatests/test_xmlrpc/xmlrpc_test.py
index a596cd69c..f60e30412 100644
--- a/ipatests/test_xmlrpc/xmlrpc_test.py
+++ b/ipatests/test_xmlrpc/xmlrpc_test.py
@@ -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)