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


Python MagicMock.recv方法代码示例

本文整理汇总了Python中unittest.mock.MagicMock.recv方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.recv方法的具体用法?Python MagicMock.recv怎么用?Python MagicMock.recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.MagicMock的用法示例。


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

示例1: test_connect

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_connect(self):

        # create fake socket
        mockedSocket = MagicMock()
        mockedSocket.connect = MagicMock()
        mockedSocket.recv = MagicMock(return_value=b"+OK")

        # mock socket module
        delMail.socket = MagicMock(return_value=mockedSocket)

        # mock print
        delMail.print = MagicMock()

        # set host and port

        delMail.host = "test"
        delMail.port = 123

        the_returned_socket = delMail.connect()

        self.assertEqual(mockedSocket, the_returned_socket)
        # check that no error occured
        self.assertEqual(0, delMail.print.call_count)

        # check socket call is ok
        mockedSocket.connect.assert_called_once_with(("test", 123))
开发者ID:Strice91,项目名称:IK-HA,代码行数:28,代码来源:test_delMail.py

示例2: test_close_connection

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_close_connection(self):
        # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return ok
        mockSocket.recv = MagicMock(return_value=b"+OK")

        # test function
        output_list = delMail.close_connection(mockSocket)

        # check if socket call is ok
        mockSocket.send.assert_called_once_with(b"QUIT\r\n")
开发者ID:Strice91,项目名称:IK-HA,代码行数:14,代码来源:test_delMail.py

示例3: test_delete_all_mails

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_delete_all_mails(self):
         # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return ok
        mockSocket.recv = MagicMock(return_value=b"+OK")

        mocketList = ["Bla", "Hallo", "Welt", "Test", "Test"]
        # test function
        output_list = delMail.delete_all_mails(mockSocket, mocketList)

        # check if socket call is ok
        mockSocket.send.assert_no_call(b"DELE Bla\r\n")
        mockSocket.send.assert_no_call(b"DELE Test\r\n")
        mockSocket.send.assert_any_call(b"DELE Hallo\r\n")
        mockSocket.send.assert_any_call(b"DELE Welt\r\n")
开发者ID:Strice91,项目名称:IK-HA,代码行数:18,代码来源:test_delMail.py

示例4: test_send_list

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_send_list(self):
         # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return ok
        mockSocket.recv = MagicMock(return_value=b"+OK\r\nHallo\r\nWelt")

        # mock print
        delMail.print = MagicMock()

        # test function
        output_list = delMail.send_list(mockSocket)

        # check if socket call is ok
        mockSocket.send.assert_called_once_with(b"LIST\r\n")

        # check output
        self.assertEqual(0, delMail.print.call_count)
        self.assertEqual(["+OK", "Hallo", "Welt"], output_list)
开发者ID:Strice91,项目名称:IK-HA,代码行数:21,代码来源:test_delMail.py

示例5: test_send_pass_correct

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_send_pass_correct(self):
         # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return ok
        mockSocket.recv = MagicMock(return_value=b"+OK")

        # mock print
        delMail.print = MagicMock()

        # set password
        delMail.password = "test"

        # test function
        delMail.send_pass(mockSocket)

        # check if socket call is ok
        mockSocket.send.assert_called_once_with(b"pass test\r\n")

        # check output
        self.assertEqual(0, delMail.print.call_count)
开发者ID:Strice91,项目名称:IK-HA,代码行数:23,代码来源:test_delMail.py

示例6: test_send_user_incorrect

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_send_user_incorrect(self):
        # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return an error
        mockSocket.recv = MagicMock(return_value=b"+ERROR")

        # mock print
        delMail.print = MagicMock()

        # set user
        delMail.user = "test"

        # test function
        delMail.send_user(mockSocket)

        # check if socket call is ok
        mockSocket.send.assert_called_once_with(b"user test\r\n")

        # check if error message is ok
        delMail.print.assert_called_once_with("User not known.")
开发者ID:Strice91,项目名称:IK-HA,代码行数:23,代码来源:test_delMail.py

示例7: test_send_pass_incorrect

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import recv [as 别名]
    def test_send_pass_incorrect(self):
         # mock socket
        mockSocket = MagicMock()
        mockSocket.send = MagicMock()
        # return ok
        mockSocket.recv = MagicMock(return_value=b"+ERROR")

        # mock print
        delMail.print = MagicMock()

        # set password
        delMail.password = "test"

        # test function
        delMail.send_pass(mockSocket)

        # check if socket call is ok
        mockSocket.send.assert_called_once_with(b"pass test\r\n")

         # check if error message is ok
        delMail.print.assert_called_once_with("Password falsch")
开发者ID:Strice91,项目名称:IK-HA,代码行数:23,代码来源:test_delMail.py


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