Skip to content

Commit

Permalink
[Container Registry] Test fixes (Azure#17847)
Browse files Browse the repository at this point in the history
Fixing the environment variables in tests to work with the pipeline.
  • Loading branch information
seankane-msft authored Apr 7, 2021
1 parent 4e42772 commit 379a23f
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 127 deletions.
4 changes: 2 additions & 2 deletions sdk/containerregistry/azure-containerregistry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)]<!--[package]--> | [API reference documentation]<!--[docs]--> | [REST API documentation][rest_docs] | [Product documentation][product_docs]
[Source code][source] | [Package (Pypi)][package] | [API reference documentation]<!--[docs]--> | [REST API documentation][rest_docs] | [Product documentation][product_docs]

## Getting started

Expand Down Expand Up @@ -99,7 +99,7 @@ additional questions or comments.

<!-- LINKS -->
[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/
<!-- [docs]: https://docs.microsoft.com/python/api/overview/azure/container-registry?view=azure-python-preview -->
[rest_docs]: https://docs.microsoft.com/rest/api/containerregistry/
[product_docs]: https://docs.microsoft.com/azure/container-registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading

0 comments on commit 379a23f

Please sign in to comment.