forked from ansible/galaxy_ng
/
test_cli_flow.py
115 lines (92 loc) · 3.79 KB
/
test_cli_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""test_cli_flow.py - Tests against the basic CLI publish/install behaviors."""
import logging
import pytest
from ..utils import ansible_galaxy
from ..utils import get_client
from ..utils import get_collection_full_path
from ..utils import create_unused_namespace
from ..utils import CollectionInspector
from ..utils import build_collection
pytestmark = pytest.mark.qa # noqa: F821
logger = logging.getLogger(__name__)
@pytest.mark.cli
def test_publish_newer_version_collection(ansible_config, cleanup_collections, uncertifiedv2):
"""Test whether a newer version of collection can be installed after being published.
If the collection version was not certified the version to be installed
has to be specified during installation.
"""
# FIXME - ^^^ is that really possible?
v1 = uncertifiedv2[0]
v2 = uncertifiedv2[1]
# Install collection without version ...
install_pid = ansible_galaxy(
f"collection install {v1.namespace}.{v1.name}",
ansible_config=ansible_config("basic_user"),
cleanup=False,
check_retcode=False
)
assert install_pid.returncode == 0, install_pid.stderr
# Ensure the certified v1 version was installed ...
collection_path = get_collection_full_path(v1.namespace, v1.name)
ci = CollectionInspector(directory=collection_path)
assert ci.version == v1.version
assert ci.version != v2.version
@pytest.mark.cli
def test_publish_newer_certified_collection_version(
ansible_config,
cleanup_collections,
certifiedv2
):
"""Test whether a newer certified collection version can be installed.
If the collection version was certified the latest version will be installed.
"""
v1 = certifiedv2[0]
v2 = certifiedv2[1]
# Ensure v2 gets installed by default ...
ansible_galaxy(
f"collection install {v1.namespace}.{v1.name}", ansible_config=ansible_config("basic_user")
)
collection_path = get_collection_full_path(v1.namespace, v1.name)
ci = CollectionInspector(directory=collection_path)
assert ci.version != v1.version
assert ci.version == v2.version
@pytest.mark.cli
def test_publish_same_collection_version(ansible_config):
"""Test you cannot publish same collection version already published."""
api_client = get_client(ansible_config("admin"))
cnamespace = create_unused_namespace(api_client=api_client)
collection = build_collection(namespace=cnamespace)
ansible_galaxy(
f"collection publish {collection.filename}",
ansible_config=ansible_config("admin", namespace=collection.namespace)
)
p = ansible_galaxy(
f"collection publish {collection.filename}",
check_retcode=1,
ansible_config=ansible_config("admin", namespace=collection.namespace)
)
assert "Artifact already exists" in str(p.stderr)
@pytest.mark.cli
def test_publish_and_install_by_self(ansible_config, published, cleanup_collections):
"""A publishing user has the permission to install an uncertified version of their
own collection.
"""
ansible_galaxy(
f"collection install {published.namespace}.{published.name}:{published.version}",
ansible_config=ansible_config("basic_user"),
)
@pytest.mark.cli
@pytest.mark.cloud_only
def test_publish_and_expect_uncertified_hidden(ansible_config, published, cleanup_collections):
"""A discovering/consumer user has the permission to download a specific version of an
uncertified collection, but not an unspecified version range.
"""
ansible_galaxy(
f"collection install {published.namespace}.{published.name}",
check_retcode=0,
ansible_config=ansible_config("basic_user"),
)
ansible_galaxy(
f"collection install {published.namespace}.{published.name}:1.0.0",
ansible_config=ansible_config("basic_user"),
)