Example #1
0
 def testEquality_True_Set(self):
     """
     Attributes are equal when the have the same key and value.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     self.assertEqual(a, b)
Example #2
0
 def testEquality_True_Set(self):
     """
     Attributes are equal when the have the same key and value.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     self.assertEqual(a, b)
Example #3
0
 def testEquality_False_Key(self):
     """
     Equality fails if attributes have different keys.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('l', ['b', 'c', 'd'])
     self.assertNotEqual(a, b)
Example #4
0
 def testEquality_False_Key(self):
     """
     Equality fails if attributes have different keys.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = attributeset.LDAPAttributeSet("l", ["b", "c", "d"])
     self.assertNotEqual(a, b)
Example #5
0
 def testEquality_False_Value(self):
     """
     LDAPAttributeSet objects are not equal when they have
     different values.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = attributeset.LDAPAttributeSet("k", ["b", "c", "e"])
     self.assertNotEqual(a, b)
Example #6
0
 def testEquality_True_Set_Ordering(self):
     """
     The order of the element in the value doesn't matter for
     equality.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'd', 'c'])
     self.assertEqual(a, b)
Example #7
0
 def testEquality_False_Value(self):
     """
     LDAPAttributeSet objects are not equal when they have
     different values.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'e'])
     self.assertNotEqual(a, b)
Example #8
0
 def testEquality_True_Set_Ordering(self):
     """
     The order of the element in the value doesn't matter for
     equality.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = attributeset.LDAPAttributeSet("k", ["b", "d", "c"])
     self.assertEqual(a, b)
Example #9
0
    def testDifference(self):
        """
        Different operation will ignore the attribute's key and will
        perform the operation onlyb based on the attribute's value.
        """
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
        b = attributeset.LDAPAttributeSet('l', ['b', 'c', 'e'])

        result = a - b

        self.assertEqual({'d'}, result)
Example #10
0
    def testDifference(self):
        """
        Different operation will ignore the attribute's key and will
        perform the operation onlyb based on the attribute's value.
        """
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
        b = attributeset.LDAPAttributeSet("l", ["b", "c", "e"])

        result = a - b

        self.assertEqual({"d"}, result)
Example #11
0
    def testRemoveNonexistingValue(self):
        """
        Removing non-existing value
        """
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])

        self.assertRaises(KeyError, a.remove, "e")
Example #12
0
    def testRemoveNonexistingValue(self):
        """
        Removing non-existing value
        """
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])

        self.assertRaises(KeyError, a.remove, 'e')
Example #13
0
 def testEquality_True_List_Ordering(self):
     """
     For list comparison the order of the element don't matter.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = ['b', 'd', 'c']
     self.assertEqual(a, b)
Example #14
0
    def _load(self):
        assert self.path.endswith(u'.dir')
        entryPath = u'%s.ldif' % self.path[:-len(u'.dir')]

        parser = StoreParsedLDIF()

        try:
            f = open(entryPath, 'rb')
        except IOError as e:
            if e.errno == errno.ENOENT:
                return
            else:
                raise
        while 1:
            data = f.read(8192)
            if not data:
                break
            parser.dataReceived(data)
        parser.connectionLost(failure.Failure(error.ConnectionDone()))
        assert parser.done

        entries = parser.seen
        if len(entries) == 0:
            raise LDIFTreeEntryContainsNoEntries()
        elif len(entries) > 1:
            raise LDIFTreeEntryContainsMultipleEntries(entries)
        else:
            for k, v in entries[0].items():
                self._attributes[k] = attributeset.LDAPAttributeSet(k, v)
Example #15
0
 def testEquality_True_List_Ordering(self):
     """
     For list comparison the order of the element don't matter.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = ["b", "d", "c"]
     self.assertEqual(a, b)
Example #16
0
    def testDeepCopy(self):
        class Magic:
            def __eq__(self, other):
                return isinstance(other, self.__class__)

            def __hash__(self):
                return 42

            def __lt__(self, other):
                return False

            def __gt__(self, other):
                return True

        m1 = Magic()
        a = attributeset.LDAPAttributeSet('k', ['a', m1])
        b = a.__deepcopy__({})
        self.assertEqual(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEqual(magicFromA, magicFromB)
        self.assertNotIdentical(magicFromA, magicFromB)

        a.update('x')
        self.assertEqual(a, {'a', m1, 'x'})
        self.assertEqual(b, {'a', m1})
Example #17
0
    def testDeepCopy(self):
        @total_ordering
        class Magic:
            def __eq__(self, other):
                return isinstance(other, self.__class__)

            def __hash__(self):
                return 42

            def __lt__(self, other):
                return False

        m1 = Magic()
        a = attributeset.LDAPAttributeSet("k", ["a", m1])
        b = a.__deepcopy__({})
        self.assertEqual(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEqual(magicFromA, magicFromB)
        self.assertNotIdentical(magicFromA, magicFromB)

        a.update("x")
        self.assertEqual(a, {"a", m1, "x"})
        self.assertEqual(b, {"a", m1})
Example #18
0
 def testEquality_True_List(self):
     """
     It can be compared with a list and in this case the key is
     ignored.
     """
     a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
     b = ["b", "c", "d"]
     self.assertEqual(a, b)
Example #19
0
    def testAddNewValue(self):
        """
        Adding new value
        """
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
        a.add("e")

        self.assertEqual(a, {"b", "c", "d", "e"})
Example #20
0
    def testAddNewValue(self):
        """
        Adding new value
        """
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
        a.add('e')

        self.assertEqual(a, {'b', 'c', 'd', 'e'})
Example #21
0
 def testEquality_True_List(self):
     """
     It can be compared with a list and in this case the key is
     ignored.
     """
     a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     b = ['b', 'c', 'd']
     self.assertEqual(a, b)
Example #22
0
    def testRemoveExistingValue(self):
        """
        Removing existing value as a byte or unicode string
        """
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])
        a.remove(b"b")
        a.remove("c")

        self.assertEqual(a, {"d"})
Example #23
0
    def testRemoveExistingValue(self):
        """
        Removing existing value as a byte or unicode string
        """
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
        a.remove(b'b')
        a.remove(u'c')

        self.assertEqual(a, {'d'})
Example #24
0
    def testAddExistingValue(self):
        """
        Adding existing value as a byte or unicode string
        """
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])

        a.add(b'b')
        self.assertEqual(a, {'b', 'c', 'd'})

        a.add(u'b')
        self.assertEqual(a, {'b', 'c', 'd'})
Example #25
0
    def testAddExistingValue(self):
        """
        Adding existing value as a byte or unicode string
        """
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d"])

        a.add(b"b")
        self.assertEqual(a, {"b", "c", "d"})

        a.add("b")
        self.assertEqual(a, {"b", "c", "d"})
Example #26
0
class LDIFTreeEntry(
        entry.EditableLDAPEntry,
        entryhelpers.DiffTreeMixin,
        entryhelpers.SubtreeFromChildrenMixin,
        entryhelpers.MatchMixin,
        entryhelpers.SearchByTreeWalkingMixin,
):
    implements(interfaces.IConnectedLDAPEntry)

    def __init__(self, path, dn=None, *a, **kw):
        if dn is None:
            dn = ''
        entry.BaseLDAPEntry.__init__(self, dn, *a, **kw)
        self.path = path
        if dn != '':  #TODO DistinguishedName.__nonzero__
            self._load()

    def _load(self):
        assert self.path.endswith('.dir')
        entryPath = '%s.ldif' % self.path[:-len('.dir')]

        parser = StoreParsedLDIF()

        try:
            f = file(entryPath)
        except IOError, e:
            if e.errno == errno.ENOENT:
                return
            else:
                raise
        while 1:
            data = f.read(8192)
            if not data:
                break
            parser.dataReceived(data)
        parser.connectionLost(failure.Failure(error.ConnectionDone))
        assert parser.done

        entries = parser.seen
        if len(entries) == 0:
            raise LDIFTreeEntryContainsNoEntries
        elif len(entries) > 1:
            raise LDIFTreeEntryContainsMultipleEntries, entries
        else:
            # TODO ugliness and all of its friends
            for k, v in entries[0].items():
                self._attributes[k] = attributeset.LDAPAttributeSet(k, v)
Example #27
0
    def testCopy(self):
        class Magic:
            pass

        m1 = Magic()
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd', m1])
        b = a.__copy__()
        self.assertEquals(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEquals(magicFromA, magicFromB)
        self.assertIdentical(magicFromA, magicFromB)

        a.update('x')
        self.assertEquals(a, sets.Set(['b', 'c', 'd', m1, 'x']))
        self.assertEquals(b, sets.Set(['b', 'c', 'd', m1]))
Example #28
0
    def testCopy(self):
        class Magic:
            def __lt__(self, other):
                return False

            def __gt__(self, other):
                return True

        m1 = Magic()
        a = attributeset.LDAPAttributeSet("k", ["b", "c", "d", m1])
        b = a.__copy__()
        self.assertEqual(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEqual(magicFromA, magicFromB)
        self.assertIdentical(magicFromA, magicFromB)

        a.update("x")
        self.assertEqual(a, {"b", "c", "d", m1, "x"})
        self.assertEqual(b, {"b", "c", "d", m1})
Example #29
0
    def testCopy(self):
        class Magic:
            def __lt__(self, other):
                return False

            def __gt__(self, other):
                return True

        m1 = Magic()
        a = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd', m1])
        b = a.__copy__()
        self.assertEqual(a, b)
        self.assertNotIdentical(a, b)

        magicFromA = [val for val in a if isinstance(val, Magic)][0]
        magicFromB = [val for val in b if isinstance(val, Magic)][0]
        self.assertEqual(magicFromA, magicFromB)
        self.assertIdentical(magicFromA, magicFromB)

        a.update('x')
        self.assertEqual(a, {'b', 'c', 'd', m1, 'x'})
        self.assertEqual(b, {'b', 'c', 'd', m1})
Example #30
0
 def testEquality_AttributeSet_False(self):
     a = delta.Add('k', ['b', 'c', 'd'])
     b = attributeset.LDAPAttributeSet('k', ['b', 'c', 'd'])
     self.assertNotEquals(a, b)