def setUp(self): super(TestManager, self).setUp() http_client = httpclient.OpenStackHttpClient(mock.MagicMock()) self.manager = fakes.FakeManager(http_client) self.instance = dict(uuid=fakes.FAKE_RESOURCE_ID, name=fakes.FAKE_RESOURCE_NAME) self.resource = fakes.FakeResource(None, self.instance)
def __init__(self, session=None, endpoint=None, **kwargs): """Initialize a new client for the VBS v2 API. :param keystoneauth1.session.Session session: The session to be used for making the HTTP API calls. If None, a default keystoneauth1.session.Session will be created. :param string endpoint: An optional URL to be used as the base for API requests on this API :param kwargs: Keyword arguments passed to keystoneauth1.session.Session(). """ # http_log_debug = utils.get_effective_log_level() <= logging.DEBUG default_options = { 'service_name': self.service_name, 'client_name': 'AntiDDos Client', 'client_version': 'v2', 'logger': LOGGER, } kwargs.update(default_options) if endpoint: endpoint += '/v2/%(project_id)s' self.client = httpclient.OpenStackHttpClient(session, endpoint, **kwargs) from antiddosclient.v2 import alert_mgr self.alerts = alert_mgr.AlertManager(self.client)
def test_convert_http_error(self, mocked): client = httpclient.OpenStackHttpClient(mock.MagicMock()) mock_resp = mock.Mock() mock_resp.status_code = 413 mock_resp.json.return_value = { 'error_code': '413', 'error_description': 'Request Entity Too Large', } mock_resp.headers = { 'Content-Type': 'application/json', 'x-openstack-request-id': mock.sentinel.fake_request_id, 'retry-after': 10, } http_error = exc.from_response(mock_resp, 'POST', 'fake_url') mocked.side_effect = http_error self.assertRaises(exc.RequestEntityTooLarge, client.request)
def test_endpoint_override(self): endpoint_override = "http://baidu.com" client = httpclient.OpenStackHttpClient(mock.MagicMock(), endpoint=endpoint_override) self.assertEqual(client.endpoint_override, endpoint_override)