本文整理汇总了Python中apiclient.http.HttpMockSequence类的典型用法代码示例。如果您正苦于以下问题:Python HttpMockSequence类的具体用法?Python HttpMockSequence怎么用?Python HttpMockSequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpMockSequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_assertion_refresh
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")
示例2: test_auth_header_sent
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'])
示例3: test_set_user_agent_nested
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"])
示例4: testPost
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')
示例5: test_non_401_error_response
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)
示例6: test_set_user_agent
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')
示例7: test_assertion_refresh
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'])
示例8: test_token_refresh_failure
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
示例9: test_add_requestor_to_uri
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)
示例10: test_token_refresh_success
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'])
示例11: _credentials_refresh
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
示例12: test_invalid_token
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
示例13: test_token_refresh_success
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")
示例14: test_set_user_agent_nested
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")
content = simplejson.loads(content.decode())
self.assertEqual('my_app/5.5 my_library/0.1', content['user-agent'])
示例15: test_no_requestor
def test_no_requestor(self):
self.credentials.requestor = None
http = HttpMockSequence([
({'status': '401'}, ''),
])
http = self.credentials.authorize(http)
try:
resp, content = http.request("http://example.com")
self.fail('should raise MissingParameter')
except MissingParameter:
pass