Beispiel #1
0
def dump_tree_sorted(ldap_server, base_domain, out_fil):
    diff_writer = SortedLdifWriter(LDIFWriter(out_fil))
    try:
        for dn, attrs in ldap_server.search_s(base_domain, ldap.SCOPE_SUBTREE):
            diff_writer.unparse(dn, attrs)
    except ldap.NO_SUCH_OBJECT:
        # if the ldap tree is empty, this will get thrown, in which
        # case we want an empty ldif, so...good!
        pass

    diff_writer.commit()
def test_writes_sorted_by_len_then_dn_to_underlying_ldif_on_commit():
    mock_ldif_writer = MockLdifWriter()
    sldif = SortedLdifWriter(mock_ldif_writer)
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn="hi", attrs=dict(hi="here"))
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn="cat", attrs=dict(hi="dog"))
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn="bye", attrs=dict(hi="there"))
    eq_([], mock_ldif_writer.called_with)
    sldif.commit()
    eq_([("hi", dict(hi="here")), ("bye", dict(hi="there")), ("cat", dict(hi="dog"))], mock_ldif_writer.called_with)
Beispiel #3
0
def test_writes_sorted_by_len_then_dn_to_underlying_ldif_on_commit():
    mock_ldif_writer = MockLdifWriter()
    sldif = SortedLdifWriter(mock_ldif_writer)
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn='hi', attrs=dict(hi='here'))
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn='cat', attrs=dict(hi='dog'))
    eq_([], mock_ldif_writer.called_with)
    sldif.unparse(dn='bye', attrs=dict(hi='there'))
    eq_([], mock_ldif_writer.called_with)
    sldif.commit()
    eq_([('hi', dict(hi='here')),
         ('bye', dict(hi='there')),
         ('cat', dict(hi='dog'))],
          mock_ldif_writer.called_with)
Beispiel #4
0
def test_barfs_on_double_commit():
    sldif = SortedLdifWriter(MockLdifWriter())
    sldif.commit()
    sldif.commit()
Beispiel #5
0
def test_barfs_on_unparse_post_commit():
    sldif = SortedLdifWriter(MockLdifWriter())
    sldif.commit()
    sldif.unparse(dn='hi', attrs=dict(hi='there'))
def test_barfs_on_double_commit():
    sldif = SortedLdifWriter(MockLdifWriter())
    sldif.commit()
    sldif.commit()
def test_barfs_on_unparse_post_commit():
    sldif = SortedLdifWriter(MockLdifWriter())
    sldif.commit()
    sldif.unparse(dn="hi", attrs=dict(hi="there"))