Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docker tests in cicd #444

Merged
merged 3 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/docker-requirements.txt
@@ -1,6 +1,6 @@
# We use gunicorn as the default server in the docker container, with gevent
# workers
gevent==21.1.2
gevent==21.12.0
gunicorn==20.0.4
passlib==1.7.4
bcrypt==3.2.0
Expand Down
30 changes: 17 additions & 13 deletions docker/test_docker.py
Expand Up @@ -16,6 +16,9 @@
import pytest


PYPISERVER_PROCESS_NAME = "pypi-server"
TEST_DEMO_PIP_PACKAGE = "pypiserver-mypkg"

THIS_DIR = Path(__file__).parent
ROOT_DIR = THIS_DIR.parent
DOCKERFILE = ROOT_DIR / "Dockerfile"
Expand All @@ -24,13 +27,13 @@
HTPASS_FILE = FIXTURES / "htpasswd.a.a"


# This is largely useless when using pytest because of the need to use the name
# of the fixture as an argument to the test function or fixture using it
# This rule is largely useless when using pytest because of the need to use the
# name of the fixture as an argument to the test function or fixture using it
# pylint: disable=redefined-outer-name
#
# Also useless for our test context, where we may want to group test functions
# in a class to share common fixtures, but where we don't care about the
# `self` instance.
# Also useless rule for our test context, where we may want to group test
# functions in a class to share common fixtures, but where we don't care about
# the `self` instance.
# pylint: disable=no-self-use


Expand Down Expand Up @@ -144,9 +147,10 @@ def uninstall_pkgs() -> None:
"""Uninstall any packages we've installed."""
res = run("pip", "freeze", capture=True)
if any(
ln.strip().startswith("pypiserver-mypkg") for ln in res.out.splitlines()
ln.strip().startswith(TEST_DEMO_PIP_PACKAGE)
for ln in res.out.splitlines()
):
run("pip", "uninstall", "-y", "pypiserver-mypkg")
run("pip", "uninstall", "-y", TEST_DEMO_PIP_PACKAGE)


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -169,7 +173,7 @@ class TestCommands:
def test_help(self, image: str) -> None:
"""We can get help from the docker container."""
res = run("docker", "run", image, "--help", capture=True)
assert "pypi-server" in res.out
assert PYPISERVER_PROCESS_NAME in res.out

def test_version(self, image: str) -> None:
"""We can get the version from the docker container."""
Expand Down Expand Up @@ -267,7 +271,7 @@ def test_runs_as_pypiserver_user(self, image: str) -> None:
proc_line = next(
filter(
# grab the process line for the pypi-server process
lambda ln: "pypi-server" in ln,
lambda ln: PYPISERVER_PROCESS_NAME in ln,
res.out.splitlines(),
)
)
Expand Down Expand Up @@ -330,7 +334,7 @@ def container(
".",
"--authenticate",
".",
*request.param, # type: ignore
*request.param,
)
res = run(*args, capture=True)
wait_for_container(port)
Expand Down Expand Up @@ -394,7 +398,7 @@ def test_install(self, container: ContainerInfo) -> None:
"install",
"--index-url",
f"http://localhost:{container.port}/simple",
"pypiserver-mypkg",
TEST_DEMO_PIP_PACKAGE,
)
run("python", "-c", "'import pypiserver_mypkg; mypkg.pkg_name()'")

Expand Down Expand Up @@ -560,7 +564,7 @@ def test_install(self) -> None:
"install",
"--index-url",
f"http://a:a@localhost:{self.HOST_PORT}/simple",
"pypiserver-mypkg",
TEST_DEMO_PIP_PACKAGE,
)
run("python", "-c", "'import pypiserver_mypkg; mypkg.pkg_name()'")

Expand All @@ -580,7 +584,7 @@ def test_install_failed_auth(self) -> None:
"--no-cache",
"--index-url",
f"http://localhost:{self.HOST_PORT}/simple",
"pypiserver-mypkg",
TEST_DEMO_PIP_PACKAGE,
check_code=lambda c: c != 0,
)

Expand Down