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 #3
0
    def test_repository_show_manifests(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({
            'manifests': [{
                'digest':
                'sha256:b972dda797ef258a7ea5738eb2109778c2bac6a99d1033e6c9f9bdb4fbd196e7',
                'tags': ['testtag1', 'testtag2']
            }, {
                'digest':
                'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7',
                'tags': ['testtag3']
            }]
        }).encode()
        mock_requests_get.return_value = response

        # Show manifests using Basic auth without detail
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            method='get',
            url=
            'https://testregistry.azurecr.io/acr/v1/testrepository/_manifests',
            headers=get_authorization_header('username', 'password'),
            params={
                'n': 100,
                'orderby': None
            },
            json=None,
            timeout=300,
            verify=mock.ANY)

        # Show manifests using Bearer auth with detail
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password'

        acr_repository_show_manifests(cmd,
                                      'testregistry',
                                      'testrepository',
                                      top=10,
                                      orderby='time_desc',
                                      detail=True)
        mock_requests_get.assert_called_with(
            method='get',
            url=
            'https://testregistry.azurecr.io/acr/v1/testrepository/_manifests',
            headers=get_authorization_header(EMPTY_GUID, 'password'),
            params={
                'n': 10,
                'orderby': 'timedesc'
            },
            json=None,
            timeout=300,
            verify=mock.ANY)
    def test_repository_show_manifests(self, mock_requests_get, mock_get_access_credentials, mock_get_registry_by_name):
        cmd = mock.MagicMock()
        cmd.cli_ctx = DummyCli()
        encoded_manifests = json.dumps({'manifests': [
            {
                'digest': 'sha256:b972dda797ef258a7ea5738eb2109778c2bac6a99d1033e6c9f9bdb4fbd196e7',
                'tags': ['testtag1', 'testtag2']
            },
            {
                'digest': 'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7',
                'tags': ['testtag3']
            }]}).encode()

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

        # Show manifests using Basic auth without detail
        mock_get_registry_by_name.return_value = Registry(location='westus', sku=Sku(name='Standard')), 'testrg'
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            method='get',
            url='https://testregistry.azurecr.io/v2/_acr/testrepository/manifests/list',
            headers=get_authorization_header('username', 'password'),
            params={
                'n': 100,
                'orderby': None
            },
            json=None,
            data=None,
            verify=mock.ANY)

        # Show manifests using Bearer auth with detail
        mock_get_registry_by_name.return_value = Registry(location='westus', sku=Sku(name='Standard')), 'testrg'
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', EMPTY_GUID, 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository', top=10, orderby='time_desc', detail=True)
        mock_requests_get.assert_called_with(
            method='get',
            url='https://testregistry.azurecr.io/acr/v1/testrepository/_manifests',
            headers=get_authorization_header(EMPTY_GUID, 'password'),
            params={
                'n': 10,
                'orderby': 'timedesc'
            },
            json=None,
            data=None,
            verify=mock.ANY)
    def test_repository_show_manifests(self, mock_requests_get, mock_get_access_credentials, mock_get_registry_by_name):
        cmd = mock.MagicMock()
        cmd.cli_ctx = DummyCli()
        encoded_manifests = json.dumps({'manifests': [
            {
                'digest': 'sha256:b972dda797ef258a7ea5738eb2109778c2bac6a99d1033e6c9f9bdb4fbd196e7',
                'tags': ['testtag1', 'testtag2']
            },
            {
                'digest': 'sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7',
                'tags': ['testtag3']
            }]}).encode()

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

        # Show manifests using Basic auth without detail
        mock_get_registry_by_name.return_value = Registry(location='westus', sku=Sku(name='Standard')), 'testrg'
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', 'username', 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository')
        mock_requests_get.assert_called_with(
            method='get',
            url='https://testregistry.azurecr.io/v2/_acr/testrepository/manifests/list',
            headers=_get_authorization_header('username', 'password'),
            params={
                'n': 20,
                'orderby': None
            },
            json=None,
            verify=mock.ANY)

        # Show manifests using Bearer auth with detail
        mock_get_registry_by_name.return_value = Registry(location='westus', sku=Sku(name='Standard')), 'testrg'
        mock_get_access_credentials.return_value = 'testregistry.azurecr.io', None, 'password'

        acr_repository_show_manifests(cmd, 'testregistry', 'testrepository', top=10, orderby='time_desc', detail=True)
        mock_requests_get.assert_called_with(
            method='get',
            url='https://testregistry.azurecr.io/acr/v1/testrepository/_manifests',
            headers=_get_authorization_header(None, 'password'),
            params={
                'n': 10,
                'orderby': 'timedesc'
            },
            json=None,
            verify=mock.ANY)