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


Python MagicMock.data方法代码示例

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


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

示例1: test_that_it_emits_quorum_status_events

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
    def test_that_it_emits_quorum_status_events(self, client):
        new = MagicMock()
        old = MagicMock()
        old.data = {
            "election_epoch": 2,
            "monmap": {
                "created": "0.000000",
                "epoch": 1,
                "fsid": "fc0dc0f5-fe35-48c1-8c9c-f2ae0770fce7",
                "modified": "0.000000",
                "mons": [
                    {
                        "addr": "198.199.75.124:6789/0",
                        "name": "vagrant-ubuntu-trusty-64",
                        "rank": 0
                    }
                ]
            },
            "quorum": [
                0
            ],
            "quorum_leader_name": "",
            "quorum_names": [
                "vagrant-ubuntu-trusty-64"
            ]
        }

        new.data = {
            "election_epoch": 2,
            "monmap": {
                "created": "0.000000",
                "epoch": 1,
                "fsid": "fc0dc0f5-fe35-48c1-8c9c-f2ae0770fce7",
                "modified": "0.000000",
                "mons": [
                    {
                        "addr": "198.199.75.124:6789/0",
                        "name": "vagrant-ubuntu-trusty-64",
                        "rank": 0
                    }
                ]
            },
            "quorum": [
                0
            ],
            "quorum_leader_name": "vagrant-ubuntu-trusty-64",
            "quorum_names": [
                "vagrant-ubuntu-trusty-64"
            ]
        }

        self.eventer._emit = MagicMock()
        self.eventer._on_quorum_status(12345, new, new)
        self.assertFalse(self.eventer._emit.called)

        self.eventer._on_quorum_status(12345, new, old)
        message = '\n'.join([str(x) for x in self.eventer._emit.call_args_list])
        print message
        self.assertIn('now quorum leader', message)
开发者ID:ceph,项目名称:calamari,代码行数:61,代码来源:test_eventer.py

示例2: test_run

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
    def test_run(self, strp_fun):
        """Test running the ReqMan
        """
        socket = self.context.socket.return_value
        socks = ((socket, server.POLLIN),)


        cnt = [0]

        def side_effect(timeout):
            del timeout
            time.sleep(0.1)
            cnt[0] += 1
            return socks

        ping = MagicMock()
        ping.type = "ping"

        req = MagicMock()
        req.type = "request"
        req.data = {"type": "scanline",
                    "satellite": MagicMock(),
                    "utctime": MagicMock()}

        notice = MagicMock()
        notice.type = "notice"
        notice.data = {"type": "scanline"}

        unknown = MagicMock()

        msgs = [ping, req, notice, unknown]

        def msg(*args, **kwargs):
            if "rawstr" in kwargs:
                return msgs[cnt[0] % len(msgs)]
            else:
                return MagicMock()

        server.Message.side_effect = msg

        self.reqman.pong = MagicMock()
        self.reqman.notice = MagicMock()
        self.reqman.scanline = MagicMock()
        self.reqman.unknown = MagicMock()
        sys.modules["zmq"].Poller.return_value.poll.side_effect = side_effect
        self.reqman.start()
        time.sleep(0.4)
        self.reqman.stop()
        self.reqman.join()
        self.reqman.pong.assert_called_once_with()
        self.reqman.notice.assert_called_once_with(notice)
        self.reqman.scanline.assert_called_once_with(req)
        self.reqman.unknown.assert_called_once_with(unknown)
        sys.modules["zmq"].Poller.return_value.side_effect = None
        server.Message.side_effect = None
开发者ID:pytroll,项目名称:trollcast,代码行数:57,代码来源:test_server.py

示例3: test_create_patient_subrecord

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_create_patient_subrecord(self):
     mock_request = MagicMock(name='mock request')
     mock_request.user = self.user
     mock_request.data = {'name': 'blue', 'episode_id': self.episode.pk,
                          'patient_id': self.patient.pk}
     response = self.patientviewset().create(mock_request)
     self.assertEqual('blue', response.data['name'])
开发者ID:wjt,项目名称:opal,代码行数:9,代码来源:test_api.py

示例4: test_update_item_changed

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
    def test_update_item_changed(self):
        created = timezone.now() - timedelta(1)

        colour = Colour.objects.create(
            name='blue',
            episode=self.episode,
            consistency_token='frist',
            created_by=self.user,
            created=created,
        )
        mock_request = MagicMock(name='mock request')
        mock_request.data = {
            'name': 'green',
            'episode_id': self.episode.pk,
            'id': colour.pk,
            'consistency_token': 'wat'
        }
        mock_request.user = self.user
        response = self.viewset().update(mock_request, pk=colour.pk)
        colour = Colour.objects.get()
        self.assertEqual(created, colour.created)
        self.assertEqual(self.user, colour.created_by)
        self.assertIsNone(colour.updated)
        self.assertIsNone(colour.updated_by)
        self.assertEqual(409, response.status_code)
开发者ID:wjt,项目名称:opal,代码行数:27,代码来源:test_api.py

示例5: test_load

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
    def test_load(self):
        """tests load method"""

        mock_run_statement = MagicMock()
        MySqlDatabase.run_statement = mock_run_statement

        config = MagicMock()
        config.schema = self.schema
        config.data = self.data
        fixture = MySqlFixture(
            config=config
        )

        fixture.load()

        # Brittle way of testing that insert statement is run
        # Assumes the keys of first row in self.data are the fields to insert
        data_row = self.data[0]
        stmnt_fields, expected_statement = MySqlInsertStatementMixin.create_insert_statement(
            table=self.schema.config.get_table(),
            fields=data_row.keys(),
            statement_string=True
        )

        expected_params = [data_row[field] for field in stmnt_fields]

        mock_run_statement.assert_called_with(
            expected_statement,
            params=expected_params,
            commit=True
        )
开发者ID:pantheon-systems,项目名称:etl-framework,代码行数:33,代码来源:test_mysql_fixture.py

示例6: create_mocked_result_set

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def create_mocked_result_set(self, n):
     rs = []
     for i in range(n):
         mock_record = MagicMock()
         mock_record.data = 'data{0}'.format(i)
         rs.append(mock_record)
     mock_conn.search.return_value = rs
开发者ID:alexandermendes,项目名称:Flask-Z3950,代码行数:9,代码来源:test_z3950.py

示例7: test_filter_message_with_uri_gets_expanded

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
    def test_filter_message_with_uri_gets_expanded(self):
        filter_message = json.dumps({
            'filter': {
                'actions': {},
                'match_policy': 'include_all',
                'clauses': [{
                    'field': '/uri',
                    'operator': 'equals',
                    'value': 'http://example.com',
                }],
            }
        })

        with patch('h.api.uri.expand') as expand:
            expand.return_value = ['http://example.com',
                                   'http://example.com/alter',
                                   'http://example.com/print']
            msg = MagicMock()
            msg.data = filter_message

            self.s.received_message(msg)

            uri_filter = self.s.filter.filter['clauses'][0]
            uri_values = uri_filter['value']
            assert len(uri_values) == 3
            assert 'http://example.com' in uri_values
            assert 'http://example.com/alter' in uri_values
            assert 'http://example.com/print' in uri_values
开发者ID:coolcool21,项目名称:h,代码行数:30,代码来源:streamer_test.py

示例8: test_parse_bool_post

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_parse_bool_post(self):
     '''Tests parsing a required bool parameter that is provided via POST.'''
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test': 'true',
     })
     self.assertTrue(rest_util.parse_bool(request, 'test'))
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例9: test_check_update

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_check_update(self):
     '''Tests checking a white-list of parameters allowed to be updated during a POST.'''
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test': 'value1',
     })
     self.assertTrue(rest_util.check_update(request, ['test']))
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例10: test_parse_int_post

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_parse_int_post(self):
     """Tests parsing a required int parameter that is provided via POST."""
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test': '10',
     })
     self.assertEqual(rest_util.parse_int(request, 'test'), 10)
开发者ID:ngageoint,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例11: test_that_it_emits_added_osd_events

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_that_it_emits_added_osd_events(self):
     self.eventer._emit = MagicMock()
     new = MagicMock()
     old = MagicMock()
     new.data = {}
     new.data['osds'] = [{'osd': 0}]
     self.eventer._on_osd_map(12345, new, old)
     self.assertIn('added to the cluster map', '\n'.join([str(x) for x in self.eventer._emit.call_args_list]))
开发者ID:ceph,项目名称:calamari,代码行数:10,代码来源:test_eventer.py

示例12: test_data_messages

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_data_messages(self):
     client, collection, data, subset = self._create_objects()
     m = MagicMock()
     m.data = data
     client.add_layer(data)
     client._update_data(m)
     client._remove_data(m)
     assert not client.layer_present(data)
开发者ID:ChrisBeaumont,项目名称:glue,代码行数:10,代码来源:test_client.py

示例13: test_parse_float_post

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_parse_float_post(self):
     '''Tests parsing a required float parameter that is provided via POST.'''
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test': '10.1',
     })
     self.assertEqual(rest_util.parse_float(request, 'test'), 10.1)
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例14: test_check_bad_param_type

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_check_bad_param_type(self):
     """Tests checking a white-list of invalid parameters allowed to be updated during a POST."""
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test1': 'value1',
         'test2': 'value2',
     })
     self.assertRaises(AssertionError, rest_util.check_update, request, 'test1')
开发者ID:ngageoint,项目名称:scale,代码行数:11,代码来源:test_rest.py

示例15: test_check_update_invalid

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import data [as 别名]
 def test_check_update_invalid(self):
     '''Tests checking a white-list of invalid parameters allowed to be updated during a POST.'''
     request = MagicMock(Request)
     request.data = QueryDict('', mutable=True)
     request.data.update({
         'test1': 'value1',
         'test2': 'value2',
     })
     self.assertRaises(ReadOnly, rest_util.check_update, request, ['test1'])
开发者ID:AppliedIS,项目名称:scale,代码行数:11,代码来源:test_rest.py


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