diff --git a/sdk/containerregistry/azure-containerregistry/README.md b/sdk/containerregistry/azure-containerregistry/README.md index 9afe3c018895..b90daef0275c 100644 --- a/sdk/containerregistry/azure-containerregistry/README.md +++ b/sdk/containerregistry/azure-containerregistry/README.md @@ -9,7 +9,7 @@ Use the client library for Azure Container Registry to: - Set read/write/delete properties on registry items - Delete images and artifacts, repositories and tags -[Source code][source] | [Package (Pypi)] | [API reference documentation] | [REST API documentation][rest_docs] | [Product documentation][product_docs] +[Source code][source] | [Package (Pypi)][package] | [API reference documentation] | [REST API documentation][rest_docs] | [Product documentation][product_docs] ## Getting started @@ -99,7 +99,7 @@ additional questions or comments. [source]: https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/containerregistry/azure-containerregistry -[package]: https://pypi.org/azure-containerregistry +[package]: https://pypi.org/project/azure-containerregistry/ [rest_docs]: https://docs.microsoft.com/rest/api/containerregistry/ [product_docs]: https://docs.microsoft.com/azure/container-registry diff --git a/sdk/containerregistry/azure-containerregistry/samples/README.md b/sdk/containerregistry/azure-containerregistry/samples/README.md index bc3ed3358af6..450b78446598 100644 --- a/sdk/containerregistry/azure-containerregistry/samples/README.md +++ b/sdk/containerregistry/azure-containerregistry/samples/README.md @@ -10,7 +10,7 @@ products: urlFragment: containerregistry-samples --- -These code samples show common scenario operations with the Azure Container Registry client library. The code samples assume an environment variable `CONTAINERREGISTRY_ENDPOINT` set including the name of the login server and the `https://` prefix. For more information on using AAD with Azure Container Registry, please see the service's [Authentication Overview](https://docs.microsoft.com/azure/container-registry/container-registry-authentication). +These code samples show common scenario operations with the Azure Container Registry client library. The code samples assume an environment variable `CONTAINERREGISTRY_ENDPOINT` is set, which includes the name of the login server and the `https://` prefix. For more information on using AAD with Azure Container Registry, please see the service's [Authentication Overview](https://docs.microsoft.com/azure/container-registry/container-registry-authentication). The async versions of the samples require Python 3.6 or later. diff --git a/sdk/containerregistry/azure-containerregistry/tests/preparer.py b/sdk/containerregistry/azure-containerregistry/tests/preparer.py index fce8db64712e..aeefbdfd6713 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/preparer.py +++ b/sdk/containerregistry/azure-containerregistry/tests/preparer.py @@ -10,6 +10,6 @@ acr_preparer = functools.partial( PowerShellPreparer, "containerregistry", - containerregistry_baseurl="fake_url.azurecr.io", + containerregistry_endpoint="fake_url.azurecr.io", containerregistry_resource_group="fake_rg", ) diff --git a/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client.py b/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client.py index b3b859dea6aa..be496d26adb6 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client.py +++ b/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client.py @@ -23,8 +23,8 @@ class TestContainerRegistryClient(ContainerRegistryTestClass): @acr_preparer() - def test_list_repositories(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + def test_list_repositories(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) repositories = client.list_repositories() assert isinstance(repositories, ItemPaged) @@ -40,8 +40,8 @@ def test_list_repositories(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_list_repositories_by_page(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + def test_list_repositories_by_page(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) results_per_page = 2 total_pages = 0 @@ -61,12 +61,12 @@ def test_list_repositories_by_page(self, containerregistry_baseurl): assert total_pages > 1 @acr_preparer() - def test_delete_repository(self, containerregistry_baseurl, containerregistry_resource_group): + def test_delete_repository(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") self._import_tag_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=repository + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repository ) - client = self.create_registry_client(containerregistry_baseurl) + client = self.create_registry_client(containerregistry_endpoint) result = client.delete_repository(repository) assert isinstance(result, DeletedRepositoryResult) @@ -80,16 +80,16 @@ def test_delete_repository(self, containerregistry_baseurl, containerregistry_re raise ValueError("Repository not deleted") @acr_preparer() - def test_delete_repository_does_not_exist(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + def test_delete_repository_does_not_exist(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) with pytest.raises(ResourceNotFoundError): deleted_result = client.delete_repository("not_real_repo") @acr_preparer() - def test_transport_closed_only_once(self, containerregistry_baseurl): + def test_transport_closed_only_once(self, containerregistry_endpoint): transport = RequestsTransport() - client = self.create_registry_client(containerregistry_baseurl, transport=transport) + client = self.create_registry_client(containerregistry_endpoint, transport=transport) with client: for r in client.list_repositories(): pass diff --git a/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client_async.py b/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client_async.py index 7d6bd5b2c4dc..714fbab26708 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client_async.py +++ b/sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client_async.py @@ -24,8 +24,8 @@ class TestContainerRegistryClient(AsyncContainerRegistryTestClass): @acr_preparer() - async def test_list_repositories(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + async def test_list_repositories(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) repositories = client.list_repositories() @@ -40,8 +40,8 @@ async def test_list_repositories(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_list_repositories_by_page(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + async def test_list_repositories_by_page(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) results_per_page = 2 total_pages = 0 @@ -61,12 +61,12 @@ async def test_list_repositories_by_page(self, containerregistry_baseurl): assert total_pages >= 1 @acr_preparer() - async def test_delete_repository(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_delete_repository(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") self._import_tag_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=repository + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repository ) - client = self.create_registry_client(containerregistry_baseurl) + client = self.create_registry_client(containerregistry_endpoint) result = await client.delete_repository(repository) assert isinstance(result, DeletedRepositoryResult) @@ -80,16 +80,16 @@ async def test_delete_repository(self, containerregistry_baseurl, containerregis raise ValueError("Repository not deleted") @acr_preparer() - async def test_delete_repository_does_not_exist(self, containerregistry_baseurl): - client = self.create_registry_client(containerregistry_baseurl) + async def test_delete_repository_does_not_exist(self, containerregistry_endpoint): + client = self.create_registry_client(containerregistry_endpoint) with pytest.raises(ResourceNotFoundError): deleted_result = await client.delete_repository("not_real_repo") @acr_preparer() - async def test_transport_closed_only_once(self, containerregistry_baseurl): + async def test_transport_closed_only_once(self, containerregistry_endpoint): transport = AioHttpTransport() - client = self.create_registry_client(containerregistry_baseurl, transport=transport) + client = self.create_registry_client(containerregistry_endpoint, transport=transport) async with client: async for r in client.list_repositories(): pass diff --git a/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client.py b/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client.py index 8e8e4638a124..df7b7e6cd3dc 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client.py +++ b/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client.py @@ -29,14 +29,14 @@ class TestContainerRepositoryClient(ContainerRegistryTestClass): @acr_preparer() - def test_delete_tag(self, containerregistry_baseurl, containerregistry_resource_group): + def test_delete_tag(self, containerregistry_endpoint, containerregistry_resource_group): repo = self.get_resource_name("repo") tag = self.get_resource_name("tag") self._import_tag_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=repo, tag=tag + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repo, tag=tag ) - client = self.create_repository_client(containerregistry_baseurl, repo) + client = self.create_repository_client(containerregistry_endpoint, repo) tag_props = client.get_tag_properties(tag) assert tag_props is not None @@ -47,22 +47,22 @@ def test_delete_tag(self, containerregistry_baseurl, containerregistry_resource_ client.get_tag_properties(tag) @acr_preparer() - def test_delete_tag_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, "hello-world") + def test_delete_tag_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, "hello-world") with pytest.raises(ResourceNotFoundError): client.delete_tag(TO_BE_DELETED) @acr_preparer() - def test_get_properties(self, containerregistry_baseurl): - repo_client = self.create_repository_client(containerregistry_baseurl, "hello-world") + def test_get_properties(self, containerregistry_endpoint): + repo_client = self.create_repository_client(containerregistry_endpoint, "hello-world") properties = repo_client.get_properties() assert isinstance(properties.content_permissions, ContentPermissions) @acr_preparer() - def test_get_tag(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_get_tag(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) tag = client.get_tag_properties("latest") @@ -70,8 +70,8 @@ def test_get_tag(self, containerregistry_baseurl): assert isinstance(tag, TagProperties) @acr_preparer() - def test_list_registry_artifacts(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_registry_artifacts(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) count = 0 for artifact in client.list_registry_artifacts(): @@ -86,8 +86,8 @@ def test_list_registry_artifacts(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_list_registry_artifacts_by_page(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_registry_artifacts_by_page(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) results_per_page = 2 pages = client.list_registry_artifacts(results_per_page=results_per_page) @@ -102,8 +102,8 @@ def test_list_registry_artifacts_by_page(self, containerregistry_baseurl): assert page_count >= 1 @acr_preparer() - def test_list_registry_artifacts_descending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_registry_artifacts_descending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -116,8 +116,8 @@ def test_list_registry_artifacts_descending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_list_registry_artifacts_ascending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_registry_artifacts_ascending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -130,8 +130,8 @@ def test_list_registry_artifacts_ascending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_get_registry_artifact_properties(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_get_registry_artifact_properties(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) properties = client.get_registry_artifact_properties("latest") @@ -140,8 +140,8 @@ def test_get_registry_artifact_properties(self, containerregistry_baseurl): assert isinstance(properties.last_updated_on, datetime) @acr_preparer() - def test_list_tags(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_tags(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) tags = client.list_tags() assert isinstance(tags, ItemPaged) @@ -152,8 +152,8 @@ def test_list_tags(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_list_tags_by_page(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_tags_by_page(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) results_per_page = 2 @@ -169,8 +169,8 @@ def test_list_tags_by_page(self, containerregistry_baseurl): assert page_count >= 1 @acr_preparer() - def test_list_tags_descending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_tags_descending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -183,8 +183,8 @@ def test_list_tags_descending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - def test_list_tags_ascending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + def test_list_tags_ascending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -198,17 +198,17 @@ def test_list_tags_ascending(self, containerregistry_baseurl): @pytest.mark.live_test_only # Recordings error, recieves more than 100 headers, not that many present @acr_preparer() - def test_set_tag_properties(self, containerregistry_baseurl, containerregistry_resource_group): + def test_set_tag_properties(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") tag_identifier = self.get_resource_name("tag") self.import_repo_to_be_deleted( - containerregistry_baseurl, + containerregistry_endpoint, resource_group=containerregistry_resource_group, tag=tag_identifier, repository=repository, ) - client = self.create_repository_client(containerregistry_baseurl, repository) + client = self.create_repository_client(containerregistry_endpoint, repository) tag_props = client.get_tag_properties(tag_identifier) permissions = tag_props.content_permissions @@ -230,25 +230,25 @@ def test_set_tag_properties(self, containerregistry_baseurl, containerregistry_r @pytest.mark.live_test_only # Recordings error, recieves more than 100 headers, not that many present @acr_preparer() - def test_set_tag_properties_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.get_resource_name("repo")) + def test_set_tag_properties_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.get_resource_name("repo")) with pytest.raises(ResourceNotFoundError): client.set_tag_properties("does_not_exist", ContentPermissions(can_delete=False)) @pytest.mark.live_test_only # Recordings error, recieves more than 100 headers, not that many present @acr_preparer() - def test_set_manifest_properties(self, containerregistry_baseurl, containerregistry_resource_group): + def test_set_manifest_properties(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo_set") tag_identifier = self.get_resource_name("tag") self.import_repo_to_be_deleted( - containerregistry_baseurl, + containerregistry_endpoint, resource_group=containerregistry_resource_group, tag=tag_identifier, repository=repository, ) - client = self.create_repository_client(containerregistry_baseurl, repository) + client = self.create_repository_client(containerregistry_endpoint, repository) for artifact in client.list_registry_artifacts(): permissions = artifact.content_permissions @@ -272,23 +272,23 @@ def test_set_manifest_properties(self, containerregistry_baseurl, containerregis @pytest.mark.live_test_only # Recordings error, recieves more than 100 headers, not that many present @acr_preparer() - def test_set_manifest_properties_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.get_resource_name("repo")) + def test_set_manifest_properties_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.get_resource_name("repo")) with pytest.raises(ResourceNotFoundError): client.set_manifest_properties("sha256:abcdef", ContentPermissions(can_delete=False)) @acr_preparer() - def test_delete_repository(self, containerregistry_baseurl, containerregistry_resource_group): + def test_delete_repository(self, containerregistry_endpoint, containerregistry_resource_group): self.import_repo_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=TO_BE_DELETED + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=TO_BE_DELETED ) - reg_client = self.create_registry_client(containerregistry_baseurl) + reg_client = self.create_registry_client(containerregistry_endpoint) existing_repos = list(reg_client.list_repositories()) assert TO_BE_DELETED in existing_repos - repo_client = self.create_repository_client(containerregistry_baseurl, TO_BE_DELETED) + repo_client = self.create_repository_client(containerregistry_endpoint, TO_BE_DELETED) result = repo_client.delete() assert isinstance(result, DeletedRepositoryResult) assert result.deleted_registry_artifact_digests is not None @@ -299,19 +299,19 @@ def test_delete_repository(self, containerregistry_baseurl, containerregistry_re assert TO_BE_DELETED not in existing_repos @acr_preparer() - def test_delete_repository_doesnt_exist(self, containerregistry_baseurl): - repo_client = self.create_repository_client(containerregistry_baseurl, DOES_NOT_EXIST) + def test_delete_repository_doesnt_exist(self, containerregistry_endpoint): + repo_client = self.create_repository_client(containerregistry_endpoint, DOES_NOT_EXIST) with pytest.raises(ResourceNotFoundError): repo_client.delete() @acr_preparer() - def test_delete_registry_artifact(self, containerregistry_baseurl, containerregistry_resource_group): + def test_delete_registry_artifact(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") self.import_repo_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=repository + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repository ) - repo_client = self.create_repository_client(containerregistry_baseurl, repository) + repo_client = self.create_repository_client(containerregistry_endpoint, repository) count = 0 for artifact in repo_client.list_registry_artifacts(): diff --git a/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client_async.py b/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client_async.py index 2a89d8e203cb..15a1d6cd4f8e 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client_async.py +++ b/sdk/containerregistry/azure-containerregistry/tests/test_container_repository_client_async.py @@ -27,8 +27,8 @@ class TestContainerRepositoryClient(AsyncContainerRegistryTestClass): @acr_preparer() - async def test_list_registry_artifacts(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_registry_artifacts(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) async for artifact in client.list_registry_artifacts(): assert artifact is not None @@ -39,8 +39,8 @@ async def test_list_registry_artifacts(self, containerregistry_baseurl): assert isinstance(artifact.last_updated_on, datetime) @acr_preparer() - async def test_list_registry_artifacts_by_page(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_registry_artifacts_by_page(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) results_per_page = 2 pages = client.list_registry_artifacts(results_per_page=results_per_page) @@ -55,8 +55,8 @@ async def test_list_registry_artifacts_by_page(self, containerregistry_baseurl): assert page_count >= 1 @acr_preparer() - async def test_list_tags(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_tags(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) tags = client.list_tags() assert isinstance(tags, AsyncItemPaged) @@ -67,8 +67,8 @@ async def test_list_tags(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_list_tags_by_page(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_tags_by_page(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) results_per_page = 2 @@ -84,8 +84,8 @@ async def test_list_tags_by_page(self, containerregistry_baseurl): assert page_count >= 1 @acr_preparer() - async def test_list_tags_descending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_tags_descending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) # TODO: This is giving time in ascending order tags = client.list_tags(order_by=TagOrderBy.LAST_UPDATE_TIME_DESCENDING) @@ -102,16 +102,16 @@ async def test_list_tags_descending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_delete_tag(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_delete_tag(self, containerregistry_endpoint, containerregistry_resource_group): repo = self.get_resource_name("repo") self._import_tag_to_be_deleted( - containerregistry_baseurl, + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repo, tag=TO_BE_DELETED, ) - client = self.create_repository_client(containerregistry_baseurl, repo) + client = self.create_repository_client(containerregistry_endpoint, repo) tag = await client.get_tag_properties(TO_BE_DELETED) assert tag is not None @@ -123,25 +123,25 @@ async def test_delete_tag(self, containerregistry_baseurl, containerregistry_res await client.get_tag_properties(TO_BE_DELETED) @acr_preparer() - async def test_delete_tag_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, "hello-world") + async def test_delete_tag_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, "hello-world") with pytest.raises(ResourceNotFoundError): await client.delete_tag(TO_BE_DELETED) @acr_preparer() - async def test_delete_repository(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_delete_repository(self, containerregistry_endpoint, containerregistry_resource_group): self.import_repo_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=TO_BE_DELETED + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=TO_BE_DELETED ) - reg_client = self.create_registry_client(containerregistry_baseurl) + reg_client = self.create_registry_client(containerregistry_endpoint) existing_repos = [] async for repo in reg_client.list_repositories(): existing_repos.append(repo) assert TO_BE_DELETED in existing_repos - repo_client = self.create_repository_client(containerregistry_baseurl, TO_BE_DELETED) + repo_client = self.create_repository_client(containerregistry_endpoint, TO_BE_DELETED) result = await repo_client.delete() assert isinstance(result, DeletedRepositoryResult) assert result.deleted_registry_artifact_digests is not None @@ -154,21 +154,21 @@ async def test_delete_repository(self, containerregistry_baseurl, containerregis assert TO_BE_DELETED not in existing_repos @acr_preparer() - async def test_delete_repository_doesnt_exist(self, containerregistry_baseurl): + async def test_delete_repository_doesnt_exist(self, containerregistry_endpoint): DOES_NOT_EXIST = "does_not_exist" - repo_client = self.create_repository_client(containerregistry_baseurl, DOES_NOT_EXIST) + repo_client = self.create_repository_client(containerregistry_endpoint, DOES_NOT_EXIST) with pytest.raises(ResourceNotFoundError): await repo_client.delete() @acr_preparer() - async def test_delete_registry_artifact(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_delete_registry_artifact(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") self.import_repo_to_be_deleted( - containerregistry_baseurl, resource_group=containerregistry_resource_group, repository=repository + containerregistry_endpoint, resource_group=containerregistry_resource_group, repository=repository ) - repo_client = self.create_repository_client(containerregistry_baseurl, repository) + repo_client = self.create_repository_client(containerregistry_endpoint, repository) count = 0 async for artifact in repo_client.list_registry_artifacts(): @@ -185,17 +185,17 @@ async def test_delete_registry_artifact(self, containerregistry_baseurl, contain assert len(artifacts) == count - 1 @acr_preparer() - async def test_set_tag_properties(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_set_tag_properties(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo") tag_identifier = self.get_resource_name("tag") self.import_repo_to_be_deleted( - containerregistry_baseurl, + containerregistry_endpoint, resource_group=containerregistry_resource_group, tag=tag_identifier, repository=repository, ) - client = self.create_repository_client(containerregistry_baseurl, repository) + client = self.create_repository_client(containerregistry_endpoint, repository) tag_props = await client.get_tag_properties(tag_identifier) permissions = tag_props.content_permissions @@ -216,24 +216,24 @@ async def test_set_tag_properties(self, containerregistry_baseurl, containerregi assert not received.content_permissions.can_delete @acr_preparer() - async def test_set_tag_properties_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.get_resource_name("repo")) + async def test_set_tag_properties_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.get_resource_name("repo")) with pytest.raises(ResourceNotFoundError): await client.set_tag_properties("does_not_exist", ContentPermissions(can_delete=False)) @acr_preparer() - async def test_set_manifest_properties(self, containerregistry_baseurl, containerregistry_resource_group): + async def test_set_manifest_properties(self, containerregistry_endpoint, containerregistry_resource_group): repository = self.get_resource_name("repo_set_mani") tag_identifier = self.get_resource_name("tag") self.import_repo_to_be_deleted( - containerregistry_baseurl, + containerregistry_endpoint, resource_group=containerregistry_resource_group, tag=tag_identifier, repository=repository, ) - client = self.create_repository_client(containerregistry_baseurl, repository) + client = self.create_repository_client(containerregistry_endpoint, repository) async for artifact in client.list_registry_artifacts(): permissions = artifact.content_permissions @@ -255,15 +255,15 @@ async def test_set_manifest_properties(self, containerregistry_baseurl, containe break @acr_preparer() - async def test_set_manifest_properties_does_not_exist(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.get_resource_name("repo")) + async def test_set_manifest_properties_does_not_exist(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.get_resource_name("repo")) with pytest.raises(ResourceNotFoundError): await client.set_manifest_properties("sha256:abcdef", ContentPermissions(can_delete=False)) @acr_preparer() - async def test_list_tags_descending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_tags_descending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -276,8 +276,8 @@ async def test_list_tags_descending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_list_tags_ascending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_tags_ascending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -290,8 +290,8 @@ async def test_list_tags_ascending(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_list_registry_artifacts(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_registry_artifacts(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) count = 0 async for artifact in client.list_registry_artifacts(): @@ -306,8 +306,8 @@ async def test_list_registry_artifacts(self, containerregistry_baseurl): assert count > 0 @acr_preparer() - async def test_list_registry_artifacts_descending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_registry_artifacts_descending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 @@ -322,8 +322,8 @@ async def test_list_registry_artifacts_descending(self, containerregistry_baseur assert count > 0 @acr_preparer() - async def test_list_registry_artifacts_ascending(self, containerregistry_baseurl): - client = self.create_repository_client(containerregistry_baseurl, self.repository) + async def test_list_registry_artifacts_ascending(self, containerregistry_endpoint): + client = self.create_repository_client(containerregistry_endpoint, self.repository) prev_last_updated_on = None count = 0 diff --git a/sdk/containerregistry/azure-containerregistry/tests/testcase.py b/sdk/containerregistry/azure-containerregistry/tests/testcase.py index 13fd9a7138c4..1979afe3e7ed 100644 --- a/sdk/containerregistry/azure-containerregistry/tests/testcase.py +++ b/sdk/containerregistry/azure-containerregistry/tests/testcase.py @@ -76,6 +76,9 @@ def process_response(self, response): body = response["body"] try: + if body["string"] == b'': + return response + refresh = json.loads(body["string"]) if "refresh_token" in refresh.keys(): refresh["refresh_token"] = REDACTED @@ -83,7 +86,9 @@ def process_response(self, response): if "access_token" in refresh.keys(): refresh["access_token"] = REDACTED body["string"] = json.dumps(refresh) - + except ValueError: + # Python 2.7 doesn't have the below error + pass except json.decoder.JSONDecodeError: pass @@ -172,16 +177,22 @@ def _clean_up(self, endpoint): reg_client = self.create_registry_client(endpoint) for repo in reg_client.list_repositories(): - repo_client = self.create_repository_client(endpoint, repo) - for tag in repo_client.list_tags(): - - p = tag.content_permissions - p.can_delete = True - repo_client.set_tag_properties(tag.digest, p) - - self.sleep(10) - - reg_client.delete_repository(repo) + if repo.startswith("repo"): + repo_client = self.create_repository_client(endpoint, repo) + for tag in repo_client.list_tags(): + + try: + p = tag.content_permissions + p.can_delete = True + repo_client.set_tag_properties(tag.digest, p) + except: + pass + + self.sleep(10) + try: + reg_client.delete_repository(repo) + except: + pass def get_credential(self): if self.is_live: