コード例 #1
0
 def testComplex(self):
     a = entry.BaseLDAPEntry(
         dn='cn=Paula Jensen,ou=Product Development,dc=airius,dc=com',
         attributes={
             'description': ['Something'],
             'telephonenumber': ['+123 456'],
             'facsimiletelephonenumber': ['+1 408 555 9876'],
         })
     b = entry.BaseLDAPEntry(
         dn='cn=Paula Jensen,ou=Product Development,dc=airius,dc=com',
         attributes={
             'postalAddress': ['123 Anystreet $ Sunnyvale, CA $ 94086'],
             'telephonenumber': ['+1 408 555 1234', '+1 408 555 5678'],
         })
     result = a.diff(b)
     self.assertEquals(
         result,
         delta.ModifyOp(
             'cn=Paula Jensen,ou=Product Development,dc=airius,dc=com', [
                 delta.Add('postalAddress',
                           ['123 Anystreet $ Sunnyvale, CA $ 94086']),
                 delta.Delete('description', ['Something']),
                 delta.Delete('facsimiletelephonenumber',
                              ['+1 408 555 9876']),
                 delta.Add('telephonenumber',
                           ['+1 408 555 1234', '+1 408 555 5678']),
                 delta.Delete('telephonenumber', ['+123 456']),
             ]))
コード例 #2
0
 def testEqual(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     result = a.diff(b)
     self.assertEquals(result, None)
コード例 #3
0
 def testAdd_Existing_OneType_OneValue(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar', 'quux'],
                             })
     result = a.diff(b)
     self.assertEquals(
         result, delta.ModifyOp('dc=foo', [
             delta.Add('foo', ['quux']),
         ]))
コード例 #4
0
 def testAdd_New_OneType_ManyValues(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux', 'thud', 'foo'],
                             })
     result = a.diff(b)
     self.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('baz', ['quux', 'thud', 'foo']),
         ]))
コード例 #5
0
 def testDelete_All_OneType(self):
     a = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux', 'thud'],
                             })
     b = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     result = a.diff(b)
     self.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Delete('baz', ['quux', 'thud']),
         ]))
コード例 #6
0
ファイル: test_delta.py プロジェクト: mpice-mn/python-opsi
 def testAddOp_DNExists(self):
     foo2 = entry.BaseLDAPEntry(
         dn='cn=foo,ou=metasyntactic,dc=example,dc=com',
         attributes={'foo': ['bar', 'baz'],
                     'quux': ['thud']})
     op = delta.AddOp(foo2)
     d = op.patch(self.root)
     def eb(fail):
         fail.trap(ldaperrors.LDAPEntryAlreadyExists)
     d.addCallbacks(testutil.mustRaise, eb)
     return d
コード例 #7
0
 def testAdd_NewAndExisting_ManyTypes(self):
     a = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux'],
                             })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar', 'thud', 'bang'],
                                 'baz': ['quux', 'bar', 'stump'],
                                 'bang': ['thud', 'barble'],
                             })
     result = a.diff(b)
     self.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('bang', ['thud', 'barble']),
             delta.Add('baz', ['bar', 'stump']),
             delta.Add('foo', ['thud', 'bang']),
         ]))
コード例 #8
0
ファイル: test_delta.py プロジェクト: mpice-mn/python-opsi
    def testSimple(self):
        op=delta.AddOp(entry.BaseLDAPEntry(
            dn='dc=example,dc=com',
            attributes={'foo': ['bar', 'baz'],
                        'quux': ['thud']}))
        self.assertEquals(op.asLDIF(),
                          """\
dn: dc=example,dc=com
changetype: add
foo: bar
foo: baz
quux: thud

""")
コード例 #9
0
    def testAdd(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: add
foo: bar
thud: quux
thud: baz

""")
        proto.connectionLost()
        self.assertEqual(proto.listOfCompleted,
                         [delta.AddOp(entry.BaseLDAPEntry(
            dn='cn=foo,dc=example,dc=com',
            attributes={
            'foo': ['bar'],
            'thud': ['quux', 'baz'],
            }))])
コード例 #10
0
    def test_diffTree_addChild(self):
        otherDir = self.mktemp()
        shutil.copytree(self.tree, otherDir)
        other = ldiftree.LDIFTreeEntry(otherDir)
        e = entry.BaseLDAPEntry(dn='cn=foo,dc=example,dc=com')
        d = ldiftree.put(otherDir, e)

        def cb1(dummy):
            return other.lookup('cn=foo,dc=example,dc=com')

        d.addCallback(cb1)

        def cb2(r):
            d = self.root.diffTree(other)
            d.addCallback(self.assertEquals, [delta.AddOp(r)])
            return d

        d.addCallback(cb2)
        return d
コード例 #11
0
    def _addChild(self, rdn, attributes):
        rdn = distinguishedname.RelativeDistinguishedName(rdn)
        for c in self._sync_children():
            if c.dn.split()[0] == rdn:
                raise ldaperrors.LDAPEntryAlreadyExists, c.dn

        dn = distinguishedname.DistinguishedName(listOfRDNs=(rdn, ) +
                                                 self.dn.split())
        e = entry.BaseLDAPEntry(dn, attributes)
        if not os.path.exists(self.path):
            os.mkdir(self.path)
        fileName = os.path.join(self.path, '%s' % rdn)
        tmp = fileName + '.' + tempName() + '.tmp'
        f = file(tmp, 'w')
        f.write(str(e))
        f.close()
        os.rename(tmp, fileName + '.ldif')
        # TODO atomicity

        dirName = os.path.join(self.path, '%s.dir' % rdn)

        e = self.__class__(dirName, dn)
        return e
コード例 #12
0
    def state_IN_ADD_ENTRY(self, line):
        assert self.dn is not None, 'self.dn must be set when in entry'
        assert self.data is not None, 'self.data must be set when in entry'

        if line == '':
            # end of entry
            if not self.data:
                raise LDIFDeltaAddMissingAttributesError, \
                      self.dn
            self.mode = ldifprotocol.WAIT_FOR_DN
            o = delta.AddOp(
                entry.BaseLDAPEntry(dn=self.dn, attributes=self.data))
            self.dn = None
            self.data = None
            self.gotEntry(o)
            return

        key, val = self._parseLine(line)

        if not key in self.data:
            self.data[key] = []

        self.data[key].append(val)