Skip to content

Commit

Permalink
test: move puslish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs committed Jan 10, 2024
1 parent 64cc54e commit c5c6ab2
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 1 deletion.
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.
8 changes: 8 additions & 0 deletions pyaptly/aptly_test.py
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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
70 changes: 69 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,12 @@ def environment(debug_mode):
aptly_conf.unlink()


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


@pytest.fixture()
def freeze(request):
"""Freeze to datetime.
Expand Down Expand Up @@ -204,7 +211,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 +227,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
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

56 changes: 56 additions & 0 deletions pyaptly/tests/publish-publish.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[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-%T"]
mirror = "fakerepo01"

[snapshot."fakerepo02-%T"]
mirror = "fakerepo02"

[snapshot."fakerepo01-%T".timestamp]
time = "00:00"

[snapshot."fakerepo02-%T".timestamp]
time = "00:00"
repeat-weekly = "sat"

[publish]
[[publish.fakerepo01]]
gpg-key = "6D79A810B9B7ABAE"
skip-contents = true
automatic-update = true
components = "main"
distribution = "main"
[[publish.fakerepo01.snapshots]]
name = "fakerepo01-%T"
timestamp = "current"
archive-on-update = "archived-fakerepo01-%T"


[[publish.fakerepo02]]
gpg-key = "6D79A810B9B7ABAE"
automatic-update = true
components = "main"
distribution = "main"
[[publish.fakerepo02.snapshots]]
name = "fakerepo02-%T"
timestamp = "current"
archive-on-update = "archived-fakerepo02-%T"

[[publish.fakerepo01-stable]]
publish = "fakerepo01 main"
gpg-key = "6D79A810B9B7ABAE"
automatic-update = true
components = "main"
distribution = "main"

12 changes: 12 additions & 0 deletions pyaptly/tests/publish-repo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[repo.centrify]
architectures = [ "amd64", "i386",]
distribution = "stable"
component = "main"

[publish]
[[publish.centrify]]
distribution = "latest"
repo = "centrify"
gpg-key = "6D79A810B9B7ABAE"
automatic-update = true
components = "main"
50 changes: 50 additions & 0 deletions pyaptly/tests/publish.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[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-%T"]
mirror = "fakerepo01"

[snapshot."fakerepo02-%T"]
mirror = "fakerepo02"

[snapshot."fakerepo01-%T".timestamp]
time = "00:00"

[snapshot."fakerepo02-%T".timestamp]
time = "00:00"
repeat-weekly = "sat"

[publish]
[[publish.fakerepo01]]
gpg-key = "6D79A810B9B7ABAE"
skip-contents = true
automatic-update = true
components = "main"
distribution = "main"
[[publish.fakerepo01.snapshots]]
name = "fakerepo01-%T"
timestamp = "current"
archive-on-update = "archived-fakerepo01-%T"


[[publish.fakerepo02]]
gpg-key = "6D79A810B9B7ABAE"
automatic-update = true
components = "main"
distribution = "main"
[[publish.fakerepo02.snapshots]]
name = "fakerepo02-%T"
timestamp = "current"
archive-on-update = "archived-fakerepo02-%T"


Loading

0 comments on commit c5c6ab2

Please sign in to comment.