def test_repository_list(self, mock_requests_get,
                             mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_repositories = json.dumps({
            'repositories': ['testrepo1', 'testrepo2']
        }).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_repositories
        mock_requests_get.return_value = response

        # List repositories using Basic auth
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'
        acr_repository_list(cmd, 'testregistry')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_catalog',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)

        # List repositories using Bearer auth
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', None, 'password'
        acr_repository_list(cmd, 'testregistry')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_catalog',
            headers=_get_authorization_header(None, 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)
    def test_repository_list(self, mock_requests_get, mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_repositories = json.dumps({'repositories': ['testrepo1', 'testrepo2']}).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_repositories
        mock_requests_get.return_value = response

        # List repositories using Basic auth
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'
        acr_repository_list(cmd, 'testregistry')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_catalog',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)

        # List repositories using Bearer auth
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', None, 'password'
        acr_repository_list(cmd, 'testregistry')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_catalog',
            headers=_get_authorization_header(None, 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)
    def test_repository_show_manifests(self, mock_requests_get,
                                       mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_manifests = json.dumps({
            'manifests': [{
                "digest":
                "sha256:b972dda797ef258a7ea5738eb2109778c2bac6a99d1033e6c9f9bdb4fbd196e7",
                "tags": ["testtag1", "testtag2"],
                "timestamp": "2017-07-05T16:02:29Z"
            }, {
                "digest":
                "sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7",
                "tags": ["testtag3"],
                "timestamp": "2017-07-05T16:02:29Z"
            }]
        }).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_manifests
        mock_requests_get.return_value = response
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_acr/testrepository/manifests/list',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)
    def test_repository_show_manifests(self, mock_requests_get, mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_manifests = json.dumps({'manifests': [
            {
                "digest": "sha256:b972dda797ef258a7ea5738eb2109778c2bac6a99d1033e6c9f9bdb4fbd196e7",
                "tags": [
                    "testtag1",
                    "testtag2"
                ],
                "timestamp": "2017-07-05T16:02:29Z"
            },
            {
                "digest": "sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7",
                "tags": [
                    "testtag3"
                ],
                "timestamp": "2017-07-05T16:02:29Z"
            }]}).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_manifests
        mock_requests_get.return_value = response
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/_acr/testrepository/manifests/list',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)
Exemple #5
0
    def test_repository_show_tags(self, mock_requests_get, mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_tags = json.dumps({'tags': ['testtag1', 'testtag2']}).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_tags
        mock_requests_get.return_value = response
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_tags(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/testrepository/tags/list',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20))
    def test_repository_show_tags(self, mock_requests_get, mock_get_access_credentials):
        cmd = mock.MagicMock()
        cmd.cli_ctx = TestCli()
        encoded_tags = json.dumps({'tags': ['testtag1', 'testtag2']}).encode()

        response = mock.MagicMock()
        response.headers = {}
        response.status_code = 200
        response.content = encoded_tags
        mock_requests_get.return_value = response
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_tags(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            'https://testregistry.azurecr.io/v2/testrepository/tags/list',
            headers=_get_authorization_header('username', 'password'),
            params=_get_pagination_params(20),
            verify=mock.ANY)