• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mocking.get_message函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中test.mocking.get_message函数的典型用法代码示例。如果您正苦于以下问题:Python get_message函数的具体用法?Python get_message怎么用?Python get_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_message函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_relative_cookie

  def test_relative_cookie(self):
    """
    Checks an authentication cookie with a relative path where expansion both
    succeeds and fails.
    """

    # we need to mock both pid and cwd lookups since the general cookie
    # expanion works by...
    # - resolving the pid of the "tor" process
    # - using that to get tor's cwd

    def call_function(command, default):
      if command == stem.util.system.GET_PID_BY_NAME_PGREP % "tor":
        return ["10"]
      elif command == stem.util.system.GET_CWD_PWDX % 10:
        return ["10: /tmp/foo"]

    with patch('stem.util.system.call') as call_mock:
      call_mock.side_effect = call_function

      control_message = mocking.get_message(RELATIVE_COOKIE_PATH)
      stem.response.convert("PROTOCOLINFO", control_message)

      stem.connection._expand_cookie_path(control_message, stem.util.system.get_pid_by_name, "tor")

      self.assertEquals(os.path.join("/tmp/foo", "tor-browser_en-US", "Data", "control_auth_cookie"), control_message.cookie_path)

    # exercise cookie expansion where both calls fail (should work, just
    # leaving the path unexpanded)

    with patch('stem.util.system.call', Mock(return_value = None)):
      control_message = mocking.get_message(RELATIVE_COOKIE_PATH)
      stem.response.convert("PROTOCOLINFO", control_message)
      self.assertEquals("./tor-browser_en-US/Data/control_auth_cookie", control_message.cookie_path)
开发者ID:arlolra,项目名称:stem,代码行数:34,代码来源:protocolinfo.py


示例2: test_convert

  def test_convert(self):
    """
    Exercises functionality of the convert method both when it works and
    there's an error.
    """

    # working case
    control_message = mocking.get_message(NO_AUTH)
    stem.response.convert("PROTOCOLINFO", control_message)

    # now this should be a ProtocolInfoResponse (ControlMessage subclass)
    self.assertTrue(isinstance(control_message, stem.response.ControlMessage))
    self.assertTrue(isinstance(control_message, stem.response.protocolinfo.ProtocolInfoResponse))

    # exercise some of the ControlMessage functionality
    raw_content = (NO_AUTH + "\n").replace("\n", "\r\n")
    self.assertEquals(raw_content, control_message.raw_content())
    self.assertTrue(str(control_message).startswith("PROTOCOLINFO 1"))

    # attempt to convert the wrong type
    self.assertRaises(TypeError, stem.response.convert, "PROTOCOLINFO", "hello world")

    # attempt to convert a different message type
    bw_event_control_message = mocking.get_message("650 BW 32326 2856")
    self.assertRaises(stem.ProtocolError, stem.response.convert, "PROTOCOLINFO", bw_event_control_message)
开发者ID:arlolra,项目名称:stem,代码行数:25,代码来源:protocolinfo.py


示例3: test_invalid_requests

 def test_invalid_requests(self):
   """
   Parses a MAPADDRESS replies that contain an error code due to hostname syntax errors.
   """
   
   control_message = mocking.get_message(UNRECOGNIZED_KEYS_RESPONSE)
   self.assertRaises(stem.socket.InvalidRequest, stem.response.convert, "MAPADDRESS", control_message)
   expected = { "23": "324" }
   
   control_message = mocking.get_message(PARTIAL_FAILURE_RESPONSE)
   stem.response.convert("MAPADDRESS", control_message)
   self.assertEqual(expected, control_message.entries)
开发者ID:eoinof,项目名称:stem,代码行数:12,代码来源:mapaddress.py


示例4: test_invalid_response

 def test_invalid_response(self):
   """
   Parses a malformed MAPADDRESS reply that contains an invalid response code.
   This is a proper controller message, but malformed according to the
   MAPADDRESS's spec.
   """
   
   control_message = mocking.get_message(INVALID_EMPTY_RESPONSE)
   self.assertRaises(stem.socket.ProtocolError, stem.response.convert, "MAPADDRESS", control_message)
   
   control_message = mocking.get_message(INVALID_RESPONSE)
   self.assertRaises(stem.socket.ProtocolError, stem.response.convert, "MAPADDRESS", control_message)
开发者ID:eoinof,项目名称:stem,代码行数:12,代码来源:mapaddress.py


示例5: test_single_line_response

  def test_single_line_response(self):
    message = mocking.get_message("552 NOTOK")
    stem.response.convert("SINGLELINE", message)
    self.assertEqual(False, message.is_ok())

    message = mocking.get_message("250 KK")
    stem.response.convert("SINGLELINE", message)
    self.assertEqual(True, message.is_ok())

    message = mocking.get_message("250 OK")
    stem.response.convert("SINGLELINE", message)
    self.assertEqual(True, message.is_ok(True))

    message = mocking.get_message("250 HMM")
    stem.response.convert("SINGLELINE", message)
    self.assertEqual(False, message.is_ok(True))
开发者ID:ankitmodi,项目名称:Projects,代码行数:16,代码来源:singleline.py


示例6: test_setevents

  def test_setevents(self):
    controller = Mock()
    controller.msg.return_value = mocking.get_message('250 OK')

    interpreter = ControlInterpretor(controller)

    self.assertEqual('\x1b[34m250 OK\x1b[0m\n', interpreter.run_command('SETEVENTS BW'))
开发者ID:FedericoCeratto,项目名称:stem,代码行数:7,代码来源:commands.py


示例7: test_invalid_non_mapping_content

 def test_invalid_non_mapping_content(self):
   """
   Parses a malformed GETINFO reply containing a line that isn't a key=value
   entry.
   """
   
   control_message = mocking.get_message(NON_KEY_VALUE_ENTRY)
   self.assertRaises(stem.socket.ProtocolError, stem.response.convert, "GETINFO", control_message)
开发者ID:jacthinman,项目名称:Tor-Stem,代码行数:8,代码来源:getinfo.py


示例8: test_single_response

 def test_single_response(self):
   """
   Parses a GETCONF reply response for a single parameter.
   """
   
   control_message = mocking.get_message(SINGLE_RESPONSE)
   stem.response.convert("GETCONF", control_message)
   self.assertEqual({"DataDirectory": ["/home/neena/.tor"]}, control_message.entries)
开发者ID:eoinof,项目名称:stem,代码行数:8,代码来源:getconf.py


示例9: test_single_response

 def test_single_response(self):
   """
   Parses a MAPADDRESS reply response with a single address mapping.
   """
   
   control_message = mocking.get_message(SINGLE_RESPONSE)
   stem.response.convert("MAPADDRESS", control_message)
   self.assertEqual({"foo": "bar"}, control_message.entries)
开发者ID:eoinof,项目名称:stem,代码行数:8,代码来源:mapaddress.py


示例10: test_password_auth

  def test_password_auth(self):
    """
    Checks a response with password authentication.
    """

    control_message = mocking.get_message(PASSWORD_AUTH)
    stem.response.convert("PROTOCOLINFO", control_message)
    self.assertEquals((AuthMethod.PASSWORD, ), control_message.auth_methods)
开发者ID:arlolra,项目名称:stem,代码行数:8,代码来源:protocolinfo.py


示例11: test_single_response

 def test_single_response(self):
   """
   Parses a GETINFO reply response for a single parameter.
   """
   
   control_message = mocking.get_message(SINGLE_RESPONSE)
   stem.response.convert("GETINFO", control_message)
   self.assertEqual({"version": "0.2.3.11-alpha-dev"}, control_message.entries)
开发者ID:jacthinman,项目名称:Tor-Stem,代码行数:8,代码来源:getinfo.py


示例12: test_multiple_auth

  def test_multiple_auth(self):
    """
    Checks a response with multiple authentication methods.
    """

    control_message = mocking.get_message(MULTIPLE_AUTH)
    stem.response.convert("PROTOCOLINFO", control_message)
    self.assertEquals((AuthMethod.COOKIE, AuthMethod.PASSWORD), control_message.auth_methods)
    self.assertEquals("/home/atagar/.tor/control_auth_cookie", control_message.cookie_path)
开发者ID:arlolra,项目名称:stem,代码行数:9,代码来源:protocolinfo.py


示例13: test_invalid_multiline_content

 def test_invalid_multiline_content(self):
   """
   Parses a malformed GETINFO reply with a multi-line entry missing a newline
   between its key and value. This is a proper controller message, but
   malformed according to the GETINFO's spec.
   """
   
   control_message = mocking.get_message(MISSING_MULTILINE_NEWLINE)
   self.assertRaises(stem.socket.ProtocolError, stem.response.convert, "GETINFO", control_message)
开发者ID:jacthinman,项目名称:Tor-Stem,代码行数:9,代码来源:getinfo.py


示例14: test_invalid_content

 def test_invalid_content(self):
   """
   Parses a malformed GETCONF reply that contains an invalid response code.
   This is a proper controller message, but malformed according to the
   GETCONF's spec.
   """
   
   control_message = mocking.get_message(INVALID_RESPONSE)
   self.assertRaises(stem.socket.ProtocolError, stem.response.convert, "GETCONF", control_message)
开发者ID:eoinof,项目名称:stem,代码行数:9,代码来源:getconf.py


示例15: test_unknown_auth

  def test_unknown_auth(self):
    """
    Checks a response with an unrecognized authtentication method.
    """

    control_message = mocking.get_message(UNKNOWN_AUTH)
    stem.response.convert("PROTOCOLINFO", control_message)
    self.assertEquals((AuthMethod.UNKNOWN, AuthMethod.PASSWORD), control_message.auth_methods)
    self.assertEquals(("MAGIC", "PIXIE_DUST"), control_message.unknown_auth_methods)
开发者ID:arlolra,项目名称:stem,代码行数:9,代码来源:protocolinfo.py


示例16: test_cookie_auth

  def test_cookie_auth(self):
    """
    Checks a response with cookie authentication and a path including escape
    characters.
    """

    control_message = mocking.get_message(COOKIE_AUTH)
    stem.response.convert("PROTOCOLINFO", control_message)
    self.assertEquals((AuthMethod.COOKIE, ), control_message.auth_methods)
    self.assertEquals("/tmp/my data\\\"dir//control_auth_cookie", control_message.cookie_path)
开发者ID:arlolra,项目名称:stem,代码行数:10,代码来源:protocolinfo.py


示例17: test_getconf

  def test_getconf(self):
    response = '250-Log=notice stdout\r\n250 Address'

    controller = Mock()
    controller.msg.return_value = mocking.get_message(response)

    interpreter = ControlInterpretor(controller)

    self.assertEqual('\x1b[34m%s\x1b[0m\n' % response, interpreter.run_command('GETCONF log address'))
    controller.msg.assert_called_with('GETCONF log address')
开发者ID:FedericoCeratto,项目名称:stem,代码行数:10,代码来源:commands.py


示例18: test_no_key_type

  def test_no_key_type(self):
    """
    Checks a response that's missing the private key type.
    """

    try:
      response = mocking.get_message(MISSING_KEY_TYPE)
      stem.response.convert('ADD_ONION', response)
      self.fail("we should've raised a ProtocolError")
    except stem.ProtocolError as exc:
      self.assertTrue(str(exc).startswith('ADD_ONION PrivateKey lines should be of the form'))
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:11,代码来源:add_onion.py


示例19: test_without_service_id

  def test_without_service_id(self):
    """
    Checks a response that lack an initial service id.
    """

    try:
      response = mocking.get_message(WRONG_FIRST_KEY)
      stem.response.convert('ADD_ONION', response)
      self.fail("we should've raised a ProtocolError")
    except stem.ProtocolError as exc:
      self.assertTrue(str(exc).startswith('ADD_ONION response should start with'))
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:11,代码来源:add_onion.py


示例20: test_without_private_key

  def test_without_private_key(self):
    """
    Checks a response without a private key.
    """

    response = mocking.get_message(WITHOUT_PRIVATE_KEY)
    stem.response.convert('ADD_ONION', response)

    self.assertEqual('gfzprpioee3hoppz', response.service_id)
    self.assertEqual(None, response.private_key)
    self.assertEqual(None, response.private_key_type)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:11,代码来源:add_onion.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap