2015-09-17 19:58:22 +02:00
|
|
|
#! /usr/bin/env py.test
|
2015-09-20 19:26:22 +02:00
|
|
|
"""
|
|
|
|
Checks an actual pypi-server against various clients.
|
|
|
|
|
|
|
|
The tests below are using 3 ways to startup pypi-servers:
|
|
|
|
|
2015-12-20 19:33:48 +01:00
|
|
|
- "open": a per-module server instance without any authed operations,
|
2015-09-20 19:26:22 +02:00
|
|
|
serving a single `wheel` package, on a fixed port.
|
2018-06-12 03:27:09 +02:00
|
|
|
- "open": a per-module server instance with authed 'download/upload'
|
|
|
|
operations, serving a single `wheel` package, on a fixed port.
|
2015-09-20 19:26:22 +02:00
|
|
|
- "new_server": starting a new server with any configurations on each test.
|
|
|
|
|
|
|
|
"""
|
2015-09-19 01:02:27 +02:00
|
|
|
from __future__ import print_function
|
2015-09-17 19:58:22 +02:00
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
from collections import namedtuple
|
2015-09-17 19:58:22 +02:00
|
|
|
import contextlib
|
2015-09-19 01:02:27 +02:00
|
|
|
import functools
|
|
|
|
import os
|
2015-09-17 19:58:22 +02:00
|
|
|
import subprocess
|
2015-09-18 18:31:12 +02:00
|
|
|
import sys
|
2015-09-19 02:36:43 +02:00
|
|
|
import tempfile
|
2015-09-17 19:58:22 +02:00
|
|
|
import time
|
2020-10-08 03:45:51 +02:00
|
|
|
from pathlib import Path
|
2018-06-12 03:27:09 +02:00
|
|
|
from shlex import split
|
|
|
|
from subprocess import Popen
|
2017-11-14 17:47:27 +01:00
|
|
|
from textwrap import dedent
|
2020-10-06 04:04:22 +02:00
|
|
|
|
2017-11-14 17:47:27 +01:00
|
|
|
try:
|
|
|
|
from urllib.request import urlopen
|
|
|
|
except ImportError:
|
|
|
|
from urllib import urlopen
|
2015-09-17 19:58:22 +02:00
|
|
|
|
|
|
|
from py import path # @UnresolvedImport
|
|
|
|
import pytest
|
|
|
|
|
2015-09-19 02:36:43 +02:00
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
# ######################################################################
|
|
|
|
# Fixtures & Helper Functions
|
|
|
|
# ######################################################################
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
_BUFF_SIZE = 2 ** 16
|
2015-09-19 01:02:27 +02:00
|
|
|
_port = 8090
|
2017-11-14 17:47:27 +01:00
|
|
|
SLEEP_AFTER_SRV = 3 # sec
|
2015-09-18 20:20:01 +02:00
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def port():
|
|
|
|
global _port
|
|
|
|
_port += 1
|
|
|
|
return _port
|
2015-09-17 19:58:22 +02:00
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
Srv = namedtuple("Srv", ("proc", "port", "package"))
|
2015-09-19 01:02:27 +02:00
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
def _run_server(packdir, port, authed, other_cli=""):
|
2017-11-14 17:47:27 +01:00
|
|
|
"""Run a server, optionally with partial auth enabled."""
|
2015-09-19 01:02:27 +02:00
|
|
|
pswd_opt_choices = {
|
2017-11-14 15:41:26 +01:00
|
|
|
True: "-Ptests/htpasswd.a.a -a update,download",
|
2017-11-14 17:47:27 +01:00
|
|
|
False: "-P. -a.",
|
2020-10-06 04:04:22 +02:00
|
|
|
"partial": "-Ptests/htpasswd.a.a -a update",
|
2015-09-19 01:02:27 +02:00
|
|
|
}
|
2015-09-20 19:26:22 +02:00
|
|
|
pswd_opts = pswd_opt_choices[authed]
|
2019-01-25 00:48:57 +01:00
|
|
|
cmd = (
|
2020-10-08 03:45:51 +02:00
|
|
|
f"{sys.executable} -m pypiserver.__main__ -vvv --overwrite -i 127.0.0.1 "
|
|
|
|
f"-p {port} {pswd_opts} {other_cli} {packdir}"
|
2019-01-25 00:48:57 +01:00
|
|
|
)
|
2015-09-19 01:02:27 +02:00
|
|
|
proc = subprocess.Popen(cmd.split(), bufsize=_BUFF_SIZE)
|
2015-12-20 19:33:48 +01:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
2015-09-19 02:36:43 +02:00
|
|
|
assert proc.poll() is None
|
2015-09-19 01:02:27 +02:00
|
|
|
|
|
|
|
return Srv(proc, int(port), packdir)
|
|
|
|
|
|
|
|
|
|
|
|
def _kill_server(srv):
|
2020-10-08 03:45:51 +02:00
|
|
|
print(f"Killing {srv}")
|
2015-09-17 19:58:22 +02:00
|
|
|
try:
|
2015-09-19 01:02:27 +02:00
|
|
|
srv.proc.terminate()
|
|
|
|
time.sleep(1)
|
2015-09-17 19:58:22 +02:00
|
|
|
finally:
|
2015-09-19 01:02:27 +02:00
|
|
|
srv.proc.kill()
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
2020-10-06 04:04:22 +02:00
|
|
|
def new_server(packdir, port, authed=False, other_cli=""):
|
|
|
|
srv = _run_server(packdir, port, authed=authed, other_cli=other_cli)
|
2015-09-19 01:02:27 +02:00
|
|
|
try:
|
|
|
|
yield srv
|
|
|
|
finally:
|
|
|
|
_kill_server(srv)
|
|
|
|
|
|
|
|
|
2015-09-19 02:36:43 +02:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def chdir(d):
|
|
|
|
old_d = os.getcwd()
|
|
|
|
try:
|
|
|
|
os.chdir(d)
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(old_d)
|
|
|
|
|
|
|
|
|
2015-09-20 19:26:22 +02:00
|
|
|
def _run_python(cmd):
|
2020-10-08 03:45:51 +02:00
|
|
|
return os.system(f"{sys.executable} {cmd}")
|
2015-09-20 18:35:11 +02:00
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.fixture(scope="module")
|
2015-09-20 19:26:22 +02:00
|
|
|
def project(request):
|
2015-09-19 02:36:43 +02:00
|
|
|
def fin():
|
|
|
|
tmpdir.remove(True)
|
2020-10-06 04:04:22 +02:00
|
|
|
|
2015-09-19 02:36:43 +02:00
|
|
|
tmpdir = path.local(tempfile.mkdtemp())
|
|
|
|
request.addfinalizer(fin)
|
2020-10-06 04:04:22 +02:00
|
|
|
src_setup_py = path.local().join("tests", "centodeps-setup.py")
|
2015-09-19 02:36:43 +02:00
|
|
|
assert src_setup_py.check()
|
2020-10-06 04:04:22 +02:00
|
|
|
projdir = tmpdir.join("centodeps")
|
2015-09-19 02:36:43 +02:00
|
|
|
projdir.mkdir()
|
2020-10-06 04:04:22 +02:00
|
|
|
dst_setup_py = projdir.join("setup.py")
|
2015-09-19 02:36:43 +02:00
|
|
|
src_setup_py.copy(dst_setup_py)
|
|
|
|
assert dst_setup_py.check()
|
2015-09-19 01:02:27 +02:00
|
|
|
|
2015-09-20 19:26:22 +02:00
|
|
|
return projdir
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.fixture(scope="module")
|
2015-09-20 19:26:22 +02:00
|
|
|
def package(project, request):
|
|
|
|
with chdir(project.strpath):
|
2020-10-06 04:04:22 +02:00
|
|
|
cmd = "setup.py bdist_wheel"
|
2015-09-20 19:26:22 +02:00
|
|
|
assert _run_python(cmd) == 0
|
2020-10-06 04:04:22 +02:00
|
|
|
pkgs = list(project.join("dist").visit("centodeps*.whl"))
|
2015-09-19 02:36:43 +02:00
|
|
|
assert len(pkgs) == 1
|
|
|
|
pkg = path.local(pkgs[0])
|
|
|
|
assert pkg.check()
|
|
|
|
|
|
|
|
return pkg
|
2015-09-19 01:02:27 +02:00
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.fixture(scope="module")
|
2015-09-19 01:02:27 +02:00
|
|
|
def packdir(package):
|
|
|
|
return package.dirpath()
|
|
|
|
|
|
|
|
|
|
|
|
open_port = 8081
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.fixture(scope="module")
|
2015-09-19 01:02:27 +02:00
|
|
|
def open_server(packdir, request):
|
2015-09-20 19:26:22 +02:00
|
|
|
srv = _run_server(packdir, open_port, authed=False)
|
2015-09-19 01:02:27 +02:00
|
|
|
fin = functools.partial(_kill_server, srv)
|
|
|
|
request.addfinalizer(fin)
|
|
|
|
|
|
|
|
return srv
|
|
|
|
|
|
|
|
|
|
|
|
protected_port = 8082
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.fixture(scope="module")
|
2015-09-19 01:02:27 +02:00
|
|
|
def protected_server(packdir, request):
|
2015-09-20 19:26:22 +02:00
|
|
|
srv = _run_server(packdir, protected_port, authed=True)
|
2015-09-19 01:02:27 +02:00
|
|
|
fin = functools.partial(_kill_server, srv)
|
|
|
|
request.addfinalizer(fin)
|
|
|
|
|
|
|
|
return srv
|
2015-09-17 19:58:22 +02:00
|
|
|
|
|
|
|
|
2015-09-18 20:20:01 +02:00
|
|
|
@pytest.fixture
|
2015-09-19 01:02:27 +02:00
|
|
|
def empty_packdir(tmpdir):
|
|
|
|
return tmpdir.mkdir("dists")
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
def _build_url(port, user="", pswd=""):
|
2020-10-08 03:45:51 +02:00
|
|
|
auth = f"{user}:{pswd}@" if user or pswd else ""
|
|
|
|
return f"http://{auth}localhost:{port}"
|
2015-09-18 19:05:07 +02:00
|
|
|
|
2015-09-17 19:58:22 +02:00
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
def _run_pip(cmd):
|
2018-06-12 03:27:09 +02:00
|
|
|
ncmd = (
|
2019-09-02 21:31:59 +02:00
|
|
|
"pip --no-cache-dir --disable-pip-version-check "
|
2020-10-08 03:45:51 +02:00
|
|
|
f"--retries 0 --timeout 5 --no-input {cmd}"
|
|
|
|
)
|
|
|
|
print(f"PIP: {ncmd}")
|
2018-06-12 03:27:09 +02:00
|
|
|
proc = Popen(split(ncmd))
|
|
|
|
proc.communicate()
|
|
|
|
return proc.returncode
|
2015-09-18 20:20:01 +02:00
|
|
|
|
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
def _run_pip_install(cmd, port, install_dir, user=None, pswd=None):
|
|
|
|
url = _build_url(port, user, pswd)
|
2020-10-08 03:45:51 +02:00
|
|
|
return _run_pip(f"-vv download -d {install_dir} -i {url} {cmd}")
|
2015-09-19 01:02:27 +02:00
|
|
|
|
2015-09-18 20:20:01 +02:00
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def pipdir(tmpdir):
|
|
|
|
return tmpdir.mkdir("pip")
|
|
|
|
|
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def pypirc_tmpfile(port, user, password):
|
|
|
|
"""Create a temporary pypirc file."""
|
|
|
|
fd, filepath = tempfile.mkstemp()
|
|
|
|
os.close(fd)
|
2020-10-08 03:45:51 +02:00
|
|
|
Path(filepath).write_text(
|
|
|
|
"\n".join(
|
|
|
|
(
|
|
|
|
"[distutils]",
|
|
|
|
"index-servers: test",
|
|
|
|
"" "[test]",
|
|
|
|
f"repository: {_build_url(port)}",
|
|
|
|
f"username: {user}",
|
|
|
|
f"password: {password}",
|
2020-10-06 04:04:22 +02:00
|
|
|
)
|
2018-11-10 01:42:13 +01:00
|
|
|
)
|
2020-10-08 03:45:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
print(Path(filepath).read_text())
|
2018-11-10 01:42:13 +01:00
|
|
|
yield filepath
|
|
|
|
os.remove(filepath)
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def pypirc_file(txt):
|
2020-10-06 04:04:22 +02:00
|
|
|
pypirc_path = path.local("~/.pypirc", expanduser=1)
|
2018-11-10 01:42:13 +01:00
|
|
|
old_pypirc = pypirc_path.read() if pypirc_path.check() else None
|
|
|
|
pypirc_path.write(txt)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
if old_pypirc:
|
|
|
|
pypirc_path.write(old_pypirc)
|
|
|
|
else:
|
|
|
|
pypirc_path.remove()
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
def twine_upload(
|
|
|
|
packages, repository="test", conf="pypirc", expect_failure=False
|
|
|
|
):
|
2018-11-10 01:42:13 +01:00
|
|
|
"""Call 'twine upload' with appropriate arguments"""
|
2020-10-06 04:04:22 +02:00
|
|
|
proc = Popen(
|
|
|
|
(
|
|
|
|
"twine",
|
|
|
|
"upload",
|
|
|
|
"--repository",
|
|
|
|
repository,
|
|
|
|
"--config-file",
|
|
|
|
conf,
|
|
|
|
" ".join(packages),
|
|
|
|
)
|
|
|
|
)
|
2018-11-10 01:42:13 +01:00
|
|
|
proc.communicate()
|
|
|
|
if not expect_failure and proc.returncode:
|
2020-10-06 04:04:22 +02:00
|
|
|
assert False, "Twine upload failed. See stdout/err"
|
2018-11-10 01:42:13 +01:00
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
def twine_register(
|
|
|
|
packages, repository="test", conf="pypirc", expect_failure=False
|
|
|
|
):
|
2018-11-10 01:42:13 +01:00
|
|
|
"""Call 'twine register' with appropriate args"""
|
2020-10-06 04:04:22 +02:00
|
|
|
proc = Popen(
|
|
|
|
(
|
|
|
|
"twine",
|
|
|
|
"register",
|
|
|
|
"--repository",
|
|
|
|
repository,
|
|
|
|
"--config-file",
|
|
|
|
conf,
|
|
|
|
" ".join(packages),
|
|
|
|
)
|
|
|
|
)
|
2018-11-10 01:42:13 +01:00
|
|
|
proc.communicate()
|
|
|
|
if not expect_failure and proc.returncode:
|
2020-10-06 04:04:22 +02:00
|
|
|
assert False, "Twine register failed. See stdout/err"
|
2018-11-10 01:42:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ######################################################################
|
|
|
|
# Tests
|
|
|
|
# ######################################################################
|
|
|
|
|
|
|
|
|
2015-09-19 01:02:27 +02:00
|
|
|
def test_pipInstall_packageNotFound(empty_packdir, port, pipdir, package):
|
2018-11-10 01:42:13 +01:00
|
|
|
with new_server(empty_packdir, port):
|
2015-09-19 01:02:27 +02:00
|
|
|
cmd = "centodeps"
|
|
|
|
assert _run_pip_install(cmd, port, pipdir) != 0
|
|
|
|
assert not pipdir.listdir()
|
|
|
|
|
|
|
|
|
|
|
|
def test_pipInstall_openOk(open_server, package, pipdir):
|
|
|
|
cmd = "centodeps"
|
|
|
|
assert _run_pip_install(cmd, open_server.port, pipdir) == 0
|
|
|
|
assert pipdir.join(package.basename).check()
|
|
|
|
|
|
|
|
|
2015-09-20 19:26:22 +02:00
|
|
|
def test_pipInstall_authedFails(protected_server, pipdir):
|
2015-09-19 01:02:27 +02:00
|
|
|
cmd = "centodeps"
|
|
|
|
assert _run_pip_install(cmd, protected_server.port, pipdir) != 0
|
|
|
|
assert not pipdir.listdir()
|
|
|
|
|
|
|
|
|
2015-09-20 19:26:22 +02:00
|
|
|
def test_pipInstall_authedOk(protected_server, package, pipdir):
|
2015-09-19 01:02:27 +02:00
|
|
|
cmd = "centodeps"
|
2020-10-06 04:04:22 +02:00
|
|
|
assert (
|
|
|
|
_run_pip_install(cmd, protected_server.port, pipdir, user="a", pswd="a")
|
|
|
|
== 0
|
|
|
|
)
|
2015-09-19 01:02:27 +02:00
|
|
|
assert pipdir.join(package.basename).check()
|
2015-09-18 20:20:01 +02:00
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.mark.parametrize("pkg_frmt", ["bdist", "bdist_wheel"])
|
|
|
|
def test_setuptoolsUpload_open(empty_packdir, port, project, package, pkg_frmt):
|
2016-05-15 05:56:00 +02:00
|
|
|
url = _build_url(port, None, None)
|
2020-10-06 04:04:22 +02:00
|
|
|
with pypirc_file(
|
|
|
|
dedent(
|
2020-10-08 03:45:51 +02:00
|
|
|
f"""\
|
2018-11-10 01:42:13 +01:00
|
|
|
[distutils]
|
|
|
|
index-servers: test
|
|
|
|
|
|
|
|
[test]
|
2020-10-08 03:45:51 +02:00
|
|
|
repository: {url}
|
2018-11-10 01:42:13 +01:00
|
|
|
username: ''
|
|
|
|
password: ''
|
2020-10-06 04:04:22 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
):
|
2016-05-15 05:56:00 +02:00
|
|
|
with new_server(empty_packdir, port):
|
|
|
|
with chdir(project.strpath):
|
2020-10-08 03:45:51 +02:00
|
|
|
cmd = f"setup.py -vvv {pkg_frmt} upload -r {url}"
|
2016-05-15 05:56:00 +02:00
|
|
|
for i in range(5):
|
2020-10-08 03:45:51 +02:00
|
|
|
print(f"++Attempt #{i}")
|
2016-05-15 05:56:00 +02:00
|
|
|
assert _run_python(cmd) == 0
|
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
2015-09-20 19:26:22 +02:00
|
|
|
assert len(empty_packdir.listdir()) == 1
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.mark.parametrize("pkg_frmt", ["bdist", "bdist_wheel"])
|
|
|
|
def test_setuptoolsUpload_authed(
|
|
|
|
empty_packdir, port, project, package, pkg_frmt, monkeypatch
|
|
|
|
):
|
2015-09-20 19:26:22 +02:00
|
|
|
url = _build_url(port)
|
2020-10-06 04:04:22 +02:00
|
|
|
with pypirc_file(
|
|
|
|
dedent(
|
2020-10-08 03:45:51 +02:00
|
|
|
f"""\
|
2018-11-10 01:42:13 +01:00
|
|
|
[distutils]
|
|
|
|
index-servers: test
|
|
|
|
|
|
|
|
[test]
|
2020-10-08 03:45:51 +02:00
|
|
|
repository: {url}
|
2018-11-10 01:42:13 +01:00
|
|
|
username: a
|
|
|
|
password: a
|
2020-10-06 04:04:22 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
):
|
2015-09-20 19:26:22 +02:00
|
|
|
with new_server(empty_packdir, port, authed=True):
|
|
|
|
with chdir(project.strpath):
|
2018-11-10 01:42:13 +01:00
|
|
|
cmd = (
|
2020-10-08 03:45:51 +02:00
|
|
|
f"setup.py -vvv {pkg_frmt} register -r test upload -r test"
|
2018-11-10 01:42:13 +01:00
|
|
|
)
|
2015-09-21 03:51:14 +02:00
|
|
|
for i in range(5):
|
2020-10-08 03:45:51 +02:00
|
|
|
print(f"++Attempt #{i}")
|
2015-09-21 03:51:14 +02:00
|
|
|
assert _run_python(cmd) == 0
|
2015-12-20 19:33:48 +01:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
2015-09-20 19:26:22 +02:00
|
|
|
assert len(empty_packdir.listdir()) == 1
|
|
|
|
|
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
@pytest.mark.parametrize("pkg_frmt", ["bdist", "bdist_wheel"])
|
|
|
|
def test_setuptools_upload_partial_authed(
|
|
|
|
empty_packdir, port, project, pkg_frmt
|
|
|
|
):
|
2017-11-14 17:47:27 +01:00
|
|
|
"""Test uploading a package with setuptools with partial auth."""
|
|
|
|
url = _build_url(port)
|
2020-10-06 04:04:22 +02:00
|
|
|
with pypirc_file(
|
|
|
|
dedent(
|
2020-10-08 03:45:51 +02:00
|
|
|
f"""\
|
2018-11-10 01:42:13 +01:00
|
|
|
[distutils]
|
|
|
|
index-servers: test
|
|
|
|
|
|
|
|
[test]
|
2020-10-08 03:45:51 +02:00
|
|
|
repository: {url}
|
2018-11-10 01:42:13 +01:00
|
|
|
username: a
|
|
|
|
password: a
|
2020-10-06 04:04:22 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
):
|
|
|
|
with new_server(empty_packdir, port, authed="partial"):
|
2017-11-14 17:47:27 +01:00
|
|
|
with chdir(project.strpath):
|
2020-10-06 04:04:22 +02:00
|
|
|
cmd = (
|
2020-10-08 03:45:51 +02:00
|
|
|
f"setup.py -vvv {pkg_frmt} register -r test upload -r test"
|
2020-10-06 04:04:22 +02:00
|
|
|
)
|
2017-11-14 17:47:27 +01:00
|
|
|
for i in range(5):
|
2020-10-08 03:45:51 +02:00
|
|
|
print(f"++Attempt #{i}")
|
2017-11-14 17:47:27 +01:00
|
|
|
assert _run_python(cmd) == 0
|
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
|
|
|
assert len(empty_packdir.listdir()) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_partial_authed_open_download(empty_packdir, port):
|
|
|
|
"""Validate that partial auth still allows downloads."""
|
2020-10-06 04:04:22 +02:00
|
|
|
url = _build_url(port) + "/simple"
|
|
|
|
with new_server(empty_packdir, port, authed="partial"):
|
2017-11-14 17:47:27 +01:00
|
|
|
resp = urlopen(url)
|
|
|
|
assert resp.getcode() == 200
|
|
|
|
|
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
def test_twine_upload_open(empty_packdir, port, package):
|
Update Tests for New Twine
* Updated .travis.yml to fix PEP 440 warnings
* Fixed twine calls
We were getting test failures on multiple branches in
`test_server.py`. I first investigated a warning message
popping up in every test run:
```
PEP440Warning,
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/pkg_resources/__init__.py:2510: PEP440Warning: 'setuptools (git-0.4.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
```
Moving the installation of setuptools, pip, sphinx, and tox
into the `install` key for Travis resolved that issue, but
`test_server.py` tests were still failing. It turns out that
Twine 1.7.0 added support for SSL cert specification and,
in the process, changed the call signature for the `upload`
and `register` internal methods.
This PR fixes the calls so that they align with Twine's new
function signature. Note that tests now fail on Twine <1.7.0,
so I have also updated the dev requirements file.
2016-07-17 20:40:06 +02:00
|
|
|
"""Test twine upload with no authentication"""
|
2020-10-06 04:04:22 +02:00
|
|
|
user, pswd = "foo", "bar"
|
2015-09-20 18:35:11 +02:00
|
|
|
with new_server(empty_packdir, port):
|
2018-11-10 01:42:13 +01:00
|
|
|
with pypirc_tmpfile(port, user, pswd) as rcfile:
|
2020-10-06 04:04:22 +02:00
|
|
|
twine_upload([package.strpath], repository="test", conf=rcfile)
|
2015-12-20 19:33:48 +01:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
2019-09-02 21:31:59 +02:00
|
|
|
|
2015-09-20 19:26:22 +02:00
|
|
|
assert len(empty_packdir.listdir()) == 1
|
2015-09-20 18:35:11 +02:00
|
|
|
|
|
|
|
|
2019-09-02 21:31:59 +02:00
|
|
|
@pytest.mark.parametrize("hash_algo", ("md5", "sha256", "sha512"))
|
|
|
|
def test_hash_algos(empty_packdir, port, package, pipdir, hash_algo):
|
|
|
|
"""Test twine upload with no authentication"""
|
2020-10-06 04:04:22 +02:00
|
|
|
user, pswd = "foo", "bar"
|
2019-09-02 21:31:59 +02:00
|
|
|
with new_server(
|
|
|
|
empty_packdir, port, other_cli="--hash-algo {}".format(hash_algo)
|
|
|
|
):
|
|
|
|
with pypirc_tmpfile(port, user, pswd) as rcfile:
|
2020-10-06 04:04:22 +02:00
|
|
|
twine_upload([package.strpath], repository="test", conf=rcfile)
|
2019-09-02 21:31:59 +02:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
|
|
|
|
|
|
|
assert _run_pip_install("centodeps", port, pipdir) == 0
|
|
|
|
|
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
def test_twine_upload_authed(empty_packdir, port, package):
|
Update Tests for New Twine
* Updated .travis.yml to fix PEP 440 warnings
* Fixed twine calls
We were getting test failures on multiple branches in
`test_server.py`. I first investigated a warning message
popping up in every test run:
```
PEP440Warning,
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/pkg_resources/__init__.py:2510: PEP440Warning: 'setuptools (git-0.4.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
```
Moving the installation of setuptools, pip, sphinx, and tox
into the `install` key for Travis resolved that issue, but
`test_server.py` tests were still failing. It turns out that
Twine 1.7.0 added support for SSL cert specification and,
in the process, changed the call signature for the `upload`
and `register` internal methods.
This PR fixes the calls so that they align with Twine's new
function signature. Note that tests now fail on Twine <1.7.0,
so I have also updated the dev requirements file.
2016-07-17 20:40:06 +02:00
|
|
|
"""Test authenticated twine upload"""
|
2020-10-06 04:04:22 +02:00
|
|
|
user, pswd = "a", "a"
|
2015-09-20 19:26:22 +02:00
|
|
|
with new_server(empty_packdir, port, authed=False):
|
2018-11-10 01:42:13 +01:00
|
|
|
with pypirc_tmpfile(port, user, pswd) as rcfile:
|
2020-10-06 04:04:22 +02:00
|
|
|
twine_upload([package.strpath], repository="test", conf=rcfile)
|
2015-12-20 19:33:48 +01:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
2015-09-20 19:26:22 +02:00
|
|
|
assert len(empty_packdir.listdir()) == 1
|
2015-09-18 19:05:07 +02:00
|
|
|
|
2020-10-06 04:04:22 +02:00
|
|
|
assert empty_packdir.join(package.basename).check(), (
|
|
|
|
package.basename,
|
|
|
|
empty_packdir.listdir(),
|
|
|
|
)
|
2015-09-19 01:02:27 +02:00
|
|
|
|
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
def test_twine_upload_partial_authed(empty_packdir, port, package):
|
2017-11-14 17:47:27 +01:00
|
|
|
"""Test partially authenticated twine upload"""
|
2020-10-06 04:04:22 +02:00
|
|
|
user, pswd = "a", "a"
|
|
|
|
with new_server(empty_packdir, port, authed="partial"):
|
2018-11-10 01:42:13 +01:00
|
|
|
with pypirc_tmpfile(port, user, pswd) as rcfile:
|
2020-10-06 04:04:22 +02:00
|
|
|
twine_upload([package.strpath], repository="test", conf=rcfile)
|
2017-11-14 17:47:27 +01:00
|
|
|
time.sleep(SLEEP_AFTER_SRV)
|
|
|
|
assert len(empty_packdir.listdir()) == 1
|
|
|
|
|
|
|
|
|
2018-11-10 01:42:13 +01:00
|
|
|
def test_twine_register_open(open_server, package):
|
Update Tests for New Twine
* Updated .travis.yml to fix PEP 440 warnings
* Fixed twine calls
We were getting test failures on multiple branches in
`test_server.py`. I first investigated a warning message
popping up in every test run:
```
PEP440Warning,
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/pkg_resources/__init__.py:2510: PEP440Warning: 'setuptools (git-0.4.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
```
Moving the installation of setuptools, pip, sphinx, and tox
into the `install` key for Travis resolved that issue, but
`test_server.py` tests were still failing. It turns out that
Twine 1.7.0 added support for SSL cert specification and,
in the process, changed the call signature for the `upload`
and `register` internal methods.
This PR fixes the calls so that they align with Twine's new
function signature. Note that tests now fail on Twine <1.7.0,
so I have also updated the dev requirements file.
2016-07-17 20:40:06 +02:00
|
|
|
"""Test unauthenticated twine registration"""
|
2015-09-20 18:35:11 +02:00
|
|
|
srv = open_server
|
2020-10-06 04:04:22 +02:00
|
|
|
with pypirc_tmpfile(srv.port, "foo", "bar") as rcfile:
|
|
|
|
twine_register([package.strpath], repository="test", conf=rcfile)
|
2015-09-20 18:35:11 +02:00
|
|
|
|
|
|
|
|
2018-11-10 01:46:06 +01:00
|
|
|
def test_twine_register_authed_ok(protected_server, package):
|
Update Tests for New Twine
* Updated .travis.yml to fix PEP 440 warnings
* Fixed twine calls
We were getting test failures on multiple branches in
`test_server.py`. I first investigated a warning message
popping up in every test run:
```
PEP440Warning,
/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/pkg_resources/__init__.py:2510: PEP440Warning: 'setuptools (git-0.4.0)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
```
Moving the installation of setuptools, pip, sphinx, and tox
into the `install` key for Travis resolved that issue, but
`test_server.py` tests were still failing. It turns out that
Twine 1.7.0 added support for SSL cert specification and,
in the process, changed the call signature for the `upload`
and `register` internal methods.
This PR fixes the calls so that they align with Twine's new
function signature. Note that tests now fail on Twine <1.7.0,
so I have also updated the dev requirements file.
2016-07-17 20:40:06 +02:00
|
|
|
"""Test authenticated twine registration"""
|
2015-09-20 18:35:11 +02:00
|
|
|
srv = protected_server
|
2020-10-06 04:04:22 +02:00
|
|
|
user, pswd = "a", "a"
|
2018-11-10 01:42:13 +01:00
|
|
|
with pypirc_tmpfile(srv.port, user, pswd) as rcfile:
|
2020-10-06 04:04:22 +02:00
|
|
|
twine_register([package.strpath], repository="test", conf=rcfile)
|