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


Python MagicMock.send方法代码示例

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


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

示例1: test_send_templated_email_without_template_context_creates_message

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [as 别名]
def test_send_templated_email_without_template_context_creates_message():
	service = SendgridService()
	sendgrid_mock = MagicMock()
	send_method_mock = MagicMock()
	send_method_mock.return_value = (200, 'some message')
	sendgrid_mock.send = send_method_mock
	service.sendgrid_v2_client = sendgrid_mock

	with patch('src.main.sendgrid.Mail') as mail_mock:
		return_mock = MagicMock()
		mail_mock.return_value = return_mock
		service.send_templated_email(
			to_email="Test Account <[email protected]>",
			from_email="[email protected]",
			subject="test subject",
			template_id="MY-FAVORITE-TEMPLATE",
		)

		mail_mock.assert_called_once_with(
			to="Test Account <[email protected]>",
			from_email="[email protected]",
			subject="test subject",
			html=" ",
		)
		return_mock.add_filter.assert_any_call(
			'templates',
			'enable',
			'1'
		)
		return_mock.add_filter.assert_any_call(
			'templates',
			'template_id',
			'MY-FAVORITE-TEMPLATE'
		)
开发者ID:mrhwick,项目名称:nameko-sendgrid,代码行数:36,代码来源:tests.py

示例2: test_send_twitch_messge

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [as 别名]
    def test_send_twitch_messge(self):
        '''Tests send twitch message'''
        socket_mock = MagicMock()
        socket_mock.send = MagicMock(return_value=True)

        channel = 'example-channel'
        message = 'example-message'
        twitch_sender = TwitchChatSenderWorker()
        twitch_sender.send_twitch_messge(channel, message)

        socket_mock.send.assert_called_with("PRIVMSG " + "#" + channel + " :" + message + "\r\n")
开发者ID:TheWeirdlings,项目名称:TwitchTube,代码行数:13,代码来源:test_TwitchChatSender.py

示例3: test_close_connection

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例4: test_delete_all_mails

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例5: test_send_list

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例6: test_send_pass_correct

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例7: test_send_user_incorrect

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例8: test_send_pass_incorrect

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [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

示例9: test_send_email_calls_sendgrid_v2_with_created_message

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [as 别名]
def test_send_email_calls_sendgrid_v2_with_created_message():
	service = SendgridService()
	
	sendgrid_mock = MagicMock()
	send_method_mock = MagicMock()
	send_method_mock.return_value = (200, 'some message')
	sendgrid_mock.send = send_method_mock
	service.sendgrid_v2_client = sendgrid_mock


	with patch('src.main.sendgrid.Mail') as mail_mock:
		return_mock = MagicMock()
		mail_mock.return_value = return_mock

		service.send_email(
			to_email="Test Account <[email protected]>",
			from_email="[email protected]",
			subject="test subject",
			body_html="test body html",
			body_text="test body text",
		)

		send_method_mock.assert_called_once_with(return_mock)
开发者ID:mrhwick,项目名称:nameko-sendgrid,代码行数:25,代码来源:tests.py

示例10: mock_socket

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import send [as 别名]
def mock_socket(send=None):
    socket = MagicMock()
    socket.send = send or Mock()
    return socket
开发者ID:piratus,项目名称:gomoku,代码行数:6,代码来源:utils.py


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