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


Python Mock.data方法代码示例

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


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

示例1: _create_execution_mocks

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def _create_execution_mocks(self, pool, status, side=None, valid=True):
     response = Mock()
     pool.urlopen.return_value = response
     if valid:
         response.data = RESPONSE_DATA
     else:
         response.data = INVALID_RESPONSE_DATA
     response.status = status
     if side:
         pool.urlopen.side_effect = side
     return response
开发者ID:mgarski,项目名称:stellr,代码行数:13,代码来源:stellr_test.py

示例2: _populate_field

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def _populate_field(self, field, hp_field_data=None, hash_control=None):
     field.private_key = 'private'
     field.timeout = 2000
     first = Mock(name='first')
     first.data = hp_field_data
     first.name = u'first'
     control = Mock(control='control')
     now = datetime.now().strftime('%s')
     control.name = HoneyPotField.get_control_prefix() + now
     field.entries = [first]
     control.data = hash_control if hash_control else field.hash_entries(now)
     field.entries.append(control)
开发者ID:mmilkin,项目名称:flask_wtf_honeypot,代码行数:14,代码来源:test_fields.py

示例3: test_update_comment

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_update_comment(self):
        org = self.organization

        self.user.name = 'Sentry Admin'
        self.user.save()
        self.login_as(self.user)

        integration = Integration.objects.create(
            provider='jira',
            name='Example Jira',
        )
        integration.add_organization(org, self.user)
        installation = integration.get_installation(org.id)

        group_note = Mock()
        comment = 'hello world\nThis is a comment.\n\n\n    I\'ve changed it'
        group_note.data = {}
        group_note.data['text'] = comment
        group_note.data['external_id'] = '123'
        with mock.patch.object(MockJiraApiClient, 'update_comment') as mock_update_comment:
            def get_client():
                return MockJiraApiClient()

            with mock.patch.object(installation, 'get_client', get_client):
                installation.update_comment(1, self.user.id, group_note)
                assert mock_update_comment.call_args[0] == \
                    (1, '123', 'Sentry Admin wrote:\n\n{quote}%s{quote}' % comment)
开发者ID:yaoqi,项目名称:sentry,代码行数:29,代码来源:test_integration.py

示例4: test_handle_error_signal

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_handle_error_signal(self):
        if not signals_available:
            # This test requires the blinker lib to run.
            print("Can't test signals without signal support")
            return
        app = Flask(__name__)
        api = flask_restful.Api(app)

        exception = Mock()
        exception.code = 400
        exception.data = {'foo': 'bar'}

        recorded = []

        def record(sender, exception):
            recorded.append(exception)

        got_request_exception.connect(record, app)
        try:
            with app.test_request_context("/foo"):
                api.handle_error(exception)
                self.assertEquals(len(recorded), 1)
                self.assertTrue(exception is recorded[0])
        finally:
            got_request_exception.disconnect(record, app)
开发者ID:fengshao0907,项目名称:flask-restful,代码行数:27,代码来源:test_api.py

示例5: test_incremental_crawl

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def test_incremental_crawl(self, bucket_mock, conn_mock):
     the_past = epoch.from_date(timezone.now() - timedelta(days=365))
     # Test runs in under a second typically, so we need to be slightly
     # behind present time, so that we can see fbm.incremental_epoch
     # get updated
     present = epoch.from_date(timezone.now() - timedelta(seconds=30))
     fbm = models.FBSyncMap.items.create(
         fbid_primary=self.fbid, fbid_secondary=self.fbid, token=self.token.token,
         back_filled=False, back_fill_epoch=the_past,
         incremental_epoch=present,
         status=models.FBSyncMap.COMPLETE, bucket='test_bucket_0'
     )
     existing_key = Mock()
     existing_key.data = {"updated": 1, "data": [{"test": "testing"}]}
     bucket_mock.return_value = existing_key
     conn_mock.return_value = s3_feed.BucketManager()
     tasks.incremental_crawl(fbm.fbid_primary, fbm.fbid_secondary)
     new_fbm = models.FBSyncMap.items.get_item(
         fbid_primary=self.fbid, fbid_secondary=self.fbid)
     self.assertEqual(fbm.status, fbm.COMPLETE)
     self.assertGreater(int(new_fbm.incremental_epoch), present)
     self.assertTrue(existing_key.extend_s3_data.called)
     self.assertSequenceEqual(
         existing_key.extend_s3_data.call_args_list[0][0],
         (False,)
     )
开发者ID:edgeflip,项目名称:edgeflip,代码行数:28,代码来源:test_tasks.py

示例6: test_download

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_download(self, mock_repo_controller, mock_dl_request):
        # Setup
        mock_catalog = Mock()
        mock_catalog.importer_id = 'mock_id'
        mock_catalog.url = 'http://dev.null/'
        mock_catalog.data = {'k': 'v'}
        mock_request = Mock()
        mock_data = {'catalog_entry': mock_catalog, 'client_request': mock_request}
        mock_responder = Mock()
        mock_importer = Mock()
        mock_importer_config = Mock()
        mock_downloader = mock_importer.get_downloader.return_value
        mock_repo_controller.get_importer_by_id.return_value = (mock_importer,
                                                                mock_importer_config)

        # Test
        self.streamer._download(mock_catalog, mock_request, mock_responder)
        mock_repo_controller.get_importer_by_id.assert_called_once_with(mock_catalog.importer_id)
        mock_dl_request.assert_called_once_with(mock_catalog.url, mock_responder, data=mock_data)
        mock_importer.get_downloader.assert_called_once_with(
            mock_importer_config, mock_catalog.url, **mock_catalog.data)
        self.assertEqual(mock_request, mock_downloader.event_listener.request)
        self.assertEqual(self.config, mock_downloader.event_listener.streamer_config)
        mock_downloader.download_one.assert_called_once_with(mock_dl_request.return_value,
                                                             events=True)
        mock_downloader.config.finalize.assert_called_once_with()
开发者ID:maxamillion,项目名称:pulp,代码行数:28,代码来源:test_server.py

示例7: test_response_matches_strictly

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_response_matches_strictly(self):
        sample = _abe_wrap_response({
            "status": 201,
            "body": {
                "id": 12,
                "name": "My Resource",
                "url": "http://example.com/resource/12",
                "author": {
                    "name": "Slough",
                    "url": "http://example.com/user/25"
                }
            }
        })
        response = Mock()
        response.status_code = 201
        response.data = {
            "id": 12,
            "name": "My Resource",
            "url": "http://example.com/resource/12",
            "author": {
                "name": "Slough",
                "url": "http://example.com/user/25"
            }
        }

        self.assert_matches_response(
            sample, response
        )
开发者ID:apibyexample,项目名称:abe-python,代码行数:30,代码来源:test_assertions.py

示例8: test_formats_group_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def test_formats_group_data(self):
     data = {'group_name': 'bob', 'group_color': 'red'}
     user = Mock()
     user.data = {}
     message = Clue(text='Hello {group_name}, you like {group_color}?')
     response = format_message(message, user, Group(data=data))
     self.assertEqual('Hello bob, you like red?', response.text)
开发者ID:ChrisPenner,项目名称:scavenger,代码行数:9,代码来源:test_scavenger.py

示例9: test_get_redirect_history_from_task_when_suspicious_in_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_get_redirect_history_from_task_when_suspicious_in_data(self, get_r_history_m, to_uni_m):
        task_mock = Mock(None)
        task_mock.data = {
            'recheck': False,
            'url': 'www.leningrad.spb.ru',
            'url_id': 666,
            'suspicious': 'whazzzup'
        }
        test_history_types = ['APPLE', 'BLACKBERRY']
        test_history_urls = ['apple.com', 'blackberry.com']
        test_counters = ['a', 'b']
        get_r_history_m.return_value = test_history_types,  test_history_urls, test_counters
        url_mock = Mock(None)
        to_uni_m.return_value = url_mock

        res_is_input, res_data = wr.get_redirect_history_from_task(task_mock, 42)

        self.assertFalse(res_is_input)
        test_data = {
            'url_id': 666,
            'result': [test_history_types, test_history_urls, test_counters],
            'check_type': 'normal',
            'suspicious': 'whazzzup'
        }
        self.assertEqual(res_data, test_data)
开发者ID:esusekov,项目名称:tech-testing-ha1,代码行数:27,代码来源:test_worker.py

示例10: test_save

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_save(self, mock_dump, mock_open):
        core = Mock()
        ts = self.get_obj(core)
        queue = Mock()
        queue.empty = Mock(side_effect=Empty)
        ts.work_queue = queue

        mock_open.side_effect = IOError
        # test that save does _not_ raise an exception even when
        # everything goes pear-shaped
        ts._save()
        queue.empty.assert_any_call()
        mock_open.assert_called_with(ts.pending_file, 'w')

        queue.reset_mock()
        mock_open.reset_mock()

        queue.data = []
        for hostname, xml in self.data:
            md = Mock()
            md.hostname = hostname
            queue.data.append((md, lxml.etree.XML(xml)))
        queue.empty.side_effect = lambda: len(queue.data) == 0
        queue.get_nowait = Mock(side_effect=lambda: queue.data.pop())
        mock_open.side_effect = None

        ts._save()
        queue.empty.assert_any_call()
        queue.get_nowait.assert_any_call()
        mock_open.assert_called_with(ts.pending_file, 'w')
        mock_open.return_value.close.assert_any_call()
        # the order of the queue data gets changed, so we have to
        # verify this call in an ugly way
        self.assertItemsEqual(mock_dump.call_args[0][0], self.data)
        self.assertEqual(mock_dump.call_args[0][1], mock_open.return_value)
开发者ID:psteinbachs,项目名称:bcfg2,代码行数:37,代码来源:Testinterfaces.py

示例11: test_load_config_bad_data

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def test_load_config_bad_data(self):
     with patch.object(self.driver, "_etcd_request") as m_etcd_req:
         m_resp = Mock()
         m_resp.data = "{garbage"
         m_etcd_req.return_value = m_resp
         self.assertRaises(ResyncRequired,
                           self.driver._load_config, "/calico/v1/config")
开发者ID:elfchief,项目名称:calico,代码行数:9,代码来源:test_driver.py

示例12: test_handle_smart_errors

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_handle_smart_errors(self):
        app = Flask(__name__)
        api = flask_restful.Api(app)
        view = flask_restful.Resource

        exception = Mock()
        exception.code = 404
        exception.data = {"status": 404, "message": "Not Found"}
        api.add_resource(view, '/foo', endpoint='bor')
        api.add_resource(view, '/fee', endpoint='bir')
        api.add_resource(view, '/fii', endpoint='ber')


        with app.test_request_context("/faaaaa"):
            resp = api.handle_error(exception)
            self.assertEquals(resp.status_code, 404)
            self.assertEquals(resp.data, dumps({
                "status": 404, "message": "Not Found",
            }))

        with app.test_request_context("/fOo"):
            resp = api.handle_error(exception)
            self.assertEquals(resp.status_code, 404)
            self.assertEquals(resp.data, dumps({
                "status": 404, "message": "Not Found. You have requested this URI [/fOo] but did you mean /foo ?",
            }))

        with app.test_request_context("/fOo"):
            del exception.data["message"]
            resp = api.handle_error(exception)
            self.assertEquals(resp.status_code, 404)
            self.assertEquals(resp.data, dumps({
                "status": 404, "message": "You have requested this URI [/fOo] but did you mean /foo ?",
            }))
开发者ID:undeadking,项目名称:flask-restful,代码行数:36,代码来源:test_api.py

示例13: test_non_strict_response_matches

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
    def test_non_strict_response_matches(self):
        sample = _abe_wrap_response({
            "status": 201,
            "body": {
                "id": 12,
                "name": "My Resource",
                "url": "http://example.com/resource/12",
                "author": {
                    "name": "Slough",
                    "url": "http://example.com/user/25"
                }
            }
        })
        response = Mock()
        response.status_code = 201
        response.data = {
            "id": 25,
            "name": "My Resource",
            "url": "http://example.com/resource/12312",
            "author": {
                "name": "Slough",
                "url": "http://testserver/25/"
            }
        }

        self.assert_matches_response(
            sample, response,
            non_strict=['id', 'url', 'author.url']
        )
开发者ID:apibyexample,项目名称:abe-python,代码行数:31,代码来源:test_assertions.py

示例14: _dict_mock

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
 def _dict_mock(self, **kwargs):
     """
     Get a mock that allows __getitem__
     """
     item = Mock()
     item.data = kwargs
     item.__getitem__ = lambda s, k: s.data[k]
     return item
开发者ID:alfredodeza,项目名称:helga,代码行数:10,代码来源:test_xmpp.py

示例15: test_main

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import data [as 别名]
def test_main(pclass, unpickle, pickle):
    p = Mock()
    pclass.return_value = p
    subsample = Mock()
    subsample.data = cars
    unpickle.return_value = subsample
    factor_analysis._main(['foo.subsample', '5', 'foo.famodel'])
    pclass.assert_called_once()
开发者ID:AnneCarpenter,项目名称:CellProfiler-Analyst,代码行数:10,代码来源:test_factor_analysis.py


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