add username's option
This commit is contained in:
parent
f3a826a8d7
commit
9f903d3e04
25
test/test_option_username.py
Normal file
25
test/test_option_username.py
Normal file
@ -0,0 +1,25 @@
|
||||
"configuration objects global API"
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import UsernameOption
|
||||
|
||||
def test_username():
|
||||
UsernameOption('a', '', 'string')
|
||||
UsernameOption('a', '', '_string')
|
||||
UsernameOption('a', '', 's_tring')
|
||||
UsernameOption('a', '', 'string_')
|
||||
UsernameOption('a', '', 'string$')
|
||||
UsernameOption('a', '', '_string$')
|
||||
raises(ValueError, "UsernameOption('a', '', 'strin$g')")
|
||||
UsernameOption('a', '', 's-tring')
|
||||
raises(ValueError, "UsernameOption('a', '', '-string')")
|
||||
UsernameOption('a', '', 's9tring')
|
||||
raises(ValueError, "UsernameOption('a', '', '9string')")
|
||||
raises(ValueError, "UsernameOption('a', '', '')")
|
||||
UsernameOption('a', '', 's')
|
||||
UsernameOption('a', '', 's2345678901234567890123456789012')
|
||||
raises(ValueError, "UsernameOption('a', '', 's23456789012345678901234567890123')")
|
||||
UsernameOption('a', '', 's234567890123456789012345678901$')
|
||||
raises(ValueError, "UsernameOption('a', '', 's2345678901234567890123456789012$')")
|
@ -1079,6 +1079,18 @@ class URLOption(DomainnameOption):
|
||||
raise ValueError(_('invalid url, should ends with filename'))
|
||||
|
||||
|
||||
class UsernameOption(Option):
|
||||
__slots__ = tuple()
|
||||
_opt_type = 'username'
|
||||
#regexp build with 'man 8 adduser' informations
|
||||
username_re = re.compile(r"^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$")
|
||||
|
||||
def _validate(self, value):
|
||||
match = self.username_re.search(value)
|
||||
if not match:
|
||||
raise ValueError(_('invalid username'))
|
||||
|
||||
|
||||
class FilenameOption(Option):
|
||||
__slots__ = tuple()
|
||||
_opt_type = 'file'
|
||||
|
Loading…
Reference in New Issue
Block a user