Skip to content

Commit

Permalink
Merge pull request #51 from ganwell/t/publish_5b84
Browse files Browse the repository at this point in the history
test: move puslish tests
  • Loading branch information
Jean-Louis Fuchs authored Jan 15, 2024
2 parents 64cc54e + c308a9a commit 26cfe4d
Show file tree
Hide file tree
Showing 12 changed files with 460 additions and 16 deletions.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ The reason for this is to ensure the continuity of the git history.

# Add good documentation to every function and module, but plan to review all of
it once everything is in place

# Do all output via logging module

- Idea show INFO and above, but display info without timestamp etc.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 23 additions & 7 deletions pyaptly/aptly_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_mirror_create():
assert state.mirrors == expect


def do_mirror_update(config):
def do_mirror_update(config): # pragma: no cover
"""Test if updating mirrors works."""
args = ["-c", config, "mirror", "create"]
state = SystemStateReader()
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_mirror_update_single():
main(args)


def do_snapshot_create(config):
def do_snapshot_create(config): # pragma: no cover
"""Test if createing snapshots works"""
do_mirror_update(config)
args = ["-c", config, "snapshot", "create"]
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_snapshot_update_threetimes_rotating():
assert state.snapshot_map == expected


def do_snapshot_update_rotating(config):
def do_snapshot_update_rotating(config): # pragma: no cover
"""Helper for rotating snapshot tests"""
do_mirror_update(config)
args = [
Expand Down Expand Up @@ -461,6 +461,7 @@ def test_snapshot_create_repo():
return state


@pytest.mark.skip
def test_snapshot_create_merge():
"""Test if snapshot merge create works."""
with test.clean_and_config(
Expand Down Expand Up @@ -490,6 +491,7 @@ def test_snapshot_create_merge():
assert expect == state.snapshot_map


@pytest.mark.skip
def test_snapshot_create_filter():
"""Test if snapshot filter create works."""
with test.clean_and_config(
Expand All @@ -507,7 +509,7 @@ def test_snapshot_create_filter():
assert state == expect


def do_publish_create(config):
def do_publish_create(config): # pragma: no cover
"""Test if creating publishes works."""
do_snapshot_create(config)
args = ["-c", config, "publish", "create"]
Expand All @@ -522,7 +524,7 @@ def do_publish_create(config):
assert expect == state.publish_map


def do_publish_create_rotating(config):
def do_publish_create_rotating(config): # pragma: no cover
"""Test if creating publishes works."""
do_snapshot_update_rotating(config)
args = ["-c", config, "publish", "create"]
Expand All @@ -547,6 +549,7 @@ def do_publish_create_rotating(config):
assert expect == state.publish_map


@pytest.mark.skip
def test_publish_create_single():
"""Test if creating a single publish works."""
with test.clean_and_config(
Expand All @@ -572,6 +575,7 @@ def test_publish_create_single():
assert expect == state.publish_map


@pytest.mark.skip
def test_publish_create_inexistent():
"""Test if creating inexistent publish raises an error."""
with test.clean_and_config(
Expand All @@ -596,6 +600,7 @@ def test_publish_create_inexistent():
assert error


@pytest.mark.skip
def test_publish_create_repo():
"""Test if creating repo publishes works."""
with test.clean_and_config(
Expand Down Expand Up @@ -626,6 +631,7 @@ def test_publish_create_repo():
assert {"centrify latest": set([])} == state.publish_map


@pytest.mark.skip
def test_publish_create_basic():
"""Test if creating publishes works."""
with test.clean_and_config(
Expand All @@ -638,6 +644,7 @@ def test_publish_create_basic():
do_publish_create(config)


@pytest.mark.skip
def test_publish_update_rotating():
"""Test if update rotating publishes works."""
with test.clean_and_config(
Expand Down Expand Up @@ -666,6 +673,7 @@ def test_publish_update_rotating():
assert expect == state.publish_map


@pytest.mark.skip
def test_publish_snapshot_update_rotating():
"""Test if update rotating publishes via snapshot works."""
with test.clean_and_config(
Expand Down Expand Up @@ -694,6 +702,7 @@ def test_publish_snapshot_update_rotating():
assert expect == state.publish_map


@pytest.mark.skip
def test_publish_create_rotating():
"""Test if creating rotating publishes works."""
with test.clean_and_config(
Expand All @@ -706,7 +715,7 @@ def test_publish_create_rotating():
do_publish_create_rotating(config)


def do_publish_create_republish(config):
def do_publish_create_republish(config): # pragma: no cover
"""Test if creating republishes works."""
with testfixtures.LogCapture() as l:
do_publish_create(config)
Expand All @@ -728,6 +737,7 @@ def do_publish_create_republish(config):
assert "fakerepo01-stable main" in state.publishes


@pytest.mark.skip
def test_publish_create_republish():
"""Test if creating republishes works."""
with test.clean_and_config(
Expand All @@ -740,6 +750,7 @@ def test_publish_create_republish():
do_publish_create_republish(config)


@pytest.mark.skip
def test_publish_update_republish():
"""Test if update republishes works."""
with test.clean_and_config(
Expand Down Expand Up @@ -782,6 +793,7 @@ def test_publish_update_republish():
assert expect == state.publish_map


@pytest.mark.skip
def test_publish_updating_basic():
"""Test if updating publishes works."""
with test.clean_and_config(
Expand Down Expand Up @@ -815,7 +827,7 @@ def test_publish_updating_basic():
assert expect == state.publish_map


def do_repo_create(config):
def do_repo_create(config): # pragma: no cover
"""Test if creating repositories works."""
args = ["-c", config, "repo", "create"]
main(args)
Expand All @@ -833,6 +845,7 @@ def do_repo_create(config):
assert set(["centrify"]) == state.repos


@pytest.mark.skip
def test_repo_create_single():
"""Test if creating a single repo works."""
with test.clean_and_config(
Expand All @@ -854,6 +867,7 @@ def test_repo_create_single():
assert set(["centrify"]) == state.repos


@pytest.mark.skip
def test_repo_create_inexistent():
"""Test if creating an inexistent repo causes an error."""
with test.clean_and_config(
Expand All @@ -877,6 +891,7 @@ def test_repo_create_inexistent():
assert error


@pytest.mark.skip
def test_repo_create_basic():
"""Test if creating repositories works."""
with test.clean_and_config(
Expand All @@ -888,6 +903,7 @@ def test_repo_create_basic():
do_repo_create(config)


@pytest.mark.skip
def test_snapshot_spec_as_dict():
"Test various snapshot formats for snapshot_spec_to_name()"

Expand Down
71 changes: 70 additions & 1 deletion pyaptly/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

aptly_conf = Path.home().absolute() / ".aptly.conf"
test_base = Path(__file__).absolute().parent / "tests"
setup_base = Path("/setup")


@pytest.fixture()
Expand Down Expand Up @@ -73,6 +74,13 @@ def environment(debug_mode):
aptly_conf.unlink()


@pytest.fixture()
def test_key_03(environment):
"""Get test gpg-key number 3."""
util.run_command(["gpg", "--import", setup_base / "test03.key"], check=True)
util.run_command(["gpg", "--import", setup_base / "test03.pub"], check=True)


@pytest.fixture()
def freeze(request):
"""Freeze to datetime.
Expand Down Expand Up @@ -204,7 +212,7 @@ def snapshot_update_rotating(config, mirror_update, freeze):


@pytest.fixture()
def repo_create(environment, config):
def repo_create(environment, config, test_key_03):
"""Test if creating repositories works."""
args = ["-c", config, "repo", "create"]
pyaptly.main(args)
Expand All @@ -220,3 +228,64 @@ def repo_create(environment, config):
]
)
assert set(["centrify"]) == state.repos


@pytest.fixture()
def publish_create(config, snapshot_create, test_key_03):
"""Test if creating publishes works."""
args = ["-c", config, "publish", "create"]
pyaptly.main(args)
state = pyaptly.SystemStateReader()
state.read()
assert set(["fakerepo02 main", "fakerepo01 main"]) == state.publishes
expect = {
"fakerepo02 main": set(["fakerepo02-20121006T0000Z"]),
"fakerepo01 main": set(["fakerepo01-20121010T0000Z"]),
}
assert expect == state.publish_map


@pytest.fixture()
def publish_create_rotating(config, snapshot_update_rotating, test_key_03):
"""Test if creating publishes works."""
args = ["-c", config, "publish", "create"]
pyaptly.main(args)
state = pyaptly.SystemStateReader()
state.read()
assert (
set(
[
"fakerepo01/current stable",
"fake/current stable",
"fakerepo02/current stable",
]
)
== state.publishes
)
expect = {
"fake/current stable": set(["fake-current"]),
"fakerepo01/current stable": set(["fakerepo01-current"]),
"fakerepo02/current stable": set(["fakerepo02-current"]),
}
assert expect == state.publish_map


@pytest.fixture()
def publish_create_republish(config, publish_create, caplog):
"""Test if creating republishes works."""
found = False
for rec in caplog.records:
if rec.levelname == "CRITICAL":
if "has been deferred" in rec.msg:
found = True
assert found
args = [
"-c",
config,
"publish",
"create",
]
pyaptly.main(args)
state = pyaptly.SystemStateReader()
state.read()
assert "fakerepo01-stable main" in state.publishes
2 changes: 1 addition & 1 deletion pyaptly/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def clean_and_config(test_input, freeze="2012-10-10 10:10:10", sign=False):
gnupg.chmod(0o700)
environb[b"GNUPGHOME"] = str(gnupg).encode("UTF-8")

if sign:
if sign: # pragma: no cover
setup = Path("/setup")
subprocess.run(["gpg", "--import", setup / "test03.pub"], check=True)
subprocess.run(["gpg", "--import", setup / "test03.key"], check=True)
Expand Down
44 changes: 44 additions & 0 deletions pyaptly/tests/publish-current.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[mirror.fakerepo01]
max-tries = 2
archive = "http://localhost:3123/fakerepo01"
gpg-keys = [ "2841988729C7F3FF",]
components = "main"
distribution = "main"

[mirror.fakerepo02]
archive = "http://localhost:3123/fakerepo02"
gpg-keys = [ "2841988729C7F3FF",]
components = "main"
distribution = "main"

[snapshot.fakerepo01-current]
mirror = "fakerepo01"

[snapshot.fakerepo02-current]
mirror = "fakerepo02"

[snapshot.fake-current]
merge = [ "fakerepo01-current", "fakerepo02-current",]

[publish]
[[publish."fakerepo01/current"]]
distribution = "stable"
architectures = [ "amd64",]
components = [ "main",]
snapshots = [ "fakerepo01-current",]
automatic-update = true

[[publish."fakerepo02/current"]]
distribution = "stable"
architectures = [ "amd64",]
components = [ "main",]
snapshots = [ "fakerepo02-current",]
automatic-update = true

[[publish."fake/current"]]
distribution = "stable"
architectures = [ "amd64",]
components = [ "main",]
snapshots = [ "fake-current",]
automatic-update = true

Loading

0 comments on commit 26cfe4d

Please sign in to comment.