diff --git a/TODO b/TODO index f9ffe6d..c03ebc7 100644 --- a/TODO +++ b/TODO @@ -6,4 +6,9 @@ The following files have just been copied without checking if their content is o - CHANELOG.rst - README.rst -The reason for this is to ensure the continuity of the git history. \ No newline at end of file +The reason for this is to ensure the continuity of the git history. + +# Tool to convert yaml config to toml + +- This is probably just a sub-command of pyaptly +- We probably still want to switch to a modern yaml parser \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 9f42a28..9f23997 100644 --- a/poetry.lock +++ b/poetry.lock @@ -813,6 +813,17 @@ build = ["setuptools-git", "twine", "wheel"] docs = ["django", "furo", "sphinx", "sybil (>=3)", "twisted", "zope.component"] test = ["django", "mypy", "pytest (>=3.6)", "pytest-cov", "pytest-django", "sybil (>=3)", "twisted", "zope.component"] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + [[package]] name = "typing-extensions" version = "4.9.0" @@ -918,4 +929,4 @@ test = ["pytest"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "961562d63a5a6df669954ff44ed4df0f6b130b26c01336919ee93ac1df85236e" +content-hash = "4040715d1ef4567da6077f9c2cffb3f08c032983acd2f88d4149aff91a52c92f" diff --git a/pyaptly/aptly_test.py b/pyaptly/aptly_test.py index a31f027..6a3614f 100644 --- a/pyaptly/aptly_test.py +++ b/pyaptly/aptly_test.py @@ -4,6 +4,7 @@ import os import freezegun +import pytest import testfixtures from pyaptly import (Command, SystemStateReader, call_output, main, @@ -70,6 +71,7 @@ def test_pretend(): assert Command.pretend_mode +@pytest.mark.skip def test_mirror_create(): """Test if createing mirrors works.""" with test.clean_and_config( diff --git a/pyaptly/conftest.py b/pyaptly/conftest.py new file mode 100644 index 0000000..5b0a374 --- /dev/null +++ b/pyaptly/conftest.py @@ -0,0 +1,51 @@ +import json +import os +import tempfile +from pathlib import Path + +import pytest +import toml +import yaml + +aptly_conf = Path.home().absolute() / ".aptly.conf" +test_base = Path(__file__).absolute().parent / "tests" + + +@pytest.fixture() +def environment(): + tempdir_obj = tempfile.TemporaryDirectory() + tempdir = Path(tempdir_obj.name).absolute() + + aptly = tempdir / "aptly" + aptly.mkdir(parents=True) + config = {"rootDir": str(aptly)} + if aptly_conf.exists(): + aptly_conf.unlink() + with aptly_conf.open("w") as f: + json.dump(config, f) + + gnupg = tempdir / "gnugp" + gnupg.mkdir(parents=True) + os.chown(gnupg, 0, 0) + gnupg.chmod(0o700) + os.environ["GNUPGHOME"] = str(gnupg) + + try: + yield + finally: + tempdir_obj.cleanup() + aptly_conf.unlink() + + +@pytest.fixture() +def config(request): + config_file = test_base / request.param + with config_file.open("r", encoding="UTF-8") as f: + config = toml.load(f) + # TODO: remove yaml conversion + try: + with tempfile.NamedTemporaryFile(mode="w", encoding="UTF-8", delete=False) as f: + yaml.dump(config, f) + yield f.name, config + finally: + Path(f.name).unlink() diff --git a/pyaptly/tests/publish.toml b/pyaptly/tests/publish.toml new file mode 100644 index 0000000..465859e --- /dev/null +++ b/pyaptly/tests/publish.toml @@ -0,0 +1,6 @@ +[mirror.fakerepo03] +archive = "http://localhost:3123/fakerepo03" +gpg-keys = ["EC54D33E5B5EBE98"] +gpg-urls = ["http://localhost:3123/keys/test02.key"] +components = "main" +distribution = "main" \ No newline at end of file diff --git a/pyaptly/tests/test_mirror.py b/pyaptly/tests/test_mirror.py new file mode 100644 index 0000000..5c192b6 --- /dev/null +++ b/pyaptly/tests/test_mirror.py @@ -0,0 +1,28 @@ +import logging + +import pytest + +import pyaptly + + +@pytest.mark.parametrize("config", ["publish.toml"], indirect=True) +def test_mirror_create(environment, config, caplog): + """Test if creating mirrors works.""" + config_file, config_dict = config + + caplog.set_level(logging.DEBUG) + pyaptly.main(["-c", config_file, "mirror", "create"]) + + keys_added = [] + for rec in caplog.records: + for arg in rec.args: + if isinstance(arg, list): + if arg[0] == "gpg": + keys_added.append(arg[7]) + assert len(keys_added) > 0 + assert len(keys_added) == len(set(keys_added)), "Key multiple times added" + + expect = set(config_dict["mirror"].keys()) + state = pyaptly.SystemStateReader() + state.read() + assert state.mirrors == expect diff --git a/pyproject.toml b/pyproject.toml index f3dfb2f..49379fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ python = "^3.11" pretty-dump = {git = "https://github.com/adfinis/freeze"} pytz = "^2023.3.post1" pyyaml = "^6.0.1" +toml = "^0.10.2" [tool.poetry.group.dev.dependencies] freezegun = "^1.2.2"