def loghub(tmpdir, mock_http_api): class args: debug = True clientdir = tmpdir.join("clientdir") yes = False verbose = False out = py.io.TextIO() hub = Hub(args, file=out) def _getmatcher(): lines = out.getvalue().split("\n") return LineMatcher(lines) hub._getmatcher = _getmatcher return hub
def loghub(tmpdir): class args: debug = True clientdir = tmpdir.join("clientdir") yes = False verbose = False settrusted = False out = py.io.TextIO() hub = Hub(args, file=out) def _getmatcher(): lines = out.getvalue().split("\n") return LineMatcher(lines) hub._getmatcher = _getmatcher return hub
def use_current_devpi_index(event, event_name, _): # type: (PreHandleEvent, str, _) -> None # TODO: local import to avoid circular dependencies, clean-up once Poetry's plug-in systems arrives from poetry.repositories.legacy_repository import LegacyRepository # TODO: this hook is fired too late, we need to mutating Repository._url below. Ideally we would change # repository settings directly after parsing pyproject.toml before the pool is even initialized command = event.command.config.handler # type: EnvCommand devpi_args = _get_devpi_args([]) hub = Hub(devpi_args) current_devpi_index = "{}/+simple".format(hub.current.index) # replace any repository with the current devpi index, no need for caching as devpi already takes care # of this if hasattr(command, 'poetry'): command.poetry.pool.repositories[:] = [ LegacyRepository(r.name, current_devpi_index, disable_cache=True) for r in command.poetry.pool.repositories ] if command.poetry.locker: # if we got a lock file, change all package.source to point at the current index for info in command.poetry.locker.lock_data.get('package', []): source = info.get('source') if source and source.get( 'url', current_devpi_index) != current_devpi_index: event.io.write( "<warning>Package '{}' was installed from '{}' " "which is not the currently active index. " "Will override with current index..</warning>\n". format(info['name'], source['url'])) source['url'] = current_devpi_index
def test_main_push_pypi(monkeypatch, tmpdir, spec): from devpi.push import main l = [] def mypost(method, url, data, headers, auth=None, cert=None, verify=None): l.append((method, url, data)) class r: status_code = 201 reason = "created" content = json.dumps( dict(type="actionlog", status=201, result=[("200", "register", "pkg", "1.0"), ("200", "upload", "pkg-1.3.tar.gz")])) headers = {"content-type": "application/json"} _json = json.loads(content) r.url = url return r class args: clientdir = tmpdir.join("client") debug = False index = None hub = Hub(args) monkeypatch.setattr(hub.http, "request", mypost) hub.current.reconfigure(dict(index="/some/index")) p = tmpdir.join("pypirc") p.write( textwrap.dedent(""" [distutils] index-servers = whatever [whatever] repository: http://anotherserver username: test password: testp """)) class args: pypirc = str(p) target = "pypi:whatever" pkgspec = spec index = None main(hub, args) assert len(l) == 1 method, url, data = l[0] assert url == hub.current.index req = json.loads(data) assert req["name"] == "pkg" assert req["version"] == "1.0" assert req["posturl"] == "http://anotherserver" assert req["username"] == "test" assert req["password"] == "testp"
def test_fail_push(monkeypatch, tmpdir): from devpi.push import main l = [] def mypost(method, url, data, headers, auth=None, cert=None, verify=None): l.append((method, url, data)) class r: status_code = 500 reason = "Internal Server Error" content = json.dumps( dict(type="actionlog", status=201, result=[("500", "Internal Server Error", "Internal Server Error")])) headers = {"content-type": "application/json"} _json = json.loads(content) class request: method = '' r.url = url r.request.method = method return r class args: clientdir = tmpdir.join("client") debug = False index = None hub = Hub(args) monkeypatch.setattr(hub.http, "request", mypost) hub.current.reconfigure(dict(index="/some/index")) p = tmpdir.join("pypirc") p.write( textwrap.dedent(""" [distutils] index-servers = whatever [whatever] repository: http://anotherserver username: test password: testp """)) class args: pypirc = str(p) target = "pypi:whatever" pkgspec = "pkg==1.0" index = None try: main(hub, args) except SystemExit as e: assert e.code == 1
def mkhub(arglist): arglist = [str(x) for x in arglist] tmp = handler.mktemp("hub") for x in arglist: if "--clientdir" in x: break else: arglist.append("--clientdir=%s" % tmp) args = parse_args(["devpi_"] + arglist) with tmp.as_cwd(): return Hub(args)
def mkhub(arglist): arglist = [str(x) for x in arglist] tmp = tmpdir_factory.mktemp("hub") for x in arglist: if "--clientdir" in x: break else: arglist.append("--clientdir=%s" % tmp) pm = get_pluginmanager() args = parse_args(["devpi_"] + arglist, pm) with tmp.as_cwd(): return Hub(args)
def hub(args): out = py.io.TextIO() hub = Hub(args, file=out) hub._out = out hub.current._currentdict["login"] = "******" return hub
def hub(args): out = py.io.TextIO() hub = Hub(args, file=out) hub._out = out return hub