diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-05 02:45:07 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-05 02:45:07 -0700 |
commit | 690ad4766d9265026d46fcc50118f341776f81b0 (patch) | |
tree | db61eceaf0fa4e681e0c847754f477ecbbec59b5 /tests/test_ipalib | |
parent | 6d6c0d81ddbfc56672f0595a5f631c5e846d8b2b (diff) | |
download | freeipa-690ad4766d9265026d46fcc50118f341776f81b0.tar.gz freeipa-690ad4766d9265026d46fcc50118f341776f81b0.tar.xz freeipa-690ad4766d9265026d46fcc50118f341776f81b0.zip |
New Param: added Str length rule methods; added corresponding unit tests
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r-- | tests/test_ipalib/test_parameter.py | 102 |
1 files changed, 77 insertions, 25 deletions
diff --git a/tests/test_ipalib/test_parameter.py b/tests/test_ipalib/test_parameter.py index 59e320314..e2016f06d 100644 --- a/tests/test_ipalib/test_parameter.py +++ b/tests/test_ipalib/test_parameter.py @@ -396,31 +396,6 @@ class test_Bytes(ClassChecker): assert dummy.message == \ '%(name)s can be at most %(maxlength)d bytes' - def test_rule_maxlength(self): - """ - Test the `ipalib.parameter.Bytes._rule_maxlength` method. - """ - name = 'My Bytes' - o = self.cls('my_bytes', maxlength=4) - assert o.maxlength == 4 - m = o._rule_maxlength - translation = u'name=%(name)r, maxlength=%(maxlength)r' - dummy = dummy_ugettext(translation) - assert dummy.translation is translation - - # Test with passing values: - for value in ('ab', '123', 'four'): - assert m(dummy, name, value) is None - assert not hasattr(dummy, 'message') - - # Test with a failing value: - assert_equal( - m(dummy, name, '12345'), - translation % dict(name=name, maxlength=4), - ) - assert dummy.message == \ - '%(name)s can be at most %(maxlength)d bytes' - def test_rule_length(self): """ Test the `ipalib.parameter.Bytes._rule_length` method. @@ -477,3 +452,80 @@ class test_Str(ClassChecker): e = raises(TypeError, o._convert_scalar, value) assert str(e) == \ 'Can only implicitly convert int, float, or bool; got %r' % value + + def test_rule_minlength(self): + """ + Test the `ipalib.parameter.Str._rule_minlength` method. + """ + name = 'My Str' + o = self.cls('my_str', minlength=3) + assert o.minlength == 3 + m = o._rule_minlength + translation = u'name=%(name)r, minlength=%(minlength)r' + dummy = dummy_ugettext(translation) + assert dummy.translation is translation + + # Test with passing values: + for value in (u'abc', u'four', u'12345'): + assert m(dummy, name, value) is None + assert not hasattr(dummy, 'message') + + # Test with a failing value: + assert_equal( + m(dummy, name, u'ab'), + translation % dict(name=name, minlength=3), + ) + assert dummy.message == \ + '%(name)s must be at least %(minlength)d characters' + + def test_rule_maxlength(self): + """ + Test the `ipalib.parameter.Str._rule_maxlength` method. + """ + name = 'My Str' + o = self.cls('my_str', maxlength=4) + assert o.maxlength == 4 + m = o._rule_maxlength + translation = u'name=%(name)r, maxlength=%(maxlength)r' + dummy = dummy_ugettext(translation) + assert dummy.translation is translation + + # Test with passing values: + for value in (u'ab', u'123', u'four'): + assert m(dummy, name, value) is None + assert not hasattr(dummy, 'message') + + # Test with a failing value: + assert_equal( + m(dummy, name, u'12345'), + translation % dict(name=name, maxlength=4), + ) + assert dummy.message == \ + '%(name)s can be at most %(maxlength)d characters' + + def test_rule_length(self): + """ + Test the `ipalib.parameter.Str._rule_length` method. + """ + name = 'My Str' + o = self.cls('my_str', length=4) + assert o.length == 4 + m = o._rule_length + translation = u'name=%(name)r, length=%(length)r' + dummy = dummy_ugettext(translation) + assert dummy.translation is translation + + # Test with passing values: + for value in (u'1234', u'four'): + assert m(dummy, name, value) is None + assert not hasattr(dummy, 'message') + + # Test with failing values: + for value in (u'ab', u'123', u'12345', u'abcdef'): + assert_equal( + m(dummy, name, value), + translation % dict(name=name, length=4), + ) + assert dummy.message == \ + '%(name)s must be exactly %(length)d characters' + dummy = dummy_ugettext(translation) |