Ejemplo n.º 1
0
def test_dc_close_events(tmpdir):
    ctx = ffi.gc(
        capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    evlog = EventLogger(ctx)
    evlog.set_timeout(5)
    set_context_callback(
        ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
    p = tmpdir.join("hello.db")
    lib.dc_open(ctx, p.strpath.encode("ascii"), ffi.NULL)
    capi.lib.dc_close(ctx)

    def find(info_string):
        while 1:
            ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
            data2 = ev[2]
            if info_string in data2:
                return
            else:
                print("skipping event", *ev)

    find("disconnecting inbox-thread")
    find("disconnecting sentbox-thread")
    find("disconnecting mvbox-thread")
    find("disconnecting SMTP")
    find("Database closed")
Ejemplo n.º 2
0
def test_is_open_actually_open(tmpdir):
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    db_fname = tmpdir.join("test.db")
    lib.dc_open(ctx, db_fname.strpath.encode("ascii"), ffi.NULL)
    assert lib.dc_is_open(ctx) == 1
Ejemplo n.º 3
0
def test_get_info_open(tmpdir):
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    db_fname = tmpdir.join("test.db")
    lib.dc_open(ctx, db_fname.strpath.encode("ascii"), ffi.NULL)
    info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
    assert 'deltachat_core_version' in info
    assert 'database_dir' in info
Ejemplo n.º 4
0
def test_empty_blobdir(tmpdir):
    # Apparently some client code expects this to be the same as passing NULL.
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    db_fname = tmpdir.join("hello.db")
    assert lib.dc_open(ctx, db_fname.strpath.encode("ascii"), b"")
Ejemplo n.º 5
0
def test_wrong_db(tmpdir):
    dc_context = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    p = tmpdir.join("hello.db")
    # write an invalid database file
    p.write("x123" * 10)
    assert not lib.dc_open(dc_context, p.strpath.encode("ascii"), ffi.NULL)