diff options
Diffstat (limited to 'src/account/test/methods.py')
-rw-r--r-- | src/account/test/methods.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/account/test/methods.py b/src/account/test/methods.py index 9c033c5..4043ddf 100644 --- a/src/account/test/methods.py +++ b/src/account/test/methods.py @@ -97,15 +97,17 @@ def create_group(group_name): if not group_exists(group_name): subprocess.check_call(["groupadd", group_name]) -def random_string(size=6, chars=None, prefix=""): +def random_string(strength=6, chars=None, prefix=""): """ Generate a random string, e.g. usable as UID/GID + + strength is count of random characters in the final string. chars + is sequence of characters to choose from, and prefix can be provided + to prepend it to final string. """ if chars is None: chars = string.ascii_uppercase + string.digits - if len(prefix) > size: - raise ValueError("prefix too long: %s > %s" % (len(prefix), size)) - salt = ''.join([random.choice(chars) for x in range(size - len(prefix))]) + salt = ''.join([random.choice(chars) for x in range(strength)]) return prefix + salt def random_shell(): |