def test_name_equality(self): node1 = Node(name='a') node2 = Node(name='a') other = Node(name='b') self.assertTrue(node1 == node2) self.assertFalse(node1 != node2) self.assertTrue(node1 != other) self.assertFalse(node1 == other) self.assertEqual(node1, node2) self.assertNotEqual(node1, other)
def test_setdefault(self): dn = 'cn=cn0,o=o' dn2 = 'cn=cn2,o=o' node = Node(name=dn, attrs=self.ENTRIES[dn], directory=self.dir) node2 = Node(name=dn2, attrs=self.ADDITIONAL[dn2], directory=self.dir) fail = 'cn=fail,o=o' self.assertEqual(node, self.dir.setdefault(dn)) self.assertEqual(node2, self.dir.setdefault(fail, node2)) # default has to be a Node self.assertRaises(AttributeError, lambda: self.dir.setdefault(fail)) self.assertRaises(AttributeError, lambda: self.dir.setdefault(fail, fail))
def test_popkeydefault(self): dn = 'cn=cn0,o=o' node = Node(name=dn, attrs=self.ENTRIES[dn]) fail = 'cn=fail,o=o' default = 'HubbaBubba' self.assertEqual(node, self.dir.pop(dn)) self.assertFalse(dn in self.dir) self.assertEqual(default, self.dir.pop(fail, default)) """ lambda turns lookup into a callable object. """ self.assertRaises(KeyError, lambda: self.dir.pop(fail))
def test_setitem(self): dn = 'cn=cn2,o=o' node = Node(name=dn, attrs=self.ADDITIONAL[dn], directory=self.dir) dn2 = 'cn=cn0,o=o' node2 = Node(name=dn2, attrs={ 'objectClass': ['applicationProcess'], 'cn': ['cn0'] }, directory=self.dir) def addnode(): self.dir[dn] = node def addexisting(): self.dir[dn2] = node2 addnode() self.assertEquals(node.name, self.dir[dn].name) addexisting() self.assertEquals(node2.name, self.dir[dn2].name)
def test_len(self): def delete(): del self.dir['cn=cn0,o=o'] dn1 = 'cn=cn0,o=o' node1 = Node(name=dn1, attrs=self.ENTRIES[dn1], directory=self.dir) def addnode1(): self.dir[dn1] = node1 dn2 = 'cn=cn2,o=o' node2 = Node(name=dn2, attrs=self.ADDITIONAL[dn2], directory=self.dir) def addnode2(): self.dir[dn2] = node2 self.assertEqual(len(self.ENTRIES), len(self.dir)) delete() self.assertTrue(len(self.ENTRIES) > len(self.dir)) addnode1() addnode2() self.assertTrue(len(self.ENTRIES) < len(self.dir))
def test_update(self): dn = 'cn=cn0,o=o' node = Node(name=dn, attrs={ 'objectClass': ['applicationProcess'], 'cn': ['cn0'] }, directory=self.dir) dn2 = 'cn=cn1,o=o' node2 = Node(name=dn2, attrs={ 'objectClass': ['organizationalRole'], 'cn': ['cn2'] }, directory=self.dir) itemList = [(node.name, node), (node2.name, node2)] dir2 = dict(itemList) self.assertEqual(None, self.dir.update(dir2)) self.assertEqual(node.name, self.dir[dn].name) self.assertEqual(None, self.dir.update(itemList)) self.assertEqual(node2.name, self.dir[dn2].name)
def test_attrs_equality(self): node1 = Node(name='name', attrs=(('a', '1'), ('b', '2'))) node2 = Node(name='name', attrs=(('a', '1'), ('b', '2'))) more = Node(name='name', attrs=(('a', '1'), ('b', '2'), ('c', '3'))) less = Node(name='name', attrs=(('a', '1'),)) other = Node(name='name', attrs=(('a', '2'), ('b', '1'))) order = Node(name='name', attrs=(('b', '2'), ('a', '1'))) self.assertEqual(node1, node2) self.assertNotEqual(node1, more) self.assertNotEqual(node1, less) self.assertNotEqual(node1, other) # (currently) ldap attributes are not ordered (see dicttree.ldap.Node) self.assertEqual(node1, order)
def test_attrs_order(self): attrlist = (('a', ['1']), ('b', ['2'])) node = Node(attrs=attrlist) self.assertEquals(attrlist, tuple(node.attrs.items()))
def test_repr(self): node = Node(name='a') self.assertEqual('<ldap node dn="a">', repr(node))