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
|
"""
GitLab API: https://docs.gitlab.com/ee/api/project_container_registry_protection_rules.html
"""
import pytest
import responses
from gitlab.v4.objects import ProjectRegistryProtectionRule
protected_registry_content = {
"id": 1,
"project_id": 7,
"repository_path_pattern": "test/image",
"minimum_access_level_for_push": "maintainer",
"minimum_access_level_for_delete": "maintainer",
}
@pytest.fixture
def resp_list_protected_registries():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/registry/protection/rules",
json=[protected_registry_content],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_create_protected_registry():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.POST,
url="http://localhost/api/v4/projects/1/registry/protection/rules",
json=protected_registry_content,
content_type="application/json",
status=201,
)
yield rsps
@pytest.fixture
def resp_update_protected_registry():
updated_content = protected_registry_content.copy()
updated_content["repository_path_pattern"] = "abc*"
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.PATCH,
url="http://localhost/api/v4/projects/1/registry/protection/rules/1",
json=updated_content,
content_type="application/json",
status=200,
)
yield rsps
def test_list_project_protected_registries(project, resp_list_protected_registries):
protected_registry = project.registry_protection_rules.list()[0]
assert isinstance(protected_registry, ProjectRegistryProtectionRule)
assert protected_registry.repository_path_pattern == "test/image"
def test_create_project_protected_registry(project, resp_create_protected_registry):
protected_registry = project.registry_protection_rules.create(
{
"repository_path_pattern": "test/image",
"minimum_access_level_for_push": "maintainer",
}
)
assert isinstance(protected_registry, ProjectRegistryProtectionRule)
assert protected_registry.repository_path_pattern == "test/image"
def test_update_project_protected_registry(project, resp_update_protected_registry):
updated = project.registry_protection_rules.update(
1, {"repository_path_pattern": "abc*"}
)
assert updated["repository_path_pattern"] == "abc*"
|