forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
584815d
commit aa77ff2
Showing
1,560 changed files
with
146,751 additions
and
342,952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/acrquery/azext_acrquery/tests/latest/mock_test_acr_query.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
import unittest | ||
from unittest import mock | ||
import json | ||
|
||
from azext_acrquery.query import ( | ||
create_query | ||
) | ||
|
||
from azure.cli.command_modules.acr._docker_utils import ( | ||
EMPTY_GUID, | ||
get_authorization_header, | ||
) | ||
|
||
from azure.cli.core.mock import DummyCli | ||
|
||
|
||
class AcrQueryCommandsTests(unittest.TestCase): | ||
|
||
@mock.patch('azext_acrquery.query.get_access_credentials', autospec=True) | ||
@mock.patch('requests.request', autospec=True) | ||
def test_acrquery(self, mock_requests_get, mock_get_access_credentials): | ||
cmd = self._setup_cmd() | ||
|
||
response = mock.MagicMock() | ||
response.headers = {} | ||
response.status_code = 200 | ||
response.content = json.dumps({'repositories': ['testrepo1', 'testrepo2']}).encode() | ||
mock_requests_get.return_value = response | ||
|
||
# Basic auth | ||
mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password' | ||
create_query(cmd, 'testregistry', 'get') | ||
mock_requests_get.assert_called_with( | ||
method='post', | ||
url='https://testregistry.azurecr.io/acr/v1/_metadata/_query', | ||
headers=get_authorization_header('username', 'password'), | ||
params=None, | ||
json={ | ||
'query': 'get' | ||
}, | ||
timeout=300, | ||
verify=mock.ANY) | ||
|
||
# Bearer auth | ||
mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' | ||
create_query(cmd, 'testregistry', 'get') | ||
mock_requests_get.assert_called_with( | ||
method='post', | ||
url='https://testregistry.azurecr.io/acr/v1/_metadata/_query', | ||
headers=get_authorization_header(EMPTY_GUID, 'password'), | ||
params=None, | ||
json={ | ||
'query': 'get' | ||
}, | ||
timeout=300, | ||
verify=mock.ANY) | ||
|
||
# Filter by repository | ||
mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' | ||
create_query(cmd, 'testregistry', 'get', repository='repository') | ||
mock_requests_get.assert_called_with( | ||
method='post', | ||
url='https://testregistry.azurecr.io/acr/v1/repository/_metadata/_query', | ||
headers=get_authorization_header(EMPTY_GUID, 'password'), | ||
params=None, | ||
json={ | ||
'query': 'get' | ||
}, | ||
timeout=300, | ||
verify=mock.ANY) | ||
|
||
# Request with skip token | ||
mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password' | ||
create_query(cmd, 'testregistry', 'get', skip_token='12345678') | ||
mock_requests_get.assert_called_with( | ||
method='post', | ||
url='https://testregistry.azurecr.io/acr/v1/repository/_metadata/_query', | ||
headers=get_authorization_header(EMPTY_GUID, 'password'), | ||
params=None, | ||
json={ | ||
'query': 'get', | ||
'options': { | ||
'$skipToken': '12345678' | ||
} | ||
}, | ||
timeout=300, | ||
verify=mock.ANY) | ||
|
||
def _setup_cmd(self): | ||
cmd = mock.MagicMock() | ||
cmd.cli_ctx = DummyCli() | ||
mock_sku = mock.MagicMock() | ||
mock_sku.classic.value = 'Classic' | ||
mock_sku.basic.value = 'Basic' | ||
cmd.get_models.return_value = mock_sku | ||
return cmd |
Oops, something went wrong.