本文整理汇总了Python中apache.aurora.common.transport.TRequestsTransport类的典型用法代码示例。如果您正苦于以下问题:Python TRequestsTransport类的具体用法?Python TRequestsTransport怎么用?Python TRequestsTransport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TRequestsTransport类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_request_transport_integration
def test_request_transport_integration():
handler = ReadOnlySchedulerHandler()
processor = ReadOnlyScheduler.Processor(handler)
pfactory = TJSONProtocol.TJSONProtocolFactory()
server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
server_thread = Thread(target=server.serve)
server_thread.start()
_, server_port = server.httpd.socket.getsockname()
response = None
try:
transport = TRequestsTransport('http://localhost:%d' % server_port)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
response = client.getRoleSummary()
finally:
server.httpd.shutdown()
assert response is not None
assert response.responseCode == ResponseCode.OK
assert response.serverInfo.clusterName == 'west'
assert response.serverInfo.thriftAPIVersion == 3
transport.close()
示例2: test_request_any_other_exception
def test_request_any_other_exception():
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post = Mock(side_effect=request_exceptions.ConnectionError())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException):
client.getRoleSummary()
transport.close()
示例3: test_request_transport_timeout
def test_request_transport_timeout():
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post = Mock(side_effect=request_exceptions.Timeout())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException) as execinfo:
client.getRoleSummary()
assert execinfo.value.message == 'Timed out talking to http://localhost:12345'
transport.close()
示例4: _connect_scheduler
def _connect_scheduler(self, uri, clock=time):
transport = TRequestsTransport(uri, user_agent=self._user_agent)
protocol = TJSONProtocol.TJSONProtocol(transport)
schedulerClient = AuroraAdmin.Client(protocol)
for _ in range(self.THRIFT_RETRIES):
try:
transport.open()
return schedulerClient
except TTransport.TTransportException:
clock.sleep(self.RETRY_TIMEOUT.as_(Time.SECONDS))
continue
except Exception as e:
# Monkey-patched proxies, like socks, can generate a proxy error here.
# without adding a dependency, we can't catch those in a more specific way.
raise self.CouldNotConnect('Connection to scheduler failed: %s' % e)
raise self.CouldNotConnect('Could not connect to %s' % uri)
示例5: test_raises_auth_error
def test_raises_auth_error():
response = requests.Response()
response.status_code = 401
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TRequestsTransport.AuthError):
client.getRoleSummary()
transport.close()
示例6: test_request_any_other_exception
def test_request_any_other_exception():
session = mock.MagicMock(spec=requests.Session)
session.headers = {}
session.post = mock.Mock(side_effect=request_exceptions.ConnectionError())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
try:
client.getRoleSummary()
assert False, 'getRoleSummary should not succeed'
except TTransport.TTransportException:
pass
except Exception as e:
assert False, 'Only expected TTransportException, got %s' % e
transport.close()
示例7: test_raise_for_status_causes_exception
def test_raise_for_status_causes_exception():
response = requests.Response()
response.status_code = 503
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException) as excinfo:
client.getRoleSummary()
assert excinfo.value.type == TTransport.TTransportException.UNKNOWN
assert excinfo.value.message.startswith('Unknown error talking to http://localhost:12345')
transport.close()
示例8: test_auth_type_valid
def test_auth_type_valid():
response = requests.Response()
response.status_code = 500
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
auth = requests.auth.AuthBase()
transport = TRequestsTransport('http://localhost:1', auth=auth, session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException):
client.getRoleSummary()
transport.close()
session.post.mock_calls = (call(ANY, data=ANY, timeout=ANY, auth=auth))
示例9: test_requests_transport_session_reuse
def test_requests_transport_session_reuse():
handler = ReadOnlySchedulerHandler()
processor = ReadOnlyScheduler.Processor(handler)
pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
server_thread = Thread(target=server.serve)
server_thread.start()
_, server_port = server.httpd.socket.getsockname()
try:
transport = TRequestsTransport('http://localhost:%d' % server_port)
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
client = ReadOnlyScheduler.Client(protocol)
client.getRoleSummary()
old_session = transport._session
client.getRoleSummary()
finally:
server.httpd.shutdown()
assert old_session == transport._session
transport.close()
示例10: _connect_scheduler
def _connect_scheduler(self, uri, clock=time):
transport = TRequestsTransport(
uri,
auth=self._auth_handler.auth(),
user_agent=self._user_agent,
session_factory=functools.partial(
_bypass_leader_redirect_session_factory,
should_bypass=self._bypass_leader_redirect))
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
schedulerClient = AuroraAdmin.Client(protocol)
for _ in range(self.THRIFT_RETRIES):
try:
transport.open()
return schedulerClient
except TTransport.TTransportException:
clock.sleep(self.RETRY_TIMEOUT.as_(Time.SECONDS))
continue
except Exception as e:
# Monkey-patched proxies, like socks, can generate a proxy error here.
# without adding a dependency, we can't catch those in a more specific way.
raise self.CouldNotConnect('Connection to scheduler failed: %s' % e)
raise self.CouldNotConnect('Could not connect to %s' % uri)
示例11: test_transport_applies_default_user_agent_if_no_factory_provided
def test_transport_applies_default_user_agent_if_no_factory_provided():
transport = TRequestsTransport('http://localhost:12345')
transport.open()
assert transport._session.headers['User-Agent'] == DEFAULT_USER_AGENT
示例12: test_transport_applies_user_agent_from_factory
def test_transport_applies_user_agent_from_factory():
user_agent = 'Some-User-Agent'
transport = TRequestsTransport('http://localhost:12345', user_agent=user_agent)
transport.open()
assert transport._session.headers['User-Agent'] == user_agent