def testUntag_Registry403(self): response = httplib2.Response({'status': 403, 'body': 'some body'}) exception = docker_http.V2DiagnosticException( response, 'some content'.encode('utf8')) self.mock_delete.side_effect = exception with self.assertRaises(util.UserRecoverableV2Error) as cm: self.Untag([_TAG_V1]) self.assertIn('Access denied:', six.text_type(cm.exception))
def testDescribe_Forbidden(self, mock_get_digest_from_name): mock_get_digest_from_name.side_effect = docker_http.V2DiagnosticException( httplib2.Response({'status': six.moves.http_client.FORBIDDEN}), ''.encode('utf-8')) test_image = 'gcr.io/foo/goodimage:latest' with self.assertRaises(util.UserRecoverableV2Error): self.Describe(test_image) self.AssertErrContains('Access denied: ' + test_image)
def testDescribe_NotFound(self, mock_get_digest_from_name): mock_get_digest_from_name.side_effect = docker_http.V2DiagnosticException( httplib2.Response({ 'status': six.moves.http_client.NOT_FOUND }), ''.encode('utf8')) test_image = 'gcr.io/foo/goodimage:latest' with self.assertRaises(util.UserRecoverableV2Error): self.Describe(test_image) self.AssertErrContains('Not found: ' + test_image)
def testDeleteDigest_Registry404(self): self._manifests = {_DIGEST_SUFFIX1: {'tag': _TAGS1, 'timestamp': ''}} self.digest_from_name_mock.side_effect = docker_http.V2DiagnosticException( httplib2.Response({'status': six.moves.http_client.NOT_FOUND}), ''.encode('utf8')) with self.assertRaises(util.UserRecoverableV2Error): self.Delete([_TAG_V1])
def testDockerError_404(self): transform_manifests_mock = self.StartPatch( 'googlecloudsdk.api_lib.container.images.util.TransformManifests') response = httplib2.Response({'status': 404, 'body': 'some body'}) exception = docker_http.V2DiagnosticException( response, 'some content'.encode('utf8')) transform_manifests_mock.side_effect = exception with self.assertRaises(util.UserRecoverableV2Error) as cm: self.ListTags() self.assertTrue('Not found', six.text_type(cm.exception))
def testListUnauthorized(self): # Simulate a 401 error the dockerless client. err = docker_http.V2DiagnosticException( httplib2.Response({ 'status': six.moves.http_client.UNAUTHORIZED }), ''.encode('utf-8')) self.registry_mock.children.side_effect = err with self.assertRaises(util.UserRecoverableV2Error): self.List() self.AssertErrContains('Access denied:')
def testListNotFound(self): # Simulate a 404 error the dockerless client. err = docker_http.V2DiagnosticException( httplib2.Response({ 'status': six.moves.http_client.NOT_FOUND }), ''.encode('utf-8')) self.registry_mock.children.side_effect = err with self.assertRaises(util.UserRecoverableV2Error): self.List() self.AssertErrContains('Not found:')