-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from ganwell/t/test_mirror_create_5520
test: convert test_mirror_create to new test
- Loading branch information
Showing
7 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters