本文整理汇总了Python中apiclient.http.HttpMockSequence.request方法的典型用法代码示例。如果您正苦于以下问题:Python HttpMockSequence.request方法的具体用法?Python HttpMockSequence.request怎么用?Python HttpMockSequence.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apiclient.http.HttpMockSequence
的用法示例。
在下文中一共展示了HttpMockSequence.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_token_refresh_failure
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_token_refresh_failure(self):
http = HttpMockSequence([({"status": "401"}, ""), ({"status": "400"}, '{"error":"access_denied"}')])
http = self.credentials.authorize(http)
try:
http.request("http://example.com")
self.fail("should raise AccessTokenRefreshError exception")
except AccessTokenRefreshError:
pass
示例2: test_token_refresh_failure
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_token_refresh_failure(self):
http = HttpMockSequence([
({'status': '401'}, ''),
({'status': '400'}, '{"error":"access_denied"}'),
])
http = self.credentials.authorize(http)
try:
http.request("http://example.com")
self.fail("should raise AccessTokenRefreshError exception")
except AccessTokenRefreshError:
pass
self.assertTrue(self.credentials.access_token_expired)
示例3: test_token_refresh_failure
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_token_refresh_failure(self):
for status_code in REFRESH_STATUS_CODES:
http = HttpMockSequence([
({'status': status_code}, ''),
({'status': '400'}, '{"error":"access_denied"}'),
])
http = self.credentials.authorize(http)
try:
http.request('http://example.com')
self.fail('should raise AccessTokenRefreshError exception')
except AccessTokenRefreshError:
pass
self.assertTrue(self.credentials.access_token_expired)
self.assertEqual(None, self.credentials.token_response)
示例4: test_non_401_error_response
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_non_401_error_response(self):
http = HttpMockSequence([
({'status': '400'}, ''),
])
http = self.credentials.authorize(http)
resp, content = http.request('http://example.com')
self.assertEqual(400, resp.status)
示例5: testPost
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def testPost(self):
request = webapp2.Request.blank("/step1", POST={
'domain': 'demo-123.resold.richieforeman.net'
})
from mock import MagicMock
http = HttpMockSequence([
({'status': '200'}, RESELLER_DISCOVERY),
({'status': '200'}, json.dumps({}))
])
# wrap http.request so we can spy on it.
http.request = MagicMock(wraps=http.request)
with patch('main.get_authorized_http', return_value=http):
response = request.get_response(app)
self.assertTrue(http.request.called)
discovery_call = http.request.call_args_list[0]
create_customer = http.request.call_args_list[1]
# ensure that a discovery call occured.
(url,), args = discovery_call
self.assertEqual(url, RESELLER_DISCOVERY_URL)
# ensure that a customer was created via the POST api.
(url, method), args = create_customer
self.assertEqual(url,
'https://www.googleapis'
'.com/apps/reseller/v1/customers?alt=json')
self.assertEqual(method, 'POST')
示例6: test_set_user_agent_nested
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_set_user_agent_nested(self):
http = HttpMockSequence([({"status": "200"}, "echo_request_headers")])
http = set_user_agent(http, "my_app/5.5")
http = set_user_agent(http, "my_library/0.1")
resp, content = http.request("http://example.com")
self.assertEqual("my_app/5.5 my_library/0.1", content["user-agent"])
示例7: test_auth_header_sent
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_auth_header_sent(self):
http = HttpMockSequence([
({'status': '200'}, 'echo_request_headers'),
])
http = self.credentials.authorize(http)
resp, content = http.request('http://example.com')
self.assertEqual('Bearer foo', content['Authorization'])
示例8: test_assertion_refresh
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_assertion_refresh(self):
http = HttpMockSequence(
[({"status": "200"}, '{"access_token":"1/3w"}'), ({"status": "200"}, "echo_request_headers")]
)
http = self.credentials.authorize(http)
resp, content = http.request("http://example.com")
self.assertEqual(content["authorization"], "OAuth 1/3w")
示例9: test_set_user_agent
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_set_user_agent(self):
http = HttpMockSequence([
({'status': '200'}, 'echo_request_headers'),
])
http = set_user_agent(http, "my_app/5.5")
resp, content = http.request("http://example.com")
self.assertEqual(content['user-agent'], 'my_app/5.5')
示例10: test_assertion_refresh
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_assertion_refresh(self):
http = HttpMockSequence([
({'status': '200'}, '{"access_token":"1/3w"}'),
({'status': '200'}, 'echo_request_headers'),
])
http = self.credentials.authorize(http)
resp, content = http.request('http://example.com')
self.assertEqual('Bearer 1/3w', content['Authorization'])
示例11: test_add_requestor_to_uri
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_add_requestor_to_uri(self):
http = HttpMockSequence([
({'status': '200'}, 'echo_request_uri'),
])
http = self.credentials.authorize(http)
resp, content = http.request("http://example.com")
self.assertEqual('http://example.com?xoauth_requestor_id=test%40example.org',
content)
示例12: test_token_refresh_success
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_token_refresh_success(self):
http = HttpMockSequence([
({'status': '401'}, ''),
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),
({'status': '200'}, 'echo_request_headers'),
])
http = self.credentials.authorize(http)
resp, content = http.request("http://example.com")
self.assertEqual('Bearer 1/3w', content['Authorization'])
示例13: _credentials_refresh
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def _credentials_refresh(self, credentials):
http = HttpMockSequence([
({'status': '200'}, '{"access_token":"1/3w","expires_in":3600}'),
({'status': '401'}, ''),
({'status': '200'}, '{"access_token":"3/3w","expires_in":3600}'),
({'status': '200'}, 'echo_request_headers'),
])
http = credentials.authorize(http)
resp, content = http.request('http://example.org')
return content
示例14: test_invalid_token
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_invalid_token(self):
http = HttpMockSequence([
({'status': '401'}, ''),
])
http = self.credentials.authorize(http)
try:
resp, content = http.request("http://example.com")
self.fail('should raise CredentialsInvalidError')
except CredentialsInvalidError:
pass
示例15: test_token_refresh_success
# 需要导入模块: from apiclient.http import HttpMockSequence [as 别名]
# 或者: from apiclient.http.HttpMockSequence import request [as 别名]
def test_token_refresh_success(self):
http = HttpMockSequence([({"status": "401"}, "")])
http = self.credentials.authorize(http)
try:
resp, content = http.request("http://example.com")
self.fail("should throw exception if token expires")
except AccessTokenCredentialsError:
pass
except Exception:
self.fail("should only throw AccessTokenCredentialsError")