Beispiel #1
0
    def test_failure(self):
        http_request = mock.MagicMock()
        response = httplib2.Response({'status': http_client.NOT_FOUND})
        content = b'Not found'
        http_request.return_value = (response, content)
        with self.assertRaises(MetadataServerHttpError):
            _get_metadata(http_request)

        http_request.assert_called_once_with(
            _METADATA_ROOT + '/?recursive=true',
            headers={'Metadata-Flavor': 'Google'})
Beispiel #2
0
 def test_success_not_json(self):
     http_request = mock.MagicMock()
     data = '12345'.encode('utf-8')
     http_request.return_value = (
         httplib2.Response({'status': http_client.OK,
                            'content-type': 'text/plain'}), data)
     result = _get_metadata(http_request, recursive=False)
     self.assertEqual(result, data.decode('utf-8'))
     http_request.assert_called_once_with(
         _METADATA_ROOT,
         headers={'Metadata-Flavor': 'Google'})
Beispiel #3
0
 def test_success(self):
     http_request = mock.MagicMock()
     data = json.dumps(A_SERVICE_ACCOUNT).encode('utf-8')
     http_request.return_value = (
         httplib2.Response({'status': http_client.OK,
                            'content-type': 'application/json'}), data)
     result = _get_metadata(http_request)
     self.assertEqual(result, json.loads(data.decode('utf-8')))
     http_request.assert_called_once_with(
         _METADATA_ROOT + '/?recursive=true',
         headers={'Metadata-Flavor': 'Google'})