コード例 #1
0
def test_provider_info_none():
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    assert lib.dc_provider_new_from_email(
        ctx, cutil.as_dc_charpointer("*****@*****.**")) == ffi.NULL
コード例 #2
0
    def __init__(  # noqa
            self, db_path: str, os_name: str, logger: logging.Logger) -> None:
        """initialize account object.

        :param db_path: a path to the account database. The database
                        will be created if it doesn't exist.
        :param os_name: this is only for decorative use.
        :param logger: account logger.
        """
        # initialize per-account plugin system
        self._pm = hookspec.PerAccount._make_plugin_manager()
        self._logging = True

        self.add_account_plugin(self)

        self.db_path = db_path
        if hasattr(db_path, "encode"):
            db_path = db_path.encode("utf8")  # type: ignore

        self._dc_context = ffi.gc(
            lib.dc_context_new(as_dc_charpointer(os_name), db_path, ffi.NULL),
            lib.dc_context_unref,
        )
        if self._dc_context == ffi.NULL:
            raise ValueError(f"Could not dc_context_new: {os_name} {db_path}")

        self._shutdown_event = Event()
        self._event_thread = BotEventThread(self, logger)
        self._configkeys = self.get_config("sys.config_keys").split()
        hook = hookspec.Global._get_plugin_manager().hook
        hook.dc_account_init(account=self)
コード例 #3
0
def test_wrong_db(tmpdir):
    p = tmpdir.join("hello.db")
    # write an invalid database file
    p.write("x123" * 10)

    context = lib.dc_context_new(ffi.NULL, p.strpath.encode("ascii"), ffi.NULL)
    assert not lib.dc_context_is_open(context)
コード例 #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"")
コード例 #5
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
コード例 #6
0
def test_get_info_closed():
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
    assert 'deltachat_core_version' in info
    assert 'database_dir' not in info
コード例 #7
0
def test_empty_blobdir(tmpdir):
    db_fname = tmpdir.join("hello.db")
    # Apparently some client code expects this to be the same as passing NULL.
    ctx = ffi.gc(
        lib.dc_context_new(ffi.NULL, db_fname.strpath.encode("ascii"), b""),
        lib.dc_context_unref,
    )
    assert ctx != ffi.NULL
コード例 #8
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)
コード例 #9
0
def test_get_info_open(tmpdir):
    db_fname = tmpdir.join("test.db")
    ctx = ffi.gc(
        lib.dc_context_new(ffi.NULL, db_fname.strpath.encode("ascii"), ffi.NULL),
        lib.dc_context_unref,
    )
    info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
    assert 'deltachat_core_version' in info
    assert 'database_dir' in info
コード例 #10
0
def test_is_open_closed():
    ctx = ffi.gc(
        lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
        lib.dc_context_unref,
    )
    assert lib.dc_is_open(ctx) == 0