From: Noel Power Date: Thu, 22 Mar 2018 12:46:55 +0000 (+0000) Subject: selftest python: get samba.tests.s3idmapdb to run with py3 X-Git-Url: http://git.samba.org/?p=metze%2Fsamba%2Fwip.git;a=commitdiff_plain;h=22d563b13eb122197bdf0b24937a78aec3b260af selftest python: get samba.tests.s3idmapdb to run with py3 Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index 323953857d50..a0bb76f68c1c 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -125,11 +125,11 @@ class Registry(DbDatabase): # High water mark keys -IDMAP_HWM_GROUP = "GROUP HWM\0" -IDMAP_HWM_USER = "USER HWM\0" +IDMAP_HWM_GROUP = b"GROUP HWM\0" +IDMAP_HWM_USER = b"USER HWM\0" -IDMAP_GROUP_PREFIX = "GID " -IDMAP_USER_PREFIX = "UID " +IDMAP_GROUP_PREFIX = b"GID " +IDMAP_USER_PREFIX = b"UID " # idmap version determines auto-conversion IDMAP_VERSION_V2 = 2 @@ -138,27 +138,27 @@ class IdmapDatabase(DbDatabase): """Samba 3 ID map database reader.""" def _check_version(self): - assert fetch_int32(self.db, "IDMAP_VERSION\0") == IDMAP_VERSION_V2 + assert fetch_int32(self.db, b"IDMAP_VERSION\0") == IDMAP_VERSION_V2 def ids(self): """Retrieve a list of all ids in this database.""" for k in self.db.iterkeys(): if k.startswith(IDMAP_USER_PREFIX): - yield k.rstrip("\0").split(" ") + yield k.rstrip(b"\0").split(b" ") if k.startswith(IDMAP_GROUP_PREFIX): - yield k.rstrip("\0").split(" ") + yield k.rstrip(b"\0").split(b" ") def uids(self): """Retrieve a list of all uids in this database.""" - for k in self.db.iterkeys(): + for k in self.db: if k.startswith(IDMAP_USER_PREFIX): - yield int(k[len(IDMAP_USER_PREFIX):].rstrip("\0")) + yield int(k[len(IDMAP_USER_PREFIX):].rstrip(b"\0")) def gids(self): """Retrieve a list of all gids in this database.""" - for k in self.db.iterkeys(): + for k in self.db: if k.startswith(IDMAP_GROUP_PREFIX): - yield int(k[len(IDMAP_GROUP_PREFIX):].rstrip("\0")) + yield int(k[len(IDMAP_GROUP_PREFIX):].rstrip(b"\0")) def get_sid(self, xid, id_type): """Retrive SID associated with a particular id and type. @@ -177,16 +177,16 @@ class IdmapDatabase(DbDatabase): :param uid: UID to retrieve SID for. :return: A SID or None if no mapping was found. """ - data = self.db.get("%s%d\0" % (IDMAP_USER_PREFIX, uid)) + data = self.db.get(b"%s%d\0" % (IDMAP_USER_PREFIX, uid)) if data is None: return data - return data.rstrip("\0") + return data.rstrip(b"\0") def get_group_sid(self, gid): - data = self.db.get("%s%d\0" % (IDMAP_GROUP_PREFIX, gid)) + data = self.db.get(b"%s%d\0" % (IDMAP_GROUP_PREFIX, gid)) if data is None: return data - return data.rstrip("\0") + return data.rstrip(b"\0") def get_user_hwm(self): """Obtain the user high-water mark.""" diff --git a/python/samba/tests/s3idmapdb.py b/python/samba/tests/s3idmapdb.py index aa2784041110..1f510f10bade 100644 --- a/python/samba/tests/s3idmapdb.py +++ b/python/samba/tests/s3idmapdb.py @@ -47,10 +47,10 @@ class IdmapDbTestCase(TestCase): self.assertEquals(3, len(list(self.idmapdb.gids()))) def test_get_user_sid(self): - self.assertEquals("S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) + self.assertEquals(b"S-1-5-21-58189338-3053988021-627566699-501", self.idmapdb.get_user_sid(65534)) def test_get_group_sid(self): - self.assertEquals("S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) + self.assertEquals(b"S-1-5-21-2447931902-1787058256-3961074038-3007", self.idmapdb.get_group_sid(10001)) def tearDown(self): self.idmapdb.close() diff --git a/selftest/tests.py b/selftest/tests.py index ea1e638f6f55..1dbbb0e5fc2f 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -79,7 +79,7 @@ planpythontestsuite("none", "samba.tests.s3param", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3passdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3registry", py3_compatible=True) planpythontestsuite("none", "samba.tests.s3windb", py3_compatible=True) -planpythontestsuite("none", "samba.tests.s3idmapdb") +planpythontestsuite("none", "samba.tests.s3idmapdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba3sam") planpythontestsuite( "none", "wafsamba.tests.test_suite",