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


Python MagicMock.assert_has_calls方法代码示例

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


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

示例1: test_mapper_args_value

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_mapper_args_value(self, db, bridge, mocker):
        """
        Test checks:
        1) that 'FeedItem' class is instantiated once with correct arguments
        2) that 'self.mapper' method is called once with correct arguments,
        Actually, with the item yielded by 'get_tenders' function.
        3) that 'self.mapper' was called AFTER 'FeedItem' class instantiated.
        """
        mock_feed_item = mocker.patch.object(databridge_module, 'FeedItem',
                                             side_effect=FeedItem,
                                             autospec=True)

        manager = MagicMock()

        mock_mapper = MagicMock()
        bridge['bridge'].mapper = mock_mapper

        manager.attach_mock(mock_mapper, 'mock_mapper')
        manager.attach_mock(mock_feed_item, 'mock_feed_item')

        bridge['bridge_thread'].join(0.1)

        manager.assert_has_calls(
            [call.mock_feed_item(bridge['tenders'][0]),
             call.mock_mapper(mock_feed_item(bridge['tenders'][0]))]
        )
开发者ID:openprocurement,项目名称:openprocurement.auction,代码行数:28,代码来源:test_databridge.py

示例2: test_database_error

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_database_error(self):
        p = MagicMock(side_effect=Exception("Weird error"))
        with patch("djstatuspage.models.Status.objects.get_or_create", p):
            response = self._get_status(views.DefaultStatusPage)
            p.assert_has_calls([call(pk=1)])

        self.assertEqual(response["database"], "error")
开发者ID:redfunction,项目名称:django-statuspage,代码行数:9,代码来源:test_views.py

示例3: test_create

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_create(self):
        credentials = Credentials("abc", "def")
        service = Service(credentials)
        response = {
            'status': 'OK',
            'ssh_key': {
                'name': 'Name 1',
                'id': 1,
                'ssh_pub_key': "asr2354tegrh23425erfwerwerffghrgh3455"
            },
        }

        mock = MagicMock(return_value=response)
        service.get = mock
        key = SSHKey.create(
            service,
            "Name 1",
            "asr2354tegrh23425erfwerwerffghrgh3455"
        )
        self.assertEquals(key.id, 1)
        self.assertEquals(key.name, 'Name 1')
        self.assertEquals(key.public, "asr2354tegrh23425erfwerwerffghrgh3455")
        mock.assert_has_calls(
            [
                call(
                    'ssh_keys/new',
                    {
                        "name": "Name 1",
                        "ssh_pub_key": "asr2354tegrh23425erfwerwerffghrgh3455"
                    })
            ]
        )
开发者ID:pirate42,项目名称:docc,代码行数:34,代码来源:test_docc_api_sshkey.py

示例4: test_retry_mechanism_no_sleep

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
def test_retry_mechanism_no_sleep(pretty_api, monkeypatch):
    mocked_sleep = MagicMock()
    mocked_random = MagicMock(return_value=1)

    t.config.secure = False
    t.config.backoff_max_attempts = 5

    monkeypatch.setattr(time, 'sleep', mocked_sleep)
    monkeypatch.setattr(random, 'uniform', mocked_random)

    with pytest.raises(HTTPError):
        t.retry()

    mocked_random.assert_has_calls([
        call(0, 0.1 * 2 ** 0),
        call(0, 0.1 * 2 ** 1),
        call(0, 0.1 * 2 ** 2),
        call(0, 0.1 * 2 ** 3),
        call(0, 0.1 * 2 ** 4),
    ])

    mocked_sleep.assert_has_calls([
        call(1),
        call(1),
        call(1),
        call(1),
        call(1),
    ])
开发者ID:PressLabs,项目名称:zipa,代码行数:30,代码来源:test_retry_mechanism.py

示例5: test_get_request_exception_and_retry_and_success

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_get_request_exception_and_retry_and_success(self, Session):
        self.count = 0
        request_exception = RequestException('I raise RequestException!')
        def exception_raiser(method, url, data, params, headers=None,
                             allow_redirects=None):
            if self.count < 4:
                self.count += 1
                raise request_exception

            return MagicMock(
                status_code=200,
                json=MagicMock(return_value={'success': 'True'}))

        Session.return_value = MagicMock(request=exception_raiser)

        ex = HttpExecutor('http://api.stormpath.com/v1', ('user', 'pass'))

        ShouldRetry = MagicMock(return_value=True)

        with patch('stormpath.http.HttpExecutor.should_retry', ShouldRetry):
            with self.assertRaises(Error):
                ex.get('/test')

        should_retry_calls = [
            call(0, request_exception), call(1, request_exception),
            call(2, request_exception), call(3, request_exception),
        ]
        ShouldRetry.assert_has_calls(should_retry_calls)
开发者ID:seanodonnell,项目名称:stormpath-sdk-python,代码行数:30,代码来源:test_http.py

示例6: test_get_request_exception_and_retry_and_success

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_get_request_exception_and_retry_and_success(self, Session):
        self.count = 0
        request_exception = RequestException('mocked error')
        successful_response = MagicMock(status_code=200, json=MagicMock(return_value={'success': 'True'}))

        def faker(*args, **kwargs):
            if self.count < 3:
                self.count += 1
                raise request_exception

            return successful_response

        Session.return_value = MagicMock(request=faker)

        ex = HttpExecutor('http://api.stormpath.com/v1', ('user', 'pass'))
        should_retry = MagicMock(return_value=True)

        with patch('stormpath.http.HttpExecutor.should_retry', should_retry):
            resp = ex.get('/test')

        self.assertEqual(resp['sp_http_status'], 200)
        should_retry.assert_has_calls([
            call(0, request_exception),
            call(1, request_exception),
            call(2, request_exception),
        ])
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:28,代码来源:test_http.py

示例7: test_check_jobs

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
def test_check_jobs(jobResetAgent):
  """Test for checkJobs function."""
  jobIDs = [1, 2]
  dummy_treatJobWithNoReq = MagicMock()
  dummy_treatJobWithReq = MagicMock()

  # if the readRequestsForJobs func returns error than checkJobs should exit and return an error
  jobResetAgent.reqClient.readRequestsForJobs.return_value = S_ERROR()
  res = jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
                                treatJobWithReq=dummy_treatJobWithReq)
  assert not res["OK"]

  # test if correct treatment functions are called
  jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {},
                                                                   'Failed': {jobIDs[0]: 'Request not found'}})
  jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
                          treatJobWithReq=dummy_treatJobWithReq)
  dummy_treatJobWithNoReq.assert_has_calls([call(jobIDs[0]), call(jobIDs[1])])
  dummy_treatJobWithReq.assert_not_called()

  dummy_treatJobWithNoReq.reset_mock()
  req1 = Request({"RequestID": 1})
  req2 = Request({"RequestID": 2})
  jobResetAgent.reqClient.readRequestsForJobs.return_value = S_OK({'Successful': {jobIDs[0]: req1,
                                                                                  jobIDs[1]: req2},
                                                                   'Failed': {}})
  jobResetAgent.checkJobs(jobIDs, treatJobWithNoReq=dummy_treatJobWithNoReq,
                          treatJobWithReq=dummy_treatJobWithReq)
  dummy_treatJobWithNoReq.assert_not_called()
  dummy_treatJobWithReq.assert_has_calls([call(jobIDs[0], req1), call(jobIDs[1], req2)])
开发者ID:LCDsoft,项目名称:ILCDIRAC,代码行数:32,代码来源:Test_JobResetAgent.py

示例8: wraps_the_env_usage_with_creation_activation_and_deactivation

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def wraps_the_env_usage_with_creation_activation_and_deactivation(self):
        execute = MagicMock()

        @contextmanager
        def prefix(command):
            execute('called before prefix')
            execute('prefix: "%s"' % command)
            yield
            execute('called after prefix')

        with patch('provy.core.roles.Role.execute', execute), patch('fabric.api.prefix', prefix), self.env_exists('fancylib') as env_exists:
            venv = VirtualenvRole(prov=None, context={'user': 'johndoe',})
            env_exists.return_value = False

            with venv('fancylib'):
                execute('some command')
                execute('some command 2')

            env_exists.assert_called_with('fancylib')

            env_creation_call = call('virtualenv %s/fancylib' % venv.base_directory, user='johndoe')
            activation_prefix_call = call('prefix: "source %s/fancylib/bin/activate"' % venv.base_directory)

            expected_executes = [
                env_creation_call,
                call('called before prefix'),
                activation_prefix_call,
                call('some command'),
                call('some command 2'),
                call('called after prefix'),
            ]
            execute.assert_has_calls(expected_executes)
开发者ID:andreaugusto,项目名称:provy,代码行数:34,代码来源:test_virtualenv.py

示例9: test_get_request_exception_and_retry_four_times

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_get_request_exception_and_retry_four_times(self, Session):
        request_exception = RequestException('I raise RequestException!')
        def exception_raiser(method, url, data, params, headers=None,
                             allow_redirects=None):
            raise request_exception

        Session.return_value = MagicMock(request=exception_raiser)

        ex = HttpExecutor('http://api.stormpath.com/v1', ('user', 'pass'))

        def try_four_times(retries, status):
            return retries <= 3

        ShouldRetry = MagicMock()
        ShouldRetry.side_effect = try_four_times

        with patch('stormpath.http.HttpExecutor.should_retry', ShouldRetry):
            with self.assertRaises(Error):
                ex.get('/test')

        should_retry_calls = [
            call(0, request_exception), call(1, request_exception),
            call(2, request_exception), call(3, request_exception),
            call(4, request_exception)
        ]
        ShouldRetry.assert_has_calls(should_retry_calls)
开发者ID:seanodonnell,项目名称:stormpath-sdk-python,代码行数:28,代码来源:test_http.py

示例10: test_observable_register

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
 def test_observable_register(self):
     notify_observers_mock = MagicMock()
     self.appmgr.notify_observers = notify_observers_mock
     self.my_app()
     app = self.appmgr.grab_apps()[0]
     calls = [call("register", app, IFakeInterface)]
     notify_observers_mock.assert_has_calls(calls)
开发者ID:kudrom,项目名称:genesis2,代码行数:9,代码来源:tests.py

示例11: test_loop

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
 def test_loop(self):
     timer = MagicMock()
     self.engine.loop(timer)
     self.engine.poll(0.01)
     self.engine.poll(0.01)
     self.engine.poll(0.01)
     timer.assert_has_calls([call() for _ in range(3)])
开发者ID:Sureiya,项目名称:pants,代码行数:9,代码来源:test_timers.py

示例12: test_check_attach_card

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_check_attach_card(self):
        cl = ContollerClient()

        vm_original = self._get_vm()
        vm_get_mock = MagicMock(return_value=vm_original)
        with patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            vm_get_mock
        ):
            scsi_spec, controller_type = cl.generate_scsi_card(
                {'label': "Cloudify"}, 10)
        vm_get_mock.assert_called_once_with(vim.VirtualMachine, 10)
        self.assertEqual(scsi_spec.device.deviceInfo.label, "Cloudify")

        device = controller_type()
        device.key = 1001
        vm_updated = self._get_vm()
        vm_updated.config.hardware.device.append(device)
        vm_get_mock = MagicMock(side_effect=[vm_original, vm_updated])

        with patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            vm_get_mock
        ):
            self.assertEqual(
                cl.attach_controller(10, scsi_spec, controller_type),
                {'busKey': 1001, 'busNumber': 0})
            vm_get_mock.assert_has_calls([
                call(vim.VirtualMachine, 10),
                call(vim.VirtualMachine, 10, use_cache=False)])
开发者ID:cloudify-cosmo,项目名称:cloudify-vsphere-plugin,代码行数:32,代码来源:test_device.py

示例13: test_unindex_objects

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
 def test_unindex_objects(self, get_es_mock):
     mapping_type = MagicMock()
     unindex_objects(mapping_type, [1, 2, 3], 'foo')
     ok_(mapping_type.unindex.called)
     mapping_type.assert_has_calls([
         call.unindex(1, es=get_es_mock(), public_index='foo'),
         call.unindex(2, es=get_es_mock(), public_index='foo'),
         call.unindex(3, es=get_es_mock(), public_index='foo')])
开发者ID:kausdev,项目名称:mozillians,代码行数:10,代码来源:test_tasks.py

示例14: test_unindex_objects

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
 def test_unindex_objects(self, get_es_mock):
     model = MagicMock()
     unindex_objects(model, [1, 2, 3], 'foo')
     ok_(model.unindex.called)
     model.assert_has_calls([
         call.unindex(es=get_es_mock(), public_index='foo', id=1),
         call.unindex(es=get_es_mock(), public_index='foo', id=2),
         call.unindex(es=get_es_mock(), public_index='foo', id=3)])
开发者ID:KryDos,项目名称:mozillians,代码行数:10,代码来源:test_tasks.py

示例15: test_observable_unregister

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import assert_has_calls [as 别名]
    def test_observable_unregister(self):
        notify_observers_mock = MagicMock()
        self.appmgr.notify_observers = notify_observers_mock

        self.my_app()
        app = self.appmgr.grab_apps()[0]
        self.appmgr.unregister(app)
        calls = [call("unregister", app, self.fake_interface)]
        notify_observers_mock.assert_has_calls(calls)
开发者ID:kudrom,项目名称:genesis2,代码行数:11,代码来源:tests.py


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