Beispiel #1
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)
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_with_commits_on_normal_execution():
    mock_ldif_writer = MockLdifWriter()
    with SortedLdifWriter(mock_ldif_writer) as sldif_writer:
        eq_([], mock_ldif_writer.called_with)
        sldif_writer.unparse(dn='hi', attrs=dict(hi='here'))
        eq_([], mock_ldif_writer.called_with)
        sldif_writer.unparse(dn='bye', attrs=dict(hi='there'))
        eq_([], mock_ldif_writer.called_with)
    eq_([('hi', dict(hi='here')),
         ('bye', dict(hi='there'))],
          mock_ldif_writer.called_with)
Beispiel #4
0
def test_with_no_commits_on_exception():
    mock_ldif_writer = MockLdifWriter()
    caught_ex = False
    try:
        with SortedLdifWriter(mock_ldif_writer) as sldif_writer:
            eq_([], mock_ldif_writer.called_with)
            sldif_writer.unparse(dn='hi', attrs=dict(hi='here'))
            eq_([], mock_ldif_writer.called_with)
            raise Exception("testing")
    except:
        caught_ex = True
        eq_([], mock_ldif_writer.called_with)

    # just to make sure I didn't screw up the test
    ok_(caught_ex)
Beispiel #5
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()
Beispiel #6
0
def test_barfs_on_double_commit():
    sldif = SortedLdifWriter(MockLdifWriter())
    sldif.commit()
    sldif.commit()
Beispiel #7
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"))