mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
New Param: decided on calling signature for rules; added unit tests for Bytes._rule_minlength, _rule_maxlength, and _rule_length
This commit is contained in:
@@ -500,30 +500,36 @@ class Bytes(Param):
|
||||
self.nice, self.minlength)
|
||||
)
|
||||
|
||||
def _rule_minlength(self, value):
|
||||
def _rule_minlength(self, _, name, value):
|
||||
"""
|
||||
Check minlength constraint.
|
||||
"""
|
||||
assert type(value) is str
|
||||
if len(value) < self.minlength:
|
||||
return 'Must be at least %(minlength)d bytes long.' % dict(
|
||||
return _('%(name)s must be at least %(minlength)d bytes') % dict(
|
||||
name=name,
|
||||
minlength=self.minlength,
|
||||
)
|
||||
|
||||
def _rule_maxlength(self, value):
|
||||
def _rule_maxlength(self, _, name, value):
|
||||
"""
|
||||
Check maxlength constraint.
|
||||
"""
|
||||
assert type(value) is str
|
||||
if len(value) > self.maxlength:
|
||||
return 'Can be at most %(maxlength)d bytes long.' % dict(
|
||||
return _('%(name)s can be at most %(maxlength)d bytes') % dict(
|
||||
name=name,
|
||||
maxlength=self.maxlength,
|
||||
)
|
||||
|
||||
def _rule_length(self, value):
|
||||
def _rule_length(self, _, name, value):
|
||||
"""
|
||||
Check length constraint.
|
||||
"""
|
||||
assert type(value) is str
|
||||
if len(value) != self.length:
|
||||
return 'Must be exactly %(length)d bytes long.' % dict(
|
||||
return _('%(name)s must be exactly %(length)d bytes') % dict(
|
||||
name=name,
|
||||
length=self.length,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user