Example #1
0
    def _make_manager(
        home: str = "",
        with_engine: bool = True,
        local_folder: Optional[Path] = None,
        user: Optional[User] = None,
    ):
        manager = Manager(home or tmp())

        # Force deletion behavior to real deletion for all tests
        manager.set_config("deletion_behavior", "delete_server")
        manager.dao.store_bool("show_deletion_prompt", False)

        request.addfinalizer(manager.close)
        log.info(f"[FIXTURE] Created {manager}")

        if with_engine:
            conf_folder = (local_folder or manager.home) / "nuxeo-conf"
            user = user or user_factory()
            manager.bind_server(
                conf_folder,
                nuxeo_url,
                user.uid,
                password=user.properties["password"],
                start_engine=False,
            )

            # Let the possibility to access user's attributes from the manager
            manager.user_details = user

            engine = None
            for engine_ in manager.engines.copy().values():
                engine = engine_

            return manager, engine

        return manager
Example #2
0
    def _append_user_attrs(self, number: int, register_roots: bool) -> None:
        """Create all stuff needed for one user. Ugly but useful."""

        # Create all what we need
        local_test_folder = self.tmpdir / str(number)
        local_nxdrive_folder = local_test_folder / "drive"
        local_nxdrive_folder.mkdir(parents=True)
        nxdrive_conf_folder = local_test_folder / "conf"
        nxdrive_conf_folder.mkdir()
        manager = Manager(nxdrive_conf_folder)
        user = getattr(self, f"user_{number}")
        password = getattr(self, f"password_{number}")
        engine = self.bind_engine(
            number,
            start_engine=False,
            manager=manager,
            user=user,
            password=password,
            folder=local_nxdrive_folder,
        )
        queue_manager = engine.queue_manager
        sync_root_folder = local_nxdrive_folder / self.workspace_title
        local_root_client = self.get_local_client(engine.local.base_folder)
        local = self.get_local_client(sync_root_folder)
        remote_document_client = DocRemote(
            self.nuxeo_url,
            getattr(self, f"user_{number}"),
            f"nxdrive-test-device-{number}",
            self.version,
            password=getattr(self, f"password_{number}"),
            base_folder=self.workspace,
            upload_tmp_dir=self.upload_tmp_dir,
            dao=engine.dao,
        )
        remote = RemoteBase(
            self.nuxeo_url,
            getattr(self, f"user_{number}"),
            f"nxdrive-test-device-{number}",
            self.version,
            password=getattr(self, f"password_{number}"),
            base_folder=self.workspace,
            upload_tmp_dir=self.upload_tmp_dir,
            dao=engine.dao,
        )
        if register_roots:
            remote.register_as_root(self.workspace)

        # Force deletion behavior to real deletion for all tests
        manager.set_config("deletion_behavior", "delete_server")
        manager.dao.store_bool("show_deletion_prompt", False)

        # And now persist in attributes
        setattr(self, f"manager_{number}", manager)
        setattr(self, f"local_test_folder_{number}", local_test_folder)
        setattr(self, f"local_nxdrive_folder_{number}", local_nxdrive_folder)
        setattr(self, f"nxdrive_conf_folder_{number}", nxdrive_conf_folder)
        setattr(self, f"queue_manager_{number}", queue_manager)
        setattr(self, f"sync_root_folder_{number}", sync_root_folder)
        setattr(self, f"local_root_client_{number}", local_root_client)
        setattr(self, f"local_{number}", local)
        setattr(self, f"remote_document_client_{number}",
                remote_document_client)
        setattr(self, f"remote_{number}", remote)