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.assertEqual( 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']), ]))
def testInequalityDifferentDN(self): """ Entries are not equal if their DNs are not equal """ a = entry.BaseLDAPEntry(dn='dn=foo', attributes={'foo': ['bar']}) b = entry.BaseLDAPEntry(dn='dn=bar', attributes={'foo': ['bar']}) self.assertNotEqual(a, b)
def testInequalityDifferentDN(self): """ Entries are not equal if their DNs are not equal """ a = entry.BaseLDAPEntry(dn="dn=foo", attributes={"foo": ["bar"]}) b = entry.BaseLDAPEntry(dn="dn=bar", attributes={"foo": ["bar"]}) self.assertNotEqual(a, b)
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.assertEqual( 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"]), ], ), )
def testDelete_Some_OneType(self): a = entry.BaseLDAPEntry( dn="dc=foo", attributes={ "foo": ["bar"], "baz": ["quux", "thud"], }, ) b = entry.BaseLDAPEntry( dn="dc=foo", attributes={ "foo": ["bar"], "baz": ["thud"], }, ) result = a.diff(b) self.assertEqual( result, delta.ModifyOp( "dc=foo", [ delta.Delete("baz", ["quux"]), ], ), )
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.assertEqual( result, delta.ModifyOp( "dc=foo", [ delta.Add("bang", ["thud", "barble"]), delta.Add("baz", ["bar", "stump"]), delta.Add("foo", ["thud", "bang"]), ], ), )
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.assertEqual(result, None)
def testDeleteOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertEqual(hash(first), hash(second))
def testDeleteOpEqualitySameDN(self): """ Objects are equal when the have the same DN. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertEqual(first, second)
def testDeleteOpInequalityDifferentEntry(self): """ DeleteOp objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertNotEqual(first, second)
def testDeleteOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com') first = delta.DeleteOp(first_entry) second = delta.DeleteOp(second_entry) self.assertNotEqual(hash(first), hash(second))
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.assertEqual( result, delta.ModifyOp('dc=foo', [ delta.Add('foo', ['quux']), ]))
def testEqualitySameType(self): """ It is equal if it has the same DN (case insensitive) and same attributes and values. """ a = entry.BaseLDAPEntry(dn='dc=foo', attributes={ 'foo': ['bar'], }) b = entry.BaseLDAPEntry(dn='Dc=Foo', attributes={ 'foo': ['bar'], }) self.assertEqual(a, b)
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.assertEqual(result, None)
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.assertEqual( result, delta.ModifyOp('dc=foo', [ delta.Delete('baz', ['quux', 'thud']), ]))
def testAddOpInequalityDifferentEntry(self): """ Objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry( dn='ou=First Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=First Team, dc=example,dc=com', attributes={'foo': ['other', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(first, second)
def testAddOpEqualitySameEntry(self): """ Objects are equal when the have the same LDAP entry. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(first, second)
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.assertEqual( result, delta.ModifyOp('dc=foo', [ delta.Add('baz', ['quux', 'thud', 'foo']), ]))
def testAddOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['one', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['other', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(hash(first), hash(second))
def testAddOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) second_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(hash(first), hash(second))
def testAdd(self): proto = LDIFDeltaDriver() proto.dataReceived(b"""\ 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=b"cn=foo,dc=example,dc=com", attributes={ b"foo": [b"bar"], b"thud": [b"quux", b"baz"], }, )) ], )
def testAsLDIF(self): """ It will return the LDIF representation of the operation. """ sut = delta.AddOp( entry.BaseLDAPEntry( dn="dc=example,dc=com", attributes={ "foo": ["bar", "baz"], "quux": ["thud"], }, )) result = sut.asLDIF() self.assertEqual( b"""dn: dc=example,dc=com changetype: add foo: bar foo: baz quux: thud """, result, )
def testAddOpEqualitySameEntry(self): """ Objects are equal when the have the same LDAP entry. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(first, second)
def testAddOpInequalityDifferentEntry(self): """ Objects are not equal when the have different LDAP entries. """ first_entry = entry.BaseLDAPEntry( dn="ou=First Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=First Team, dc=example,dc=com", attributes={"foo": ["other", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(first, second)
def testAddOpHashSimilar(self): """ Objects which are equal have the same hash. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["same", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertEqual(hash(first), hash(second))
def testAddOpHashDifferent(self): """ Objects which are not equal have different hash. """ first_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["one", "attributes"]}, ) second_entry = entry.BaseLDAPEntry( dn="ou=Duplicate Team, dc=example,dc=com", attributes={"foo": ["other", "attributes"]}, ) first = delta.AddOp(first_entry) second = delta.AddOp(second_entry) self.assertNotEqual(hash(first), hash(second))
def testDeleteOpInequalityNoEntryObject(self): """ DeleteOp objects is not equal with random objects. """ team_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com') sut = delta.DeleteOp(team_entry) self.assertNotEqual(sut, 'ou=Team, dc=example,dc=com')
def testEqualitySameType(self): """ It is equal if it has the same DN (case insensitive) and same attributes and values. """ a = entry.BaseLDAPEntry( dn="dc=foo", attributes={ "foo": ["bar"], }, ) b = entry.BaseLDAPEntry( dn="Dc=Foo", attributes={ "foo": ["bar"], }, ) self.assertEqual(a, b)
def testGetLDIF(self): """ Getting human readable representation of an entry """ sut = entry.BaseLDAPEntry(dn='dc=foo', attributes={ 'foo': ['bar'], 'bar': ['foo'], }) self.assertEqual(sut.getLDIF(), u'dn: dc=foo\nbar: foo\nfoo: bar\n\n')
def testAddOpInequalityNoEntryObject(self): """ Objects is not equal with random objects. """ team_entry = entry.BaseLDAPEntry( dn='ou=Duplicate Team, dc=example,dc=com', attributes={'foo': ['same', 'attributes']}) sut = delta.AddOp(team_entry) self.assertNotEqual(sut, {'foo': ['same', 'attributes']})