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


Python MagicMock.body方法代码示例

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


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

示例1: test_Forward_PM_Answer

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
    def test_Forward_PM_Answer(self):
        r = MagicMock()
        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = credentials.admin_username
        msg.id = 'msgid2'
        msg.distinguished = None
        msg.subject = 're: #msgid1 /u/user: "sub"'
        msg.body = 'body'
        pmUserCache = { }

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=([], 'text'))

        oldMsg = MagicMock()
        r.inbox.message = MagicMock(return_value=oldMsg)

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue(msg.author.name not in pmUserCache, "don't admin")

        expected = [call.inbox.message('msgid1')]
        self.assertEqual(r.method_calls, expected, 'reddit call')

        expected = [call.message('msgid1')]
        self.assertEqual(r.inbox.method_calls, expected, 'get old msg')

        expected = [call.reply('body')]
        self.assertEqual(oldMsg.method_calls, expected, 'reply old')

        expected = [call.reply('answer forwarded')]
        self.assertEqual(msg.method_calls, expected, 'reply new')

        self.assertEqual(helper.method_calls, [], 'no helper calls')
开发者ID:d-schmidt,项目名称:hearthscan-bot,代码行数:37,代码来源:test.py

示例2: test_Forward_PM

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
    def test_Forward_PM(self):
        r = MagicMock()
        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = 'user'
        msg.id = 'msgidpm'
        msg.distinguished = None
        msg.subject = 'sub'
        msg.body = 'body'
        pmUserCache = { }

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=([], ''))

        redMsg = MagicMock()
        r.redditor = MagicMock(return_value=redMsg)

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue('user' in pmUserCache, 'user added to cache')

        expected = [call.redditor(credentials.admin_username)]
        self.assertEqual(r.method_calls, expected, 'get redditor')

        expected = [call.message('#msgidpm /u/user: "sub"', msg.body)]
        self.assertEqual(redMsg.method_calls, expected, 'set message')

        expected = [call.parseText('sub body')]
        self.assertEqual(helper.method_calls, expected, 'parseText')
        self.assertEqual(msg.method_calls, [], 'no reply')
开发者ID:d-schmidt,项目名称:hearthscan-bot,代码行数:33,代码来源:test.py

示例3: test_AnswerMail_Success

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

        msg = MagicMock()
        msg.subreddit = None
        msg.author.name = 'user'
        msg.id = 'msgids'
        msg.distinguished = None
        msg.subject = 'sub'
        msg.body = 'body'
        pmUserCache = { }

        helper = MagicMock()
        helper.parseText = MagicMock(return_value=(['card'], 'text'))

        # test
        hsbot.answerPM(r, msg, pmUserCache, helper)

        self.assertTrue('user' in pmUserCache, 'user added to cache')

        self.assertEqual(r.method_calls, [], 'no reddit calls')
        expected = [call.parseText('sub body')]
        self.assertEqual(helper.method_calls, expected, 'parseText')
        expected = [call.reply('text')]
        self.assertEqual(msg.method_calls, expected, 'reply')
开发者ID:d-schmidt,项目名称:hearthscan-bot,代码行数:27,代码来源:test.py

示例4: test_sqs_message_processor

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
    def test_sqs_message_processor(self):
        mock = MagicMock()
        mock.body = '{"Records":[{"s3":{"bucket":{"name":"name"},"object":{"key":"key"}}}]}'
        processor = SQSMessageProcessor()
        with patch.object(SQSMessageProcessor, 'processor_class', create=True) as mock_processor_class:
            processor.process(mock)

        mock_processor_class.assert_has_calls([
            call(),
            call().process({'Records': [{'s3': {'bucket': {'name': 'name'}, 'object': {'key': 'key'}}}]})])

        mock.assert_has_calls([call.delete()])
开发者ID:naveenlj,项目名称:python-sqs-consumer,代码行数:14,代码来源:test_processor.py

示例5: test_get_file

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
def test_get_file(http_controller, tmpdir, project, node, compute):
    response = MagicMock()
    response.body = b"world"
    compute.http_query = AsyncioMagicMock(return_value=response)
    response = http_controller.get("/projects/{project_id}/nodes/{node_id}/files/hello".format(project_id=project.id, node_id=node.id), raw=True)
    assert response.status == 200
    assert response.body == b'world'

    compute.http_query.assert_called_with("GET", "/projects/{project_id}/files/project-files/vpcs/{node_id}/hello".format(project_id=project.id, node_id=node.id), timeout=None, raw=True)

    response = http_controller.get("/projects/{project_id}/nodes/{node_id}/files/../hello".format(project_id=project.id, node_id=node.id), raw=True)
    assert response.status == 404
开发者ID:GNS3,项目名称:gns3-server,代码行数:14,代码来源:test_node.py

示例6: test_get_and_post_with_nested_paths_normalization

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
def test_get_and_post_with_nested_paths_normalization(http_controller, tmpdir, project, node, compute):
    response = MagicMock()
    response.body = b"world"
    compute.http_query = AsyncioMagicMock(return_value=response)
    response = http_controller.get("/projects/{project_id}/nodes/{node_id}/files/hello\\nested".format(project_id=project.id, node_id=node.id), raw=True)
    assert response.status == 200
    assert response.body == b'world'

    compute.http_query.assert_called_with("GET", "/projects/{project_id}/files/project-files/vpcs/{node_id}/hello/nested".format(project_id=project.id, node_id=node.id), timeout=None, raw=True)

    compute.http_query = AsyncioMagicMock()
    response = http_controller.post("/projects/{project_id}/nodes/{node_id}/files/hello\\nested".format(project_id=project.id, node_id=node.id), body=b"hello", raw=True)
    assert response.status == 201

    compute.http_query.assert_called_with("POST", "/projects/{project_id}/files/project-files/vpcs/{node_id}/hello/nested".format(project_id=project.id, node_id=node.id), data=b'hello', timeout=None, raw=True)
开发者ID:GNS3,项目名称:gns3-server,代码行数:17,代码来源:test_node.py

示例7: _mock_github

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
 def _mock_github(self):
     with patch("github.Github") as MockGh:
         instance = MockGh.return_value
         instance.get_user.return_value = instance.get_repo.return_value = instance
         mockissue = MagicMock("mockissue")
         mockmile = MagicMock("mockmile")
         mockmile.title = "issue.milestone"
         mockmile.return_value = True
         instance.get_issues.return_value = [mockissue]
         mockissue.labels = [{"la": "red"}, {"lb": "green"}]
         mockissue.title = "ta"
         mockissue.number = "2016"
         mockissue.body = "issue.body"
         mockissue.milestone = mockmile
         mockissue.state = "issue.state"
         return instance, mockmile
开发者ID:labase,项目名称:activlets,代码行数:18,代码来源:test_model.py

示例8: test_cunsume_message

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
    def test_cunsume_message(self):
        message = MagicMock()
        message.body = '{"Records":[{"s3":{"bucket":{"name":"name"},"object":{"key":"key"}}}]}'
        queue = MagicMock()
        queue.receive_messages = MagicMock(return_value=[message])

        class _SQSMessagesProcessor(SQSMessagesProcessor):
            def __init__(self):
                self.processor_class = SQSMessageProcessor

        consumer = SQSConsumerPool(max_threads=1, processor_class=_SQSMessagesProcessor, queue_name=self.queue_name)

        with patch.object(SQSMessageProcessor, 'processor_class', create=True) as mock_processor_class:
            consumer.consume(queue)

        mock_processor_class.assert_has_calls([
            call(),
            call().process({'Records': [{'s3': {'bucket': {'name': 'name'}, 'object': {'key': 'key'}}}]})])
开发者ID:naveenlj,项目名称:python-sqs-consumer,代码行数:20,代码来源:test_sqs_consumer_pool.py

示例9: init_issues

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import body [as 别名]
 def init_issues(self):
     issue = MagicMock()
     repository = MagicMock()
     repository.url = "repository_url"
     issue.id = 3
     issue.url = "issue_url"
     issue.repository = repository
     issue.labels_url = "labels_url"
     issue.comments_url = "comments_url"
     issue.events_url = "events_url"
     issue.html_url = "html_url"
     issue.number = 5
     issue.state = "open"
     issue.title = "title"
     issue.body = "git gud or git rekt"
     issue.user = self.init_user(self)
     issue.assignee = None
     issue.milestone = None
     issue.labels = None
     issue.comments = "comments"
     issue.pull_request = None
     return [issue]
开发者ID:luiseduardo1,项目名称:Github-API,代码行数:24,代码来源:GithubTest.py


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