Update deprecated statements in tests

master
Miro Hrončok 7 years ago
parent 851474b004
commit d8de865630
  1. 150
      Tests/t_ldapurl.py

@ -24,7 +24,7 @@ def sort(l):
class TestLDAPUrl(unittest.TestCase):
def assertNone(self, expr, msg=None):
self.failIf(expr is not None, msg or ("%r" % expr))
self.assertFalse(expr is not None, msg or ("%r" % expr))
def test_combo(self):
u = MyLDAPUrl("ldap://127.0.0.1:1234/dc=example,dc=com"
@ -35,29 +35,29 @@ class TestLDAPUrl(unittest.TestCase):
+ ",X-BINDPW=" + quote("???")
+ ",trace=8"
)
self.assertEquals(u.urlscheme, "ldap")
self.assertEquals(u.hostport, "127.0.0.1:1234")
self.assertEquals(u.dn, "dc=example,dc=com")
self.assertEquals(u.attrs, ["attr1","attr2","attr3"])
self.assertEquals(u.scope, ldap.SCOPE_SUBTREE)
self.assertEquals(u.filterstr, "(objectClass=*)")
self.assertEquals(len(u.extensions), 3)
self.assertEquals(u.who, "cn=d,c=au")
self.assertEquals(u.cred, "???")
self.assertEquals(u.trace_level, "8")
self.assertEqual(u.urlscheme, "ldap")
self.assertEqual(u.hostport, "127.0.0.1:1234")
self.assertEqual(u.dn, "dc=example,dc=com")
self.assertEqual(u.attrs, ["attr1","attr2","attr3"])
self.assertEqual(u.scope, ldap.SCOPE_SUBTREE)
self.assertEqual(u.filterstr, "(objectClass=*)")
self.assertEqual(len(u.extensions), 3)
self.assertEqual(u.who, "cn=d,c=au")
self.assertEqual(u.cred, "???")
self.assertEqual(u.trace_level, "8")
def test_parse_default_hostport(self):
u = LDAPUrl("ldap://")
self.assertEquals(u.urlscheme, "ldap")
self.assertEquals(u.hostport, "")
self.assertEqual(u.urlscheme, "ldap")
self.assertEqual(u.hostport, "")
def test_parse_empty_dn(self):
u = LDAPUrl("ldap://")
self.assertEquals(u.dn, "")
self.assertEqual(u.dn, "")
u = LDAPUrl("ldap:///")
self.assertEquals(u.dn, "")
self.assertEqual(u.dn, "")
u = LDAPUrl("ldap:///?")
self.assertEquals(u.dn, "")
self.assertEqual(u.dn, "")
def test_parse_default_attrs(self):
u = LDAPUrl("ldap://")
@ -73,71 +73,71 @@ class TestLDAPUrl(unittest.TestCase):
def test_parse_default_extensions(self):
u = LDAPUrl("ldap://")
self.assertEquals(len(u.extensions), 0)
self.assertEqual(len(u.extensions), 0)
def test_parse_schemes(self):
u = LDAPUrl("ldap://")
self.assertEquals(u.urlscheme, "ldap")
self.assertEqual(u.urlscheme, "ldap")
u = LDAPUrl("ldapi://")
self.assertEquals(u.urlscheme, "ldapi")
self.assertEqual(u.urlscheme, "ldapi")
u = LDAPUrl("ldaps://")
self.assertEquals(u.urlscheme, "ldaps")
self.assertEqual(u.urlscheme, "ldaps")
def test_parse_hostport(self):
u = LDAPUrl("ldap://a")
self.assertEquals(u.hostport, "a")
self.assertEqual(u.hostport, "a")
u = LDAPUrl("ldap://a.b")
self.assertEquals(u.hostport, "a.b")
self.assertEqual(u.hostport, "a.b")
u = LDAPUrl("ldap://a.")
self.assertEquals(u.hostport, "a.")
self.assertEqual(u.hostport, "a.")
u = LDAPUrl("ldap://%61%62:%32/")
self.assertEquals(u.hostport, "ab:2")
self.assertEqual(u.hostport, "ab:2")
u = LDAPUrl("ldap://[::1]/")
self.assertEquals(u.hostport, "[::1]")
self.assertEqual(u.hostport, "[::1]")
u = LDAPUrl("ldap://[::1]")
self.assertEquals(u.hostport, "[::1]")
self.assertEqual(u.hostport, "[::1]")
u = LDAPUrl("ldap://[::1]:123/")
self.assertEquals(u.hostport, "[::1]:123")
self.assertEqual(u.hostport, "[::1]:123")
u = LDAPUrl("ldap://[::1]:123")
self.assertEquals(u.hostport, "[::1]:123")
self.assertEqual(u.hostport, "[::1]:123")
def test_parse_dn(self):
u = LDAPUrl("ldap:///")
self.assertEquals(u.dn, "")
self.assertEqual(u.dn, "")
u = LDAPUrl("ldap:///dn=foo")
self.assertEquals(u.dn, "dn=foo")
self.assertEqual(u.dn, "dn=foo")
u = LDAPUrl("ldap:///dn=foo%2cdc=bar")
self.assertEquals(u.dn, "dn=foo,dc=bar")
self.assertEqual(u.dn, "dn=foo,dc=bar")
u = LDAPUrl("ldap:///dn=foo%20bar")
self.assertEquals(u.dn, "dn=foo bar")
self.assertEqual(u.dn, "dn=foo bar")
u = LDAPUrl("ldap:///dn=foo%2fbar")
self.assertEquals(u.dn, "dn=foo/bar")
self.assertEqual(u.dn, "dn=foo/bar")
u = LDAPUrl("ldap:///dn=foo%2fbar?")
self.assertEquals(u.dn, "dn=foo/bar")
self.assertEqual(u.dn, "dn=foo/bar")
u = LDAPUrl("ldap:///dn=foo%3f?")
self.assertEquals(u.dn, "dn=foo?")
self.assertEqual(u.dn, "dn=foo?")
u = LDAPUrl("ldap:///dn=foo%3f")
self.assertEquals(u.dn, "dn=foo?")
self.assertEqual(u.dn, "dn=foo?")
u = LDAPUrl("ldap:///dn=str%c3%b6der.com")
self.assertEquals(u.dn, "dn=str\xf6der.com")
self.assertEqual(u.dn, "dn=str\xf6der.com")
def test_parse_attrs(self):
u = LDAPUrl("ldap:///?")
self.assertEquals(u.attrs, None)
self.assertEqual(u.attrs, None)
u = LDAPUrl("ldap:///??")
self.assertEquals(u.attrs, None)
self.assertEqual(u.attrs, None)
u = LDAPUrl("ldap:///?*?")
self.assertEquals(u.attrs, ['*'])
self.assertEqual(u.attrs, ['*'])
u = LDAPUrl("ldap:///?*,*?")
self.assertEquals(u.attrs, ['*','*'])
self.assertEqual(u.attrs, ['*','*'])
u = LDAPUrl("ldap:///?a")
self.assertEquals(u.attrs, ['a'])
self.assertEqual(u.attrs, ['a'])
u = LDAPUrl("ldap:///?%61")
self.assertEquals(u.attrs, ['a'])
self.assertEqual(u.attrs, ['a'])
u = LDAPUrl("ldap:///?a,b")
self.assertEquals(u.attrs, ['a','b'])
self.assertEqual(u.attrs, ['a','b'])
u = LDAPUrl("ldap:///?a%3fb")
self.assertEquals(u.attrs, ['a?b'])
self.assertEqual(u.attrs, ['a?b'])
def test_parse_scope_default(self):
u = LDAPUrl("ldap:///??")
@ -147,73 +147,73 @@ class TestLDAPUrl(unittest.TestCase):
def test_parse_scope(self):
u = LDAPUrl("ldap:///??sub")
self.assertEquals(u.scope, ldap.SCOPE_SUBTREE)
self.assertEqual(u.scope, ldap.SCOPE_SUBTREE)
u = LDAPUrl("ldap:///??sub?")
self.assertEquals(u.scope, ldap.SCOPE_SUBTREE)
self.assertEqual(u.scope, ldap.SCOPE_SUBTREE)
u = LDAPUrl("ldap:///??base")
self.assertEquals(u.scope, ldap.SCOPE_BASE)
self.assertEqual(u.scope, ldap.SCOPE_BASE)
u = LDAPUrl("ldap:///??base?")
self.assertEquals(u.scope, ldap.SCOPE_BASE)
self.assertEqual(u.scope, ldap.SCOPE_BASE)
u = LDAPUrl("ldap:///??one")
self.assertEquals(u.scope, ldap.SCOPE_ONELEVEL)
self.assertEqual(u.scope, ldap.SCOPE_ONELEVEL)
u = LDAPUrl("ldap:///??one?")
self.assertEquals(u.scope, ldap.SCOPE_ONELEVEL)
self.assertEqual(u.scope, ldap.SCOPE_ONELEVEL)
def test_parse_filter(self):
u = LDAPUrl("ldap:///???(cn=Bob)")
self.assertEquals(u.filterstr, "(cn=Bob)")
self.assertEqual(u.filterstr, "(cn=Bob)")
u = LDAPUrl("ldap:///???(cn=Bob)?")
self.assertEquals(u.filterstr, "(cn=Bob)")
self.assertEqual(u.filterstr, "(cn=Bob)")
u = LDAPUrl("ldap:///???(cn=Bob%20Smith)?")
self.assertEquals(u.filterstr, "(cn=Bob Smith)")
self.assertEqual(u.filterstr, "(cn=Bob Smith)")
u = LDAPUrl("ldap:///???(cn=Bob/Smith)?")
self.assertEquals(u.filterstr, "(cn=Bob/Smith)")
self.assertEqual(u.filterstr, "(cn=Bob/Smith)")
u = LDAPUrl("ldap:///???(cn=Bob:Smith)?")
self.assertEquals(u.filterstr, "(cn=Bob:Smith)")
self.assertEqual(u.filterstr, "(cn=Bob:Smith)")
u = LDAPUrl("ldap:///???&(cn=Bob)(objectClass=user)?")
self.assertEquals(u.filterstr, "&(cn=Bob)(objectClass=user)")
self.assertEqual(u.filterstr, "&(cn=Bob)(objectClass=user)")
u = LDAPUrl("ldap:///???|(cn=Bob)(objectClass=user)?")
self.assertEquals(u.filterstr, "|(cn=Bob)(objectClass=user)")
self.assertEqual(u.filterstr, "|(cn=Bob)(objectClass=user)")
u = LDAPUrl("ldap:///???(cn=Q%3f)?")
self.assertEquals(u.filterstr, "(cn=Q?)")
self.assertEqual(u.filterstr, "(cn=Q?)")
u = LDAPUrl("ldap:///???(cn=Q%3f)")
self.assertEquals(u.filterstr, "(cn=Q?)")
self.assertEqual(u.filterstr, "(cn=Q?)")
u = LDAPUrl("ldap:///???(sn=Str%c3%b6der)") # (possibly bad?)
self.assertEquals(u.filterstr, "(sn=Str\xf6der)")
self.assertEqual(u.filterstr, "(sn=Str\xf6der)")
u = LDAPUrl("ldap:///???(sn=Str\\c3\\b6der)")
self.assertEquals(u.filterstr, "(sn=Str\\c3\\b6der)") # (recommended)
self.assertEqual(u.filterstr, "(sn=Str\\c3\\b6der)") # (recommended)
u = LDAPUrl("ldap:///???(cn=*\\2a*)")
self.assertEquals(u.filterstr, "(cn=*\\2a*)")
self.assertEqual(u.filterstr, "(cn=*\\2a*)")
u = LDAPUrl("ldap:///???(cn=*%5c2a*)")
self.assertEquals(u.filterstr, "(cn=*\\2a*)")
self.assertEqual(u.filterstr, "(cn=*\\2a*)")
def test_parse_extensions(self):
u = LDAPUrl("ldap:///????")
self.assertNone(u.extensions)
self.assertNone(u.who)
u = LDAPUrl("ldap:///????bindname=cn=root")
self.assertEquals(len(u.extensions), 1)
self.assertEquals(u.who, "cn=root")
self.assertEqual(len(u.extensions), 1)
self.assertEqual(u.who, "cn=root")
u = LDAPUrl("ldap:///????!bindname=cn=root")
self.assertEquals(len(u.extensions), 1)
self.assertEquals(u.who, "cn=root")
self.assertEqual(len(u.extensions), 1)
self.assertEqual(u.who, "cn=root")
u = LDAPUrl("ldap:///????bindname=%3f,X-BINDPW=%2c")
self.assertEquals(len(u.extensions), 2)
self.assertEquals(u.who, "?")
self.assertEquals(u.cred, ",")
self.assertEqual(len(u.extensions), 2)
self.assertEqual(u.who, "?")
self.assertEqual(u.cred, ",")
def test_parse_extensions_nulls(self):
u = LDAPUrl("ldap:///????bindname=%00name")
self.assertEquals(u.who, "\0name")
self.assertEqual(u.who, "\0name")
def test_parse_extensions_5questions(self):
u = LDAPUrl("ldap:///????bindname=?")
self.assertEquals(len(u.extensions), 1)
self.assertEquals(u.who, "?")
self.assertEqual(len(u.extensions), 1)
self.assertEqual(u.who, "?")
def test_parse_extensions_novalue(self):
u = LDAPUrl("ldap:///????bindname")
self.assertEquals(len(u.extensions), 1)
self.assertEqual(len(u.extensions), 1)
self.assertNone(u.who)
@unittest.expectedFailure

Loading…
Cancel
Save