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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import pytest
from azure.core.exceptions import ClientAuthenticationError
from azure.core.paging import ItemPaged
from azure.containerregistry import (
ArtifactTagProperties,
RepositoryProperties,
ArtifactManifestProperties,
ContainerRegistryClient,
)
from testcase import ContainerRegistryTestClass, is_public_endpoint
from constants import HELLO_WORLD
from preparer import acr_preparer
from devtools_testutils import recorded_by_proxy
class TestContainerRegistryClient(ContainerRegistryTestClass):
@acr_preparer()
@recorded_by_proxy
def test_list_repository_names(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
repositories = client.list_repository_names()
assert isinstance(repositories, ItemPaged)
count = 0
prev = None
for repo in repositories:
count += 1
assert isinstance(repo, str)
assert prev != repo
prev = repo
assert count > 0
@acr_preparer()
@recorded_by_proxy
def test_list_repository_names_by_page(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
results_per_page = 2
total_pages = 0
repository_pages = client.list_repository_names(results_per_page=results_per_page)
prev = None
for page in repository_pages.by_page():
page_count = 0
for repo in page:
assert isinstance(repo, str)
assert prev != repo
prev = repo
page_count += 1
assert page_count <= results_per_page
total_pages += 1
assert total_pages >= 1
@acr_preparer()
@recorded_by_proxy
def test_get_repository_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
properties = client.get_repository_properties(HELLO_WORLD)
assert isinstance(properties, RepositoryProperties)
assert properties.name == HELLO_WORLD
@acr_preparer()
@recorded_by_proxy
def test_list_manifest_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
count = 0
for manifest in client.list_manifest_properties(HELLO_WORLD):
assert isinstance(manifest, ArtifactManifestProperties)
count += 1
assert count > 0
@acr_preparer()
@recorded_by_proxy
def test_get_manifest_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
registry_artifact = client.get_manifest_properties(HELLO_WORLD, "latest")
assert isinstance(registry_artifact, ArtifactManifestProperties)
assert "latest" in registry_artifact.tags
assert registry_artifact.repository_name == HELLO_WORLD
@acr_preparer()
@recorded_by_proxy
def test_list_tag_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
count = 0
for tag in client.list_tag_properties(HELLO_WORLD):
count += 1
assert isinstance(tag, ArtifactTagProperties)
assert count > 0
@acr_preparer()
@recorded_by_proxy
def test_delete_repository(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
with pytest.raises(ClientAuthenticationError):
client.delete_repository(HELLO_WORLD)
@acr_preparer()
@recorded_by_proxy
def test_delete_tag(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
with pytest.raises(ClientAuthenticationError):
client.delete_tag(HELLO_WORLD, "latest")
@acr_preparer()
@recorded_by_proxy
def test_delete_manifest(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
assert client._credential is None
with pytest.raises(ClientAuthenticationError):
client.delete_manifest(HELLO_WORLD, "latest")
@acr_preparer()
@recorded_by_proxy
def test_update_repository_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
properties = client.get_repository_properties(HELLO_WORLD)
with pytest.raises(ClientAuthenticationError):
client.update_repository_properties(HELLO_WORLD, properties, can_delete=True)
@acr_preparer()
@recorded_by_proxy
def test_update_tag_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
properties = client.get_tag_properties(HELLO_WORLD, "latest")
with pytest.raises(ClientAuthenticationError):
client.update_tag_properties(HELLO_WORLD, "latest", properties, can_delete=True)
@acr_preparer()
@recorded_by_proxy
def test_update_manifest_properties(self, containerregistry_anonregistry_endpoint):
if not is_public_endpoint(containerregistry_anonregistry_endpoint):
pytest.skip("Not a public endpoint")
with self.create_anon_client(containerregistry_anonregistry_endpoint) as client:
properties = client.get_manifest_properties(HELLO_WORLD, "latest")
with pytest.raises(ClientAuthenticationError):
client.update_manifest_properties(HELLO_WORLD, "latest", properties, can_delete=True)
def test_set_api_version():
containerregistry_endpoint = "https://fake_url.azurecr.io"
with ContainerRegistryClient(endpoint=containerregistry_endpoint, audience="https://microsoft.com") as client:
assert client._client._config.api_version == "2021-07-01"
with ContainerRegistryClient(
endpoint=containerregistry_endpoint, audience="https://microsoft.com", api_version="2019-08-15-preview"
) as client:
assert client._client._config.api_version == "2019-08-15-preview"
with pytest.raises(ValueError):
with ContainerRegistryClient(
endpoint=containerregistry_endpoint, audience="https://microsoft.com", api_version="2019-08-15"
) as client:
pass
|