summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>2015-10-09 15:33:16 +0300
committerJakub Hrozek <jhrozek@redhat.com>2015-10-22 18:34:35 +0200
commitefdcf49660505e13607b99ba82eb504cf37b8794 (patch)
tree64b62f9b68e3e79ef011268e2ecfe82951343baf
parent86ffb3db2a6e798aaa920a0b40e0c517db8c293f (diff)
downloadsssd-efdcf49660505e13607b99ba82eb504cf37b8794.tar.gz
sssd-efdcf49660505e13607b99ba82eb504cf37b8794.tar.xz
sssd-efdcf49660505e13607b99ba82eb504cf37b8794.zip
intg: Fix all PEP8 issues
Reviewed-by: Michal Židek <mzidek@redhat.com>
-rw-r--r--src/tests/intg/ds.py14
-rw-r--r--src/tests/intg/ds_openldap.py39
-rw-r--r--src/tests/intg/ent.py47
-rw-r--r--src/tests/intg/ent_test.py68
-rw-r--r--src/tests/intg/ldap_test.py56
-rw-r--r--src/tests/intg/util.py2
6 files changed, 121 insertions, 105 deletions
diff --git a/src/tests/intg/ds.py b/src/tests/intg/ds.py
index fe9338490..df08facf4 100644
--- a/src/tests/intg/ds.py
+++ b/src/tests/intg/ds.py
@@ -35,13 +35,13 @@ class DS:
admin_rdn Administrator DN, relative to BASE_DN.
admin_pw Administrator password.
"""
- self.dir = dir
- self.port = port
- self.ldap_url = "ldap://localhost:" + str(self.port)
- self.base_dn = base_dn
- self.admin_rdn = admin_rdn
- self.admin_dn = admin_rdn + "," + base_dn
- self.admin_pw = admin_pw
+ self.dir = dir
+ self.port = port
+ self.ldap_url = "ldap://localhost:" + str(self.port)
+ self.base_dn = base_dn
+ self.admin_rdn = admin_rdn
+ self.admin_dn = admin_rdn + "," + base_dn
+ self.admin_pw = admin_pw
def setup(self):
"""Setup the instance"""
diff --git a/src/tests/intg/ds_openldap.py b/src/tests/intg/ds_openldap.py
index ba7fde649..ab313cb57 100644
--- a/src/tests/intg/ds_openldap.py
+++ b/src/tests/intg/ds_openldap.py
@@ -55,23 +55,23 @@ class DSOpenLDAP(DS):
admin_pw Administrator password.
"""
DS.__init__(self, dir, port, base_dn, admin_rdn, admin_pw)
- self.run_dir = self.dir + "/var/run/ldap"
- self.pid_path = self.run_dir + "/slapd.pid"
- self.conf_dir = self.dir + "/etc/ldap"
- self.conf_slapd_d_dir = self.conf_dir + "/slapd.d"
- self.data_dir = self.dir + "/var/lib/ldap"
+ self.run_dir = self.dir + "/var/run/ldap"
+ self.pid_path = self.run_dir + "/slapd.pid"
+ self.conf_dir = self.dir + "/etc/ldap"
+ self.conf_slapd_d_dir = self.conf_dir + "/slapd.d"
+ self.data_dir = self.dir + "/var/lib/ldap"
def _setup_config(self):
"""Setup the instance initial configuration."""
- dist_lib_dir = first_dir("/usr/lib/openldap",
- "/usr/lib64/openldap",
- "/usr/lib/ldap")
- dist_conf_dir = first_dir("/etc/ldap",
- "/etc/openldap")
- args_file = self.run_dir + "/slapd.args"
- admin_pw_hash = hash_password(self.admin_pw)
- uid = os.geteuid()
- gid = os.getegid()
+ dist_lib_dir = first_dir("/usr/lib/openldap",
+ "/usr/lib64/openldap",
+ "/usr/lib/ldap")
+ dist_conf_dir = first_dir("/etc/ldap",
+ "/etc/openldap")
+ args_file = self.run_dir + "/slapd.args"
+ admin_pw_hash = hash_password(self.admin_pw)
+ uid = os.geteuid()
+ gid = os.getegid()
#
# Add configuration
@@ -159,7 +159,7 @@ class DSOpenLDAP(DS):
slapadd = subprocess.Popen(
["slapadd", "-F", self.conf_slapd_d_dir, "-b", "cn=config"],
- stdin = subprocess.PIPE, close_fds = True
+ stdin=subprocess.PIPE, close_fds=True
)
slapadd.communicate(config)
if slapadd.returncode != 0:
@@ -182,9 +182,9 @@ class DSOpenLDAP(DS):
def setup(self):
"""Setup the instance."""
- ldapi_socket = self.run_dir + "/ldapi"
- ldapi_url = "ldapi://" + urllib.quote(ldapi_socket, "")
- url_list = ldapi_url + " " + self.ldap_url
+ ldapi_socket = self.run_dir + "/ldapi"
+ ldapi_url = "ldapi://" + urllib.quote(ldapi_socket, "")
+ url_list = ldapi_url + " " + self.ldap_url
os.makedirs(self.conf_slapd_d_dir)
os.makedirs(self.run_dir)
@@ -209,7 +209,8 @@ class DSOpenLDAP(DS):
while True:
try:
ldap_conn = ldap.initialize(ldapi_url)
- ldap_conn.simple_bind_s(self.admin_rdn + ",cn=config", self.admin_pw)
+ ldap_conn.simple_bind_s(self.admin_rdn + ",cn=config",
+ self.admin_pw)
ldap_conn.unbind_s()
ldap_conn = ldap.initialize(self.ldap_url)
ldap_conn.simple_bind_s(self.admin_dn, self.admin_pw)
diff --git a/src/tests/intg/ent.py b/src/tests/intg/ent.py
index 0ba7758a1..0fe08dcbd 100644
--- a/src/tests/intg/ent.py
+++ b/src/tests/intg/ent.py
@@ -21,9 +21,9 @@ from pprint import pformat
import pwd
import grp
-_PASSWD_LIST_DESC = {None: ("user", {})}
-_GROUP_DESC = {"mem": ("member list", {None: ("member", {})})}
-_GROUP_LIST_DESC = {None: ("group", _GROUP_DESC)}
+_PASSWD_LIST_DESC = {None: ("user", {})}
+_GROUP_DESC = {"mem": ("member list", {None: ("member", {})})}
+_GROUP_LIST_DESC = {None: ("group", _GROUP_DESC)}
def _get_desc(desc_map, key):
@@ -39,10 +39,10 @@ def _get_desc(desc_map, key):
return desc_map[key]
if None in desc_map:
desc = desc_map[None]
- if key != None:
+ if key is not None:
desc = (desc[0] + " " + pformat(key), desc[1])
return desc
- elif key == None:
+ elif key is None:
return ("item", {})
else:
return (pformat(key), {})
@@ -123,9 +123,8 @@ def _diff(ent, pattern, desc_map={}):
if not d:
pattern_matches[pi] += 1
- unmatched_pattern = [ pattern[pi] for pi in \
- xrange(0, len(pattern)) \
- if pattern_matches[pi] == 0 ]
+ unmatched_pattern = [pattern[pi] for pi in xrange(0, len(pattern))
+ if pattern_matches[pi] == 0]
items = _get_desc(desc_map, None)[0] + "s"
if len(unmatched_pattern) > 0:
@@ -145,12 +144,10 @@ def _diff(ent, pattern, desc_map={}):
pattern_matches[pi] += 1
ent_matches[ei] += 1
- unmatched_pattern = [ pattern[pi] for pi in \
- xrange(0, len(pattern)) \
- if pattern_matches[pi] == 0 ]
- unmatched_ent = [ ent[pi] for pi in \
- xrange(0, len(ent)) \
- if ent_matches[pi] == 0 ]
+ unmatched_pattern = [pattern[pi] for pi in xrange(0, len(pattern))
+ if pattern_matches[pi] == 0]
+ unmatched_ent = [ent[pi] for pi in xrange(0, len(ent))
+ if ent_matches[pi] == 0]
items = _get_desc(desc_map, None)[0] + "s"
d = ""
@@ -190,13 +187,13 @@ def _convert_passwd(passwd):
Convert a passwd entry returned by pwd module to an entry dictionary.
"""
return dict(
- name = passwd.pw_name,
- passwd = passwd.pw_passwd,
- uid = passwd.pw_uid,
- gid = passwd.pw_gid,
- gecos = passwd.pw_gecos,
- dir = passwd.pw_dir,
- shell = passwd.pw_shell
+ name=passwd.pw_name,
+ passwd=passwd.pw_passwd,
+ uid=passwd.pw_uid,
+ gid=passwd.pw_gid,
+ gecos=passwd.pw_gecos,
+ dir=passwd.pw_dir,
+ shell=passwd.pw_shell
)
@@ -353,10 +350,10 @@ def _convert_group(group):
Convert a group entry returned by grp module to an entry dictionary.
"""
return dict(
- name = group.gr_name,
- passwd = group.gr_passwd,
- gid = group.gr_gid,
- mem = group.gr_mem
+ name=group.gr_name,
+ passwd=group.gr_passwd,
+ gid=group.gr_gid,
+ mem=group.gr_mem
)
diff --git a/src/tests/intg/ent_test.py b/src/tests/intg/ent_test.py
index 7c044c7c7..abba94a24 100644
--- a/src/tests/intg/ent_test.py
+++ b/src/tests/intg/ent_test.py
@@ -52,47 +52,47 @@ def group_path(request):
return backup_envvar_file(name)
-USER1 = dict(name="user1", passwd="x", uid=1001, gid=2001,
- gecos="User 1", dir="/home/user1", shell="/bin/bash")
-USER2 = dict(name="user2", passwd="x", uid=1002, gid=2002,
- gecos="User 2", dir="/home/user2", shell="/bin/bash")
-USER_LIST = [USER1, USER2]
-USER_NAME_DICT = dict((u["name"], u) for u in USER_LIST)
-USER_UID_DICT = dict((u["uid"], u) for u in USER_LIST)
-
-
-EMPTY_GROUP = dict(name="empty_group", passwd="x", gid=2000,
- mem=ent.contains_only())
-GROUP1 = dict(name="group1", passwd="x", gid=2001,
- mem=ent.contains_only())
-GROUP2 = dict(name="group2", passwd="x", gid=2002,
- mem=ent.contains_only())
+USER1 = dict(name="user1", passwd="x", uid=1001, gid=2001,
+ gecos="User 1", dir="/home/user1", shell="/bin/bash")
+USER2 = dict(name="user2", passwd="x", uid=1002, gid=2002,
+ gecos="User 2", dir="/home/user2", shell="/bin/bash")
+USER_LIST = [USER1, USER2]
+USER_NAME_DICT = dict((u["name"], u) for u in USER_LIST)
+USER_UID_DICT = dict((u["uid"], u) for u in USER_LIST)
+
+
+EMPTY_GROUP = dict(name="empty_group", passwd="x", gid=2000,
+ mem=ent.contains_only())
+GROUP1 = dict(name="group1", passwd="x", gid=2001,
+ mem=ent.contains_only())
+GROUP2 = dict(name="group2", passwd="x", gid=2002,
+ mem=ent.contains_only())
ONE_USER_GROUP1 = dict(name="one_user_group1", passwd="x", gid=2011,
mem=ent.contains_only("user1"))
ONE_USER_GROUP2 = dict(name="one_user_group2", passwd="x", gid=2012,
mem=ent.contains_only("user2"))
-TWO_USER_GROUP = dict(name="two_user_group", passwd="x", gid=2020,
- mem=ent.contains_only("user1", "user2"))
-GROUP_LIST = [EMPTY_GROUP,
- GROUP1,
- GROUP2,
- ONE_USER_GROUP1,
- ONE_USER_GROUP2,
- TWO_USER_GROUP]
+TWO_USER_GROUP = dict(name="two_user_group", passwd="x", gid=2020,
+ mem=ent.contains_only("user1", "user2"))
+GROUP_LIST = [EMPTY_GROUP,
+ GROUP1,
+ GROUP2,
+ ONE_USER_GROUP1,
+ ONE_USER_GROUP2,
+ TWO_USER_GROUP]
GROUP_NAME_DICT = dict((g["name"], g) for g in GROUP_LIST)
-GROUP_GID_DICT = dict((g["gid"], g) for g in GROUP_LIST)
+GROUP_GID_DICT = dict((g["gid"], g) for g in GROUP_LIST)
@pytest.fixture(scope="module")
def users_and_groups(request, passwd_path, group_path):
passwd_contents = "".join([
- "{name}:{passwd}:{uid}:{gid}:{gecos}:{dir}:{shell}\n".format(**u) \
- for u in USER_LIST
+ "{name}:{passwd}:{uid}:{gid}:{gecos}:{dir}:{shell}\n".format(**u)
+ for u in USER_LIST
])
group_contents = "".join([
"%s:%s:%s:%s\n" % (g["name"], g["passwd"], g["gid"],
- ",".join(g["mem"])) \
- for g in GROUP_LIST
+ ",".join(g["mem"]))
+ for g in GROUP_LIST
])
with open(passwd_path, "a") as f:
@@ -174,15 +174,15 @@ def test_assert_each_passwd_by_name(users_and_groups):
def test_assert_each_passwd_by_uid(users_and_groups):
ent.assert_each_passwd_by_uid({})
- ent.assert_each_passwd_by_uid({1001:USER1})
+ ent.assert_each_passwd_by_uid({1001: USER1})
ent.assert_each_passwd_by_uid(USER_UID_DICT)
try:
- ent.assert_each_passwd_by_uid({1003:{}})
+ ent.assert_each_passwd_by_uid({1003: {}})
assert False
except AssertionError as e:
assert str(e) == "'getpwuid(): uid not found: 1003'"
try:
- ent.assert_each_passwd_by_uid({1001:dict(uid=1002)})
+ ent.assert_each_passwd_by_uid({1001: dict(uid=1002)})
assert False
except AssertionError as e:
assert str(e) == \
@@ -369,15 +369,15 @@ def test_assert_each_group_by_name(users_and_groups):
def test_assert_each_group_by_gid(users_and_groups):
ent.assert_each_group_by_gid({})
- ent.assert_each_group_by_gid({2001:GROUP1})
+ ent.assert_each_group_by_gid({2001: GROUP1})
ent.assert_each_group_by_gid(GROUP_GID_DICT)
try:
- ent.assert_each_group_by_gid({2003:{}})
+ ent.assert_each_group_by_gid({2003: {}})
assert False
except AssertionError as e:
assert str(e) == "'getgrgid(): gid not found: 2003'"
try:
- ent.assert_each_group_by_gid({2001:dict(gid=2002)})
+ ent.assert_each_group_by_gid({2001: dict(gid=2002)})
assert False
except AssertionError as e:
assert str(e) == \
diff --git a/src/tests/intg/ldap_test.py b/src/tests/intg/ldap_test.py
index 240ee5688..6a09b3725 100644
--- a/src/tests/intg/ldap_test.py
+++ b/src/tests/intg/ldap_test.py
@@ -32,7 +32,7 @@ import ds_openldap
import ldap_ent
from util import *
-LDAP_BASE_DN="dc=example,dc=com"
+LDAP_BASE_DN = "dc=example,dc=com"
@pytest.fixture(scope="module")
@@ -267,9 +267,12 @@ def test_regression_ticket2163(ldap_conn, simple_rfc2307):
def test_sanity_rfc2307(ldap_conn, sanity_rfc2307):
passwd_pattern = ent.contains_only(
- dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', dir='/home/user1', shell='/bin/bash'),
- dict(name='user2', passwd='*', uid=1002, gid=2002, gecos='1002', dir='/home/user2', shell='/bin/bash'),
- dict(name='user3', passwd='*', uid=1003, gid=2003, gecos='1003', dir='/home/user3', shell='/bin/bash')
+ dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001',
+ dir='/home/user1', shell='/bin/bash'),
+ dict(name='user2', passwd='*', uid=1002, gid=2002, gecos='1002',
+ dir='/home/user2', shell='/bin/bash'),
+ dict(name='user3', passwd='*', uid=1003, gid=2003, gecos='1003',
+ dir='/home/user3', shell='/bin/bash')
)
ent.assert_passwd(passwd_pattern)
@@ -277,8 +280,10 @@ def test_sanity_rfc2307(ldap_conn, sanity_rfc2307):
dict(name='group1', passwd='*', gid=2001, mem=ent.contains_only()),
dict(name='group2', passwd='*', gid=2002, mem=ent.contains_only()),
dict(name='group3', passwd='*', gid=2003, mem=ent.contains_only()),
- dict(name='empty_group', passwd='*', gid=2010, mem=ent.contains_only()),
- dict(name='two_user_group', passwd='*', gid=2012, mem=ent.contains_only("user1", "user2"))
+ dict(name='empty_group', passwd='*', gid=2010,
+ mem=ent.contains_only()),
+ dict(name='two_user_group', passwd='*', gid=2012,
+ mem=ent.contains_only("user1", "user2"))
)
ent.assert_group(group_pattern)
@@ -294,9 +299,12 @@ def test_sanity_rfc2307(ldap_conn, sanity_rfc2307):
def test_sanity_rfc2307_bis(ldap_conn, sanity_rfc2307_bis):
passwd_pattern = ent.contains_only(
- dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001', dir='/home/user1', shell='/bin/bash'),
- dict(name='user2', passwd='*', uid=1002, gid=2002, gecos='1002', dir='/home/user2', shell='/bin/bash'),
- dict(name='user3', passwd='*', uid=1003, gid=2003, gecos='1003', dir='/home/user3', shell='/bin/bash')
+ dict(name='user1', passwd='*', uid=1001, gid=2001, gecos='1001',
+ dir='/home/user1', shell='/bin/bash'),
+ dict(name='user2', passwd='*', uid=1002, gid=2002, gecos='1002',
+ dir='/home/user2', shell='/bin/bash'),
+ dict(name='user3', passwd='*', uid=1003, gid=2003, gecos='1003',
+ dir='/home/user3', shell='/bin/bash')
)
ent.assert_passwd(passwd_pattern)
@@ -304,16 +312,26 @@ def test_sanity_rfc2307_bis(ldap_conn, sanity_rfc2307_bis):
dict(name='group1', passwd='*', gid=2001, mem=ent.contains_only()),
dict(name='group2', passwd='*', gid=2002, mem=ent.contains_only()),
dict(name='group3', passwd='*', gid=2003, mem=ent.contains_only()),
- dict(name='empty_group1', passwd='*', gid=2010, mem=ent.contains_only()),
- dict(name='empty_group2', passwd='*', gid=2011, mem=ent.contains_only()),
- dict(name='two_user_group', passwd='*', gid=2012, mem=ent.contains_only("user1", "user2")),
- dict(name='group_empty_group', passwd='*', gid=2013, mem=ent.contains_only()),
- dict(name='group_two_empty_groups', passwd='*', gid=2014, mem=ent.contains_only()),
- dict(name='one_user_group1', passwd='*', gid=2015, mem=ent.contains_only("user1")),
- dict(name='one_user_group2', passwd='*', gid=2016, mem=ent.contains_only("user2")),
- dict(name='group_one_user_group', passwd='*', gid=2017, mem=ent.contains_only("user1")),
- dict(name='group_two_user_group', passwd='*', gid=2018, mem=ent.contains_only("user1", "user2")),
- dict(name='group_two_one_user_groups', passwd='*', gid=2019, mem=ent.contains_only("user1", "user2"))
+ dict(name='empty_group1', passwd='*', gid=2010,
+ mem=ent.contains_only()),
+ dict(name='empty_group2', passwd='*', gid=2011,
+ mem=ent.contains_only()),
+ dict(name='two_user_group', passwd='*', gid=2012,
+ mem=ent.contains_only("user1", "user2")),
+ dict(name='group_empty_group', passwd='*', gid=2013,
+ mem=ent.contains_only()),
+ dict(name='group_two_empty_groups', passwd='*', gid=2014,
+ mem=ent.contains_only()),
+ dict(name='one_user_group1', passwd='*', gid=2015,
+ mem=ent.contains_only("user1")),
+ dict(name='one_user_group2', passwd='*', gid=2016,
+ mem=ent.contains_only("user2")),
+ dict(name='group_one_user_group', passwd='*', gid=2017,
+ mem=ent.contains_only("user1")),
+ dict(name='group_two_user_group', passwd='*', gid=2018,
+ mem=ent.contains_only("user1", "user2")),
+ dict(name='group_two_one_user_groups', passwd='*', gid=2019,
+ mem=ent.contains_only("user1", "user2"))
)
ent.assert_group(group_pattern)
diff --git a/src/tests/intg/util.py b/src/tests/intg/util.py
index a5e01b3db..66ec0baa1 100644
--- a/src/tests/intg/util.py
+++ b/src/tests/intg/util.py
@@ -31,6 +31,7 @@ def unindent(text):
the first non-empty line from the beginning of every line.
"""
indent_ref = [0]
+
def replace(match):
if indent_ref[0] == 0:
indent_ref[0] = len(match.group())
@@ -58,7 +59,6 @@ def run_shell():
)
-
def first_dir(*args):
"""Return first argument that points to an existing directory."""
for arg in args: