def xom(request, makexom): import devpi_web.main xom = makexom(plugins=[(devpi_web.main, None)]) from devpi_server.main import set_default_indexes with xom.keyfs.transaction(write=True): set_default_indexes(xom.model) return xom
def makexom(opts=(), httpget=httpget, proxy=None, mocking=True, plugins=()): from devpi_server import auth_basic from devpi_server import auth_devpi plugins = list(plugins) + [(auth_basic, None), (auth_devpi, None)] pm = get_pluginmanager() for plugin in plugins: pm.register(plugin) serverdir = gentmp() fullopts = ["devpi-server", "--serverdir", serverdir] + list(opts) fullopts = [str(x) for x in fullopts] config = parseoptions(pm, fullopts) config.init_nodeinfo() if mocking: if proxy is None: proxy = mock.create_autospec(XMLProxy) proxy.list_packages_with_serial.return_value = {} xom = XOM(config, proxy=proxy, httpget=httpget) add_pypistage_mocks(monkeypatch, httpget) else: xom = XOM(config) # initialize default indexes from devpi_server.main import set_default_indexes if not xom.config.args.master_url: with xom.keyfs.transaction(write=True): set_default_indexes(xom.model) if mocking: xom.pypimirror.init_pypi_mirror(proxy) if request.node.get_marker("start_threads"): xom.thread_pool.start() elif request.node.get_marker("with_notifier"): xom.thread_pool.start_one(xom.keyfs.notifier) request.addfinalizer(xom.thread_pool.shutdown) return xom
def xom(request, makexom): import devpi_findlinks.main xom = makexom(plugins=[(devpi_findlinks.main, None)]) from devpi_server.main import set_default_indexes with xom.keyfs.transaction(write=True): set_default_indexes(xom.model) return xom
def makexom(opts=(), httpget=httpget, proxy=None, mocking=True, plugins=()): hook = PluginManager(plugins) serverdir = gentmp() fullopts = ["devpi-server", "--serverdir", serverdir] + list(opts) fullopts = [str(x) for x in fullopts] config = parseoptions(fullopts, hook=hook) if mocking: if proxy is None: proxy = mock.create_autospec(XMLProxy) proxy.list_packages_with_serial.return_value = {} xom = XOM(config, proxy=proxy, httpget=httpget) add_pypistage_mocks(monkeypatch, httpget) else: xom = XOM(config) # initialize default indexes from devpi_server.main import set_default_indexes if not xom.config.args.master_url: with xom.keyfs.transaction(write=True): set_default_indexes(xom.model) if mocking: xom.pypimirror.init_pypi_mirror(proxy) if request.node.get_marker("start_threads"): xom.thread_pool.start() elif request.node.get_marker("with_notifier"): xom.thread_pool.start_one(xom.keyfs.notifier) request.addfinalizer(xom.thread_pool.shutdown) return xom
def makexom(opts=(), httpget=httpget, plugins=()): from devpi_server import auth_basic from devpi_server import auth_devpi plugins = [ plugin[0] if isinstance(plugin, tuple) else plugin for plugin in plugins ] for plugin in [auth_basic, auth_devpi, storage_info["_test_plugin"]]: if plugin not in plugins: plugins.append(plugin) pm = get_pluginmanager(load_entrypoints=False) for plugin in plugins: pm.register(plugin) serverdir = gentmp() fullopts = ["devpi-server", "--serverdir", serverdir] + list(opts) if request.node.get_marker("with_replica_thread"): fullopts.append("--master=http://localhost") if not request.node.get_marker("no_storage_option"): if storage_info["name"] != "sqlite": fullopts.append("--storage=%s" % storage_info["name"]) fullopts = [str(x) for x in fullopts] config = parseoptions(pm, fullopts) config.init_nodeinfo() for marker in ("storage_with_filesystem", ): if request.node.get_marker(marker): info = config._storage_info() markers = info.get("_test_markers", []) if marker not in markers: pytest.skip("The storage doesn't have marker '%s'." % marker) if not request.node.get_marker("no_storage_option"): assert storage_info["storage"] is config.storage if request.node.get_marker("nomocking"): xom = XOM(config) else: xom = XOM(config, httpget=httpget) if not request.node.get_marker("nomockprojectsremote"): monkeypatch.setattr(extpypi.PyPIStage, "_get_remote_projects", lambda self: set()) add_pypistage_mocks(monkeypatch, httpget) # initialize default indexes from devpi_server.main import set_default_indexes if not xom.config.args.master_url: with xom.keyfs.transaction(write=True): set_default_indexes(xom.model) if request.node.get_marker("with_replica_thread"): from devpi_server.replica import ReplicaThread rt = ReplicaThread(xom) xom.replica_thread = rt xom.thread_pool.register(rt) xom.thread_pool.start_one(rt) if request.node.get_marker("start_threads"): xom.thread_pool.start() elif request.node.get_marker("with_notifier"): xom.thread_pool.start_one(xom.keyfs.notifier) request.addfinalizer(xom.thread_pool.shutdown) return xom
def test_setdefault_indexes(xom, model): from devpi_server.main import set_default_indexes with model.keyfs.transaction(write=True): set_default_indexes(xom.model) with model.keyfs.transaction(write=False): assert model.getstage("root/pypi").ixconfig["type"] == "mirror" with model.keyfs.transaction(write=False): ixconfig = model.getstage("root/pypi").ixconfig for key in ixconfig: assert py.builtin._istext(key) userconfig = model.get_user("root").get() for key in userconfig["indexes"]["pypi"]: assert py.builtin._istext(key)
def test_setdefault_indexes(db): from devpi_server.main import set_default_indexes set_default_indexes(db) ixconfig = db.getindexconfig("root/pypi") assert ixconfig["type"] == "pypimirror" ixconfig = db.getindexconfig("root/dev") assert ixconfig["type"] == "pypi" assert ixconfig["bases"] == ("root/prod",) assert ixconfig["volatile"] ixconfig = db.getindexconfig("root/prod") assert ixconfig["type"] == "pypi" assert ixconfig["bases"] == () assert not ixconfig["volatile"]
def test_setdefault_indexes(db): from devpi_server.main import set_default_indexes set_default_indexes(db) ixconfig = db.index_get("root/pypi") assert ixconfig["type"] == "mirror"
def db(xom): from devpi_server.db import DB from devpi_server.main import set_default_indexes db = DB(xom) set_default_indexes(db) return db
def test_setdefault_indexes(xom, model): from devpi_server.main import set_default_indexes with model.keyfs.transaction(write=True): set_default_indexes(xom.model) with model.keyfs.transaction(write=False): assert model.getstage("root/pypi").ixconfig["type"] == "mirror"