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


Python MagicMock.content方法代码示例

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


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

示例1: test_leave_server_command_execute

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
    def test_leave_server_command_execute(self):
        client = MagicMock()
        message = MagicMock(content='.leave')

        # No args
        client.send_message = MagicMock()
        client.leave_server = MagicMock()
        leave_cmd = actions.admin_commands.LeaveServerCommand(client, message)
        self.assertTrue(leave_cmd.execute())
        client.send_message.assert_called_once_with(message.channel, 'Farewell!')
        client.leave_server.assert_called_once_with(message.server)

        # With args
        message.content = '.leave 12083t1141241'
        server = MagicMock(name='12083t1141241', id='12083t1141241')
        client.servers = [server]
        client.send_message = MagicMock()
        client.leave_server = MagicMock()
        leave_cmd = actions.admin_commands.LeaveServerCommand(client, message)
        self.assertTrue(leave_cmd.execute())
        client.send_message.assert_called_once_with(message.channel, 'Leaving server: {}'.format(server.name))
        client.leave_server.assert_called_once_with(server)

        # Exception
        client.send_message = MagicMock()
        client.leave_server = MagicMock()
        client.leave_server.side_effect = actions.admin_commands.HTTPException(MagicMock())
        leave_cmd = actions.admin_commands.LeaveServerCommand(client, message)
        self.assertEqual(leave_cmd.execute(), 'The leave command failed')
开发者ID:stuckshut,项目名称:eris,代码行数:31,代码来源:test_admin_commands.py

示例2: mock_request

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
 def mock_request(self, body, status=0):
     if self.mock_api:
         json_content = {'status': status}
         if body is not None:
             json_content['body'] = body
         response = MagicMock()
         response.content = json.dumps(json_content).encode('utf8')
         Session.request = MagicMock(return_value=response)
开发者ID:orcasgit,项目名称:python-withings,代码行数:10,代码来源:test_nokia_api.py

示例3: test_join_server_command_execute

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
    def test_join_server_command_execute(self):
        client = MagicMock()
        message = MagicMock(content='.join')

        # No args
        join_cmd = actions.admin_commands.JoinServerCommand(client, message)
        self.assertEqual(join_cmd.execute(), 'What do you want me to join?')

        # Server problem or expired invite
        client.accept_invite.side_effect = actions.HTTPException(MagicMock())
        message.content = '.join http://null.null/123123123'
        join_cmd = actions.admin_commands.JoinServerCommand(client, message)
        self.assertEqual(join_cmd.execute(), "I couldn't accept that request for some reason")

        # Invalid arg
        client.accept_invite.side_effect = actions.InvalidArgument()
        message.content = '.join 2t94awgh-348yq3=4tq34=8tqa='
        join_cmd = actions.admin_commands.JoinServerCommand(client, message)
        self.assertEqual(join_cmd.execute(), 'That is not a valid request')
开发者ID:stuckshut,项目名称:eris,代码行数:21,代码来源:test_admin_commands.py

示例4: get

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
def get(url, **kwargs):
    root = os.path.join(os.path.dirname(__file__), 'statics')
    load = lambda x: open(os.path.join(root, x), 'rb').read()
    response = MagicMock(spec=requests.Response)
    if url == 'feed_url':
        response.text = load('feed.xml')
    elif url == 'entry_url':
        response.text = load('entry.html')
    elif url == 'thumbnail_url':
        response.content = load('thumbnail.png')
    return response
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:13,代码来源:test_scraper.py

示例5: test_analize_object_for_watchers_adding_owner_non_empty_comment

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
def test_analize_object_for_watchers_adding_owner_non_empty_comment():
    user1 = f.UserFactory.create()

    issue = MagicMock()
    issue.description = "Foo"
    issue.content = ""

    history = MagicMock()
    history.comment = "Comment"
    history.owner = user1

    services.analize_object_for_watchers(issue, history.comment, history.owner)
    assert issue.add_watcher.call_count == 1
开发者ID:tnir,项目名称:taiga-back,代码行数:15,代码来源:test_notifications.py

示例6: test__get_resource

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
    def test__get_resource(self, req_mock):
        ex_content = b'1.1.1.1\n2.2.2.2\n'
        expected = Resource(ex_content, self.url, 200)

        response_mock = MagicMock()
        response_mock.status_code = 200
        response_mock.url = self.url
        response_mock.content = ex_content

        req_mock.get.return_value = response_mock

        result = self.fetcher._get_resource(self.fetcher.url)
        self.assertEqual(result, expected)
开发者ID:flazzarini,项目名称:blocklister,代码行数:15,代码来源:test_fetcher.py

示例7: build

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
 def build(self):
     m = MagicMock()
     m.text = self._text
     m.url = self._url
     m.status_code = self._status_code
     m.headers = CaseInsensitiveDict({
         "content-type": self._content_type
     })
     m.content = self._content
     m.encoding = self._encoding
     m.elapsed = datetime.timedelta(seconds=self._seconds, microseconds=self._microseconds)
     m.json.return_value = self._json
     return m
开发者ID:tadashi-aikawa,项目名称:gemini,代码行数:15,代码来源:test_executor.py

示例8: test_analize_object_for_watchers

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
def test_analize_object_for_watchers():
    user1 = f.UserFactory.create()
    user2 = f.UserFactory.create()

    issue = MagicMock()
    issue.description = "Foo @{0} @{1} ".format(user1.username, user2.username)
    issue.content = ""

    history = MagicMock()
    history.comment = ""

    services.analize_object_for_watchers(issue, history.comment, history.owner)
    assert issue.add_watcher.call_count == 2
开发者ID:andrewchenshx,项目名称:taiga-back,代码行数:15,代码来源:test_notifications.py

示例9: get_method_mock

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
        def get_method_mock(*args, **kwargs):
            """
            Mocks called urls:

            1. /user/GatewayList
            2. /gateway/gatewaydata?gtMacID="..."&...

            :param args:
            :param kwargs:
            :return:
            """

            gatewaydata_path = 'gatewaydata'
            gateway_list_path = 'GatewayList'

            # comes in form 'http://test.com/section/command' - we want to split to get the command
            path_segment = args[0].split('/')[4].split('?')[0]
            mm = MagicMock()
            mm.status_code = 200

            content = '{"message": "not implemented"}'
            if path_segment == gatewaydata_path:

                if SecureAPITests.mock_call_counter % 2 == 0:
                    print('online')
                    gcs_data = SecureAPITests.gw_online

                if SecureAPITests.mock_call_counter % 2 == 1:
                    print('offline')
                    gcs_data = SecureAPITests.gw_offline

                # special case
                if SecureAPITests.mock_call_counter == 3:
                    gcs_data = SecureAPITests.capability_push_response
                    mm.status_code = 400

                content = gcs_data

                SecureAPITests.mock_call_counter += 1

            if path_segment == gateway_list_path:
                content = SecureAPITests.gateway_list

            mm.content = content

            return mm
开发者ID:dschien,项目名称:energy-aggregator,代码行数:48,代码来源:tests.py

示例10: test__get_resource_gziped

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
    def test__get_resource_gziped(self, req_mock):
        ex_content = b'1.1.1.1\n2.2.2.2\n'
        expected = Resource(ex_content, self.gzip_url, 200)

        # To test gzip decompression lets gzip our `ex_content`
        ex_content_gziped = BytesIO()
        g = GzipFile(fileobj=ex_content_gziped, mode='w', compresslevel=5)
        g.write(ex_content)
        g.close()
        ex_content_gziped.seek(0)

        response_mock = MagicMock()
        response_mock.status_code = 200
        response_mock.url = self.gzip_url
        response_mock.content = ex_content_gziped.read()

        req_mock.get.return_value = response_mock

        result = self.fetcher._get_resource(self.gzip_url)
        self.assertEqual(result, expected)
开发者ID:flazzarini,项目名称:blocklister,代码行数:22,代码来源:test_fetcher.py

示例11: make_response

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
 def make_response(self, json_string, status=200, headers=None):
     response = MagicMock()
     response.status_code = status
     response.headers = headers or dict()
     response.content = json_string
     return ResponseWrapper(response)
开发者ID:evilkost,项目名称:copr,代码行数:8,代码来源:test_handlers.py

示例12: produce_requests_response_object

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import content [as 别名]
def produce_requests_response_object(status_code, content):
    requests_mock = MagicMock()
    requests_mock.status_code = status_code
    requests_mock.content = content

    return requests_mock
开发者ID:eserge,项目名称:tpb-crawler,代码行数:8,代码来源:tests.py


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