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


Python mocking.get_message函数代码示例

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


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


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