当前位置: 首页>>代码示例>>Python>>正文


Python HttpMockSequence.request方法代码示例

本文整理汇总了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
开发者ID:cezarexxi,项目名称:google-api-python-client,代码行数:10,代码来源:test_oauth2client.py

示例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)
开发者ID:DimitryDushkin,项目名称:eco_map,代码行数:14,代码来源:test_oauth2client.py

示例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)
开发者ID:peter-saltin,项目名称:GoogleApiPython3x,代码行数:16,代码来源:test_oauth2client.py

示例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)
开发者ID:peter-saltin,项目名称:GoogleApiPython3x,代码行数:9,代码来源:test_oauth2client.py

示例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')
开发者ID:EduardoDuarte,项目名称:enterprise-deployments,代码行数:33,代码来源:handlers_test.py

示例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"])
开发者ID:eac2192,项目名称:ticket_scalper,代码行数:9,代码来源:test_http.py

示例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'])
开发者ID:peter-saltin,项目名称:GoogleApiPython3x,代码行数:9,代码来源:test_oauth2client.py

示例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")
开发者ID:cezarexxi,项目名称:google-api-python-client,代码行数:9,代码来源:test_oauth2client.py

示例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')
开发者ID:GeomancerProject,项目名称:Software,代码行数:10,代码来源:test_http.py

示例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'])
开发者ID:peter-saltin,项目名称:GoogleApiPython3x,代码行数:10,代码来源:test_oauth2client.py

示例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)
开发者ID:Blurjp,项目名称:HuangDaxi,代码行数:10,代码来源:test_oauth.py

示例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'])
开发者ID:Blurjp,项目名称:HuangDaxi,代码行数:11,代码来源:test_oauth2client.py

示例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
开发者ID:fmoga,项目名称:google-api-python-client,代码行数:12,代码来源:test_oauth2client_jwt.py

示例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
开发者ID:Blurjp,项目名称:HuangDaxi,代码行数:12,代码来源:test_oauth.py

示例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")
开发者ID:cezarexxi,项目名称:google-api-python-client,代码行数:12,代码来源:test_oauth2client.py


注:本文中的apiclient.http.HttpMockSequence.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。