Esempio n. 1
0
def cleanup_test_config(m: Maestral, test_folder_dbx: Optional[str] = None) -> None:
    """
    Shuts down syncing for the given Maestral instance, removes all local files and
    folders related to that instance, including the local Dropbox folder, and removes
    any '.mignore' files.

    :param m: Maestral instance.
    :param test_folder_dbx: Optional test folder to clean up.
    """

    # stop syncing and clean up remote folder
    m.stop_sync()

    if test_folder_dbx:
        try:
            m.client.remove(test_folder_dbx)
        except NotFoundError:
            pass

    try:
        m.client.remove("/.mignore")
    except NotFoundError:
        pass

    # remove creds from system keyring
    m.client.auth.delete_creds()

    # remove local files and folders
    delete(m.dropbox_path)
    remove_configuration("test-config")
Esempio n. 2
0
    def tearDown(self):

        self.observer.stop()
        self.observer.join()

        remove_configuration("test-config")
        delete(self.sync.dropbox_path)
Esempio n. 3
0
    def test_remote_exceptions(self):

        # start daemon process
        start_maestral_daemon_process(self.config_name)

        # create proxy and call a remote method which raises an error
        with MaestralProxy(self.config_name) as m:
            with self.assertRaises(NotLinkedError):
                m.get_account_info()

        # stop daemon
        stop_maestral_daemon_process(self.config_name)

        # clean up config
        remove_configuration(self.config_name)
Esempio n. 4
0
    def test_fallback(self):

        config_name = "daemon-lifecycle-test"

        # create proxy w/o fallback
        with self.assertRaises(CommunicationError):
            MaestralProxy(config_name)

        # create proxy w/ fallback
        with MaestralProxy(config_name, fallback=True) as m:
            self.assertEqual(m.config_name, config_name)
            self.assertTrue(m._is_fallback)
            self.assertIsInstance(m._m, Maestral)

        # clean up config
        remove_configuration(config_name)
Esempio n. 5
0
    def test_connection(self):

        # start daemon process
        res = start_maestral_daemon_process(self.config_name)
        self.assertEqual(Start.Ok, res)

        # create proxy
        with MaestralProxy(self.config_name) as m:
            self.assertEqual(m.config_name, self.config_name)
            self.assertFalse(m._is_fallback)
            self.assertIsInstance(m._m, Proxy)

        # stop daemon
        res = stop_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Stop.Ok)

        # clean up config
        remove_configuration(self.config_name)
Esempio n. 6
0
def configs() -> None:

    # clean up stale configs
    config_names = list_configs()

    for name in config_names:
        dbid = MaestralConfig(name).get("account", "account_id")
        if dbid == "" and not is_running(name):
            remove_configuration(name)

    # display remaining configs
    names = list_configs()
    emails = [MaestralState(c).get("account", "email") for c in names]

    click.echo("")
    click.echo(
        format_table(columns=[names, emails], headers=["Config name", "Account"])
    )
    click.echo("")
Esempio n. 7
0
    def test_lifecycle_attached(self):

        # start daemon process
        res = start_maestral_daemon_process(self.config_name, detach=False)
        self.assertEqual(res, Start.Ok)

        # check that we have attached process
        ctx = mp.get_context("spawn" if IS_MACOS else "fork")
        daemon = ctx.active_children()[0]
        self.assertEqual(daemon.name, "maestral-daemon")

        # stop daemon
        res = stop_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Stop.Ok)

        # retry stop daemon
        res = stop_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Stop.NotRunning)

        # clean up config
        remove_configuration(self.config_name)
Esempio n. 8
0
    def test_lifecycle_detached(self):

        # start daemon process
        res = start_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Start.Ok)

        # retry start daemon process
        res = start_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Start.AlreadyRunning)

        # retry start daemon in-process
        with self.assertRaises(RuntimeError):
            start_maestral_daemon(self.config_name)

        # stop daemon
        res = stop_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Stop.Ok)

        # retry stop daemon
        res = stop_maestral_daemon_process(self.config_name)
        self.assertEqual(res, Stop.NotRunning)

        # clean up config
        remove_configuration(self.config_name)
Esempio n. 9
0
 def tearDown(self):
     remove_configuration("test-config")