summaryrefslogtreecommitdiffstats
path: root/src/account/test/methods.py
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2013-01-14 18:22:04 +0100
committerRoman Rakus <rrakus@redhat.com>2013-01-14 18:23:58 +0100
commite2f7cec35373782817e161ec988922a577dd2da6 (patch)
treee0f1db679bd0410a75e6a523bb05f782ca7b99f2 /src/account/test/methods.py
parentdf6847b72e4ba18d34c9309847f1f8c061102dd0 (diff)
downloadopenlmi-providers-e2f7cec35373782817e161ec988922a577dd2da6.tar.gz
openlmi-providers-e2f7cec35373782817e161ec988922a577dd2da6.tar.xz
openlmi-providers-e2f7cec35373782817e161ec988922a577dd2da6.zip
Account: tests
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src/account/test/methods.py')
-rw-r--r--src/account/test/methods.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/account/test/methods.py b/src/account/test/methods.py
new file mode 100644
index 0000000..b40859f
--- /dev/null
+++ b/src/account/test/methods.py
@@ -0,0 +1,80 @@
+# -*- encoding: utf-8 -*-
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Authors: Roman Rakus <rrakus@redhat.com
+#
+
+import subprocess
+
+def field_in_passwd(username, number):
+ """
+ Return numberth field in /etc/passwd for given username
+ """
+ for line in open("/etc/passwd").readlines():
+ if line.startswith(username):
+ return line.split(":")[number].strip()
+
+def field_in_shadow(username, number):
+ """
+ Return numberth field in /etc/shadow for given username
+ """
+ for line in open("/etc/shadow").readlines():
+ if line.startswith(username):
+ return line.split(":")[number].strip()
+
+def field_in_group(groupname, number):
+ """
+ Return numberth field in /etc/group for given groupname
+ """
+ for line in open("/etc/group").readlines():
+ if line.startswith(groupname):
+ return line.split(":")[number].strip()
+
+def clean_account(user_name):
+ """
+ Force to delete testing account and remove home dir
+ """
+ subprocess.call(["userdel", "-fr", user_name])
+ # groups should be expicitely deleted
+ subprocess.call(["groupdel", user_name])
+ subprocess.call(["rm", "-fr", "/home/%s" %user_name])
+
+def add_user_to_group(user_name, group_name):
+ """
+ Will add user to group
+ """
+ subprocess.call(["usermod", "-a", "-G", group_name, user_name])
+
+def create_account(user_name):
+ """
+ Force to create account; run clean_account before creation
+ """
+ clean_account(user_name)
+ subprocess.call(["useradd", user_name])
+
+def clean_group(group_name):
+ """
+ Force to delete testing group
+ """
+ subprocess.call(["groupdel", group_name])
+
+def create_group(group_name):
+ """
+ Force to create group
+ """
+ clean_group(group_name)
+ subprocess.call(["groupadd", group_name])