diff options
Diffstat (limited to 'src/account/test/methods.py')
-rw-r--r-- | src/account/test/methods.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/account/test/methods.py b/src/account/test/methods.py index b453c68..9c033c5 100644 --- a/src/account/test/methods.py +++ b/src/account/test/methods.py @@ -18,6 +18,8 @@ # Authors: Roman Rakus <rrakus@redhat.com> # +import random +import string import subprocess def user_exists(username): @@ -95,3 +97,42 @@ 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=""): + """ + Generate a random string, e.g. usable as UID/GID + """ + 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))]) + return prefix + salt + +def random_shell(): + """ + Make up a funny shell + """ + return random.choice([ + "/bin/ash", + "/bin/cash", + "/bin/dash", + "/bin/hash", + "/bin/nash", + "/bin/mash", + "/bin/sash", + "/bin/stash", + "/bin/splash", + "/bin/wash", + ]) + +def field_is_unique(fname, records): + """ + True if the field in `records` has unique values. + """ + seen = [] + for record in records: + if record[fname] in seen: + return False + else: + seen.append(record[fname]) + return True |