def test_session_no_ca_verify(self, monkeypatch): urllib_mock = Mock() monkeypatch.setattr(brewtils.rest.client, "urllib3", urllib_mock) client = RestClient(bg_host="host", bg_port=80, api_version=1, ca_verify=False) assert client.session.verify is False assert urllib_mock.disable_warnings.called is True
def __init__(self): self._client = RestClient( brew_view.config.web.public_fqdn, brew_view.config.web.port, ssl_enabled=brew_view.config.web.ssl.enabled, url_prefix=brew_view.config.web.url_prefix, )
def client(self, session_mock, url_prefix): client = RestClient( bg_host="host", bg_port=80, api_version=1, url_prefix=url_prefix ) client.session = session_mock return client
def __init__(self, bg_host=None, bg_port=None, ssl_enabled=False, api_version=None, ca_cert=None, client_cert=None, parser=None, logger=None, url_prefix=None, ca_verify=True, **kwargs): bg_host = bg_host or kwargs.get('host') bg_port = bg_port or kwargs.get('port') self.logger = logger or logging.getLogger(__name__) self.parser = parser or SchemaParser() self.client = RestClient(bg_host=bg_host, bg_port=bg_port, ssl_enabled=ssl_enabled, api_version=api_version, ca_cert=ca_cert, client_cert=client_cert, url_prefix=url_prefix, ca_verify=ca_verify, **kwargs)
def test_args_from_config(self, monkeypatch): brewtils.plugin.CONFIG.bg_host = "localhost" brewtils.plugin.CONFIG.bg_port = 3000 client = RestClient() assert client.bg_host == "localhost" assert client.bg_port == 3000
def ssl_client(self, session_mock, url_prefix): client = RestClient(bg_host='host', bg_port=80, api_version=1, url_prefix=url_prefix, ssl_enabled=True) client.session = session_mock return client
def test_proxy_config_ssl(self, monkeypatch): proxy = "test:1234" brewtils.plugin.CONFIG.bg_host = "localhost" brewtils.plugin.CONFIG.bg_port = 3000 brewtils.plugin.CONFIG.ssl_enabled = True brewtils.plugin.CONFIG.proxy = proxy client = RestClient() assert client.session.proxies["https"] == proxy
def _load_from_url(url): # type: (str) -> Union[str, dict] """Load a definition from a URL""" from brewtils.rest.client import RestClient # Use a RestClient's session since TLS will (hopefully) be configured response = RestClient(bg_host="").session.get(url) if "application/json" in response.headers.get("content-type", "").lower(): return response.json() return response.text
def test_old_positional_args(self, client, url_prefix): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") test_client = RestClient("host", 80, api_version=1, url_prefix=url_prefix, ssl_enabled=False) assert test_client.version_url == client.version_url assert len(w) == 2
def client(self, session_mock, url_prefix): client = RestClient( bg_host="host", bg_port=80, api_version=1, url_prefix=url_prefix, username="******", password="******", ssl_enabled=False, ) client.session = session_mock return client
def test_client_cert_without_username_password(self, monkeypatch): get_tokens_mock = Mock() monkeypatch.setattr(brewtils.rest.client.RestClient, "get_tokens", get_tokens_mock) client = RestClient( bg_host="host", bg_port=443, api_version=1, ssl_enabled=True, client_cert="/path/to/cert", ) session_get_response = Mock() session_get_response.status_code = 401 session_get_mock = Mock(return_value=session_get_response) monkeypatch.setattr(client.session, "get", session_get_mock) client.get_garden("somegarden") assert get_tokens_mock.called is True
def test_session_no_ca_cert(self): client = RestClient(bg_host='host', bg_port=80, api_version=1) assert client.session.verify is True
def test_session_ca_cert(self): client = RestClient(bg_host='host', bg_port=80, api_version=1, ca_cert='/path/to/ca/cert') assert client.session.verify == '/path/to/ca/cert'
def test_session_client_cert(self): client = RestClient( bg_host="host", bg_port=80, api_version=1, client_cert="/path/to/cert" ) assert client.session.cert == "/path/to/cert"
def test_bad_args(self, kwargs): with pytest.raises(YapconfItemError): RestClient(**kwargs)
def test_old_positional_args(self, client, url_prefix): test_client = RestClient('host', 80, api_version=1, url_prefix=url_prefix) assert test_client.version_url == client.version_url
def test_bad_args(self, kwargs): with pytest.raises(ValueError): RestClient(**kwargs)
def __init__(self, *args, **kwargs): # This points DeprecationWarnings at the right line kwargs.setdefault("stacklevel", 4) self.client = RestClient(*args, **kwargs)