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


Python MagicMock.status方法代码示例

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


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

示例1: test_wait_for_delete

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_wait_for_delete(self):
        _ctx = self._gen_decorators_context('test_wait_for_delete')

        @decorators.wait_for_delete(status_deleted=['deleted'],
                                    status_pending=['pending'])
        def test_delete(*agrs, **kwargs):
            pass

        # deleted
        mock_interface = MagicMock()
        mock_interface.status = 'deleted'

        test_delete(ctx=_ctx, iface=mock_interface)

        self.assertEqual(_ctx.instance.runtime_properties, {
            '__deleted': True,
        })

        # pending
        mock_interface = MagicMock()
        mock_interface.status = 'pending'

        with self.assertRaises(OperationRetry):
            test_delete(ctx=_ctx, iface=mock_interface)

        # unknow
        mock_interface = MagicMock()
        mock_interface.status = 'unknow'

        with self.assertRaises(NonRecoverableError):
            test_delete(ctx=_ctx, iface=mock_interface)
开发者ID:cloudify-cosmo,项目名称:cloudify-aws-plugin,代码行数:33,代码来源:test_decorators.py

示例2: test_wait_for_status

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

        _ctx = self._gen_decorators_context(
            'test_wait_for_status',
            op_name='cloudify.interfaces.lifecycle.create')

        @decorators.wait_for_status(status_good=['ok'],
                                    status_pending=['pending'])
        def test_ok(*agrs, **kwargs):
            pass

        # ok
        mock_interface = MagicMock()
        mock_interface.status = 'ok'
        mock_interface.properties = {'status': 'ok'}

        test_ok(ctx=_ctx, iface=mock_interface)

        self.assertEqual(_ctx.instance.runtime_properties, {
            'resource_config': {},
            'create_response': {'status': 'ok'},
        })

        # pending
        mock_interface = MagicMock()
        mock_interface.status = 'pending'
        mock_interface.properties = {'status': 'pending'}

        with self.assertRaises(OperationRetry):
            test_ok(ctx=_ctx, iface=mock_interface)

        # unknow
        mock_interface = MagicMock()
        mock_interface.status = 'unknown'
        mock_interface.properties = {'status': 'unknown'}

        with self.assertRaises(NonRecoverableError):
            test_ok(ctx=_ctx, iface=mock_interface)

        # empty status
        mock_interface = MagicMock()
        mock_interface.status = None
        mock_interface.properties = {'status': None}

        with self.assertRaises(NonRecoverableError):
            test_ok(ctx=_ctx, iface=mock_interface)

        # empty status but ignore
        mock_interface = MagicMock()
        mock_interface.status = None
        mock_interface.properties = {'status': None}

        @decorators.wait_for_status(status_pending=['pending'],
                                    fail_on_missing=False)
        def test_ignore(*agrs, **kwargs):
            pass

        test_ignore(ctx=_ctx, iface=mock_interface)
开发者ID:cloudify-cosmo,项目名称:cloudify-aws-plugin,代码行数:60,代码来源:test_decorators.py

示例3: test_command_succeeded

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
 def test_command_succeeded(self):
     response = MagicMock()
     result = json.loads('{"status": "Failure", "kind": "Status", "code": 409, "apiVersion": "v1", "reason": "AlreadyExists", "details": {"kind": "node", "name": "10.200.147.200"}, "message": "node \\"10.200.147.200\\" already exists", "creationTimestamp": null}')  # noqa
     response.status = 200
     self.r.command_succeeded(response, result)
     response.status = 409
     self.r.command_succeeded(response, result)
     response.status = 500
     with pytest.raises(RuntimeError):
         self.r.command_succeeded(response, result)
开发者ID:40a,项目名称:kansible,代码行数:12,代码来源:test_registrator.py

示例4: get_response

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def get_response(self):
        method, url = self.__class__.last_op

        resp = MagicMock()

        if method == "GET":
            if url == "/-/":
                resp.status = 200
                resp.read.return_value = read_file_as_string("files/occi.txt")
            elif url == "/compute/1":
                resp.status = 200
                resp.read.return_value = read_file_as_string("files/occi_vm_info.txt")
            elif url.startswith("/storage"):
                resp.status = 200
                resp.read.return_value = 'X-OCCI-Attribute: occi.storage.state="online"'
        elif method == "POST":
            if url == "/compute/":
                resp.status = 201
                resp.read.return_value = 'https://server.com/compute/1'
            elif url.endswith("action=suspend"):
                resp.status = 200
            elif url.endswith("action=start"):
                resp.status = 200
            elif url == "/link/storagelink":
                resp.status = 200
        elif method == "DELETE":
            if url.endswith("/compute/1"):
                resp.status = 200
            elif url.endswith("/storage/1"):
                resp.status = 200

        return resp
开发者ID:indigo-dc,项目名称:im,代码行数:34,代码来源:OCCI.py

示例5: get_response

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def get_response(self):
        method, url = self.__class__.last_op

        resp = MagicMock()

        if method == "GET":
            if "/deployments/" in url:
                resp.status = 200
                resp.read.return_value = ("<Deployment><Status>Running</Status><RoleInstanceList><RoleInstance>"
                                          "<InstanceSize>RoleSizeName</InstanceSize><PowerState>Started</PowerState>"
                                          "<IpAddress>10.0.0.1</IpAddress><InstanceEndpoints><InstanceEndpoint>"
                                          "<Vip>158.42.1.1</Vip></InstanceEndpoint></InstanceEndpoints></RoleInstance>"
                                          "</RoleInstanceList></Deployment>")
            if "/operations/" in url:
                resp.status = 200
                resp.read.return_value = ("<Operation><Status>Succeeded"
                                          "</Status></Operation>")
            elif "/storageservices/" in url:
                resp.status = 200
                resp.read.return_value = ("<StorageService><StorageServiceProperties><GeoPrimaryRegion>North Europe"
                                          "</GeoPrimaryRegion></StorageServiceProperties></StorageService>")
            elif url.endswith("/rolesizes"):
                resp.status = 200
                resp.read.return_value = ("<RoleSizes><RoleSize><SupportedByVirtualMachines>true"
                                          "</SupportedByVirtualMachines><Name>RoleSizeName</Name>"
                                          "<MemoryInMb>512</MemoryInMb><Cores>1</Cores>"
                                          "<VirtualMachineResourceDiskSizeInMb>2014"
                                          "</VirtualMachineResourceDiskSizeInMb>"
                                          "</RoleSize>"
                                          "<RoleSize><SupportedByVirtualMachines>true"
                                          "</SupportedByVirtualMachines><Name>RoleSizeName</Name>"
                                          "<MemoryInMb>2048</MemoryInMb><Cores>2</Cores>"
                                          "<VirtualMachineResourceDiskSizeInMb>2014"
                                          "</VirtualMachineResourceDiskSizeInMb>"
                                          "</RoleSize>"
                                          "</RoleSizes>")

        elif method == "POST":
            if url.endswith("/Operations"):
                resp.status = 202
                resp.getheader.return_value = "id"
            elif url.endswith("/services/hostedservices"):
                resp.status = 201
                resp.read.return_value = ""
            elif url.endswith("/deployments"):
                resp.status = 202
                resp.getheader.return_value = "id"
        elif method == "DELETE":
            if url.endswith("comp=media"):
                resp.status = 202
                resp.getheader.return_value = "id"
        elif method == "PUT":
            if "roles" in url:
                resp.status = 202
                resp.getheader.return_value = "id"

        return resp
开发者ID:indigo-dc,项目名称:im,代码行数:59,代码来源:Azure.py

示例6: test_SchedulerAdmin_status_renderer

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
 def test_SchedulerAdmin_status_renderer(self):
     scheduler = MagicMock()
     schedulerAdmin = SchedulerAdmin(Scheduler, MagicMock())
     scheduler.status = 'S'
     self.assertEqual('<font color="green">Success</font>',
                      schedulerAdmin.status_renderer(scheduler))
     scheduler.status = 'I'
     self.assertEqual('<font color="yellow">Invalid</font>',
                      schedulerAdmin.status_renderer(scheduler))
     scheduler.status = 'F'
     self.assertEqual('<font color="red">Fail</font>',
                      schedulerAdmin.status_renderer(scheduler))
     scheduler.status = 'R'
     self.assertEqual('<font color="orange">Running</font>',
                      schedulerAdmin.status_renderer(scheduler))
开发者ID:FBK-WED,项目名称:wed-pipe,代码行数:17,代码来源:admin.py

示例7: test_backup_info_exception

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_backup_info_exception(self, command_mock):
        # BackupManager mock
        backup_manager = build_backup_manager(name="test_server")
        backup_manager.config.pre_test_hook = "not_existent_script"
        backup_manager.get_previous_backup = MagicMock()
        backup_manager.get_previous_backup.side_effect = UnknownBackupIdException()

        # BackupInfo mock
        backup_info = MagicMock(name="backup_info")
        backup_info.get_basebackup_directory.return_value = "backup_directory"
        backup_info.backup_id = "123456789XYZ"
        backup_info.error = None
        backup_info.status = "OK"

        # the actual test
        script = HookScriptRunner(backup_manager, "test_hook", "pre")
        script.env_from_backup_info(backup_info)
        expected_env = {
            "BARMAN_PHASE": "pre",
            "BARMAN_VERSION": version,
            "BARMAN_SERVER": "test_server",
            "BARMAN_CONFIGURATION": "build_config_from_dicts",
            "BARMAN_HOOK": "test_hook",
            "BARMAN_BACKUP_DIR": "backup_directory",
            "BARMAN_BACKUP_ID": "123456789XYZ",
            "BARMAN_ERROR": "",
            "BARMAN_STATUS": "OK",
            "BARMAN_PREVIOUS_ID": "",
        }
        script.run()
        assert command_mock.call_count == 1
        assert command_mock.call_args[1]["env_append"] == expected_env
开发者ID:stig,项目名称:barman,代码行数:34,代码来源:test_hooks.py

示例8: test034_launch_asynchronous_ftp_error

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
 def test034_launch_asynchronous_ftp_error(self,
                                           m_session_transaction,
                                           m_Scan,
                                           m_ftp_ctrl,
                                           m_add_empty_result):
     m_scan, m_session = MagicMock(), MagicMock()
     fw1, fw2 = MagicMock(), MagicMock()
     file1, file2 = MagicMock(), MagicMock()
     pathf1, pathf2 = 'path-file1', 'path-file2'
     file1.path = pathf1
     file2.path = pathf2
     fw1.file.sha256 = "sha256file1"
     fw1.file.mimetype = "mimetypefile1"
     fw2.file.sha256 = "sha256file2"
     fw2.file.mimetype = "mimetypefile2"
     m_scan.files_web = [fw1, fw2]
     m_scan.files = [file1, file2]
     probe1, probe2 = "Probe1", "Probe2"
     probelist = [probe1, probe2]
     m_scan.get_probe_list.return_value = probelist
     m_add_empty_result.return_value = probelist
     m_session_transaction().__enter__.return_value = m_session
     m_scan.status = IrmaScanStatus.ready
     m_scan.mimetype_filtering = False
     m_Scan.load_from_ext_id.return_value = m_scan
     scanid = "scanid"
     m_ftp_ctrl.upload_scan.side_effect = IrmaFtpError()
     module.launch_asynchronous(scanid)
     expected = IrmaScanStatus.error_ftp_upload
     m_scan.set_status.assert_called_once_with(expected)
开发者ID:ufausther,项目名称:irma-frontend,代码行数:32,代码来源:test_scanctrl.py

示例9: test_read_from

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

        instance.status = 1
        instance.scores = {
            'left': [5, 10, 15, 20],
            'right': [10, 15, 20, 25],
        }

        self.object().read_from(instance)

        assert self.object().get_data_dict(True) == {
            'csrf_token': self.mget_csrf_token().return_value,
            'status': 1,
            'left_quart_1': 5,
            'left_quart_2': 10,
            'left_quart_3': 15,
            'left_quart_4': 20,
            'right_quart_1': 10,
            'right_quart_2': 15,
            'right_quart_3': 20,
            'right_quart_4': 25,
        }

        assert self.object().instance is instance
开发者ID:socek,项目名称:impex,代码行数:27,代码来源:test_forms.py

示例10: test_backup_info_exception

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_backup_info_exception(self, command_mock):
        # BackupManager mock
        backup_manager = build_backup_manager(name='test_server')
        backup_manager.config.pre_test_hook = 'not_existent_script'
        backup_manager.get_previous_backup = MagicMock()
        backup_manager.get_previous_backup.side_effect = \
            UnknownBackupIdException()

        # BackupInfo mock
        backup_info = MagicMock(name='backup_info')
        backup_info.get_basebackup_directory.return_value = 'backup_directory'
        backup_info.backup_id = '123456789XYZ'
        backup_info.error = None
        backup_info.status = 'OK'

        # the actual test
        script = HookScriptRunner(backup_manager, 'test_hook', 'pre')
        script.env_from_backup_info(backup_info)
        expected_env = {
            'BARMAN_PHASE': 'pre',
            'BARMAN_VERSION': version,
            'BARMAN_SERVER': 'test_server',
            'BARMAN_CONFIGURATION': 'build_config_from_dicts',
            'BARMAN_HOOK': 'test_hook',
            'BARMAN_BACKUP_DIR': 'backup_directory',
            'BARMAN_BACKUP_ID': '123456789XYZ',
            'BARMAN_ERROR': '',
            'BARMAN_STATUS': 'OK',
            'BARMAN_PREVIOUS_ID': '',
            'BARMAN_RETRY': '0',
        }
        script.run()
        assert command_mock.call_count == 1
        assert command_mock.call_args[1]['env_append'] == expected_env
开发者ID:zacchiro,项目名称:barman,代码行数:36,代码来源:test_hooks.py

示例11: make_response_mock

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
def make_response_mock(response_status):
    """ Constructs HTTP Response mock object.
    """
    response_mock = MagicMock()
    response_mock.status = response_status

    return response_mock
开发者ID:povilasb,项目名称:scrapy-html-storage,代码行数:9,代码来源:test_html_storage_middleware.py

示例12: test_backup_info_corner_cases

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_backup_info_corner_cases(self, command_mock):
        # BackupManager mock
        backup_manager = self.build_backup_manager('test_server', 'test_file')
        backup_manager.config.post_test_hook = 'not_existent_script'
        backup_manager.get_previous_backup.return_value = None

        # BackupInfo mock
        backup_info = MagicMock(name='backup_info')
        backup_info.get_basebackup_directory.return_value = 'backup_directory'
        backup_info.backup_id = '123456789XYZ'
        backup_info.error = 'Test error'
        backup_info.status = 'FAILED'

        # the actual test
        script = HookScriptRunner(backup_manager, 'test_hook', 'post')
        script.env_from_backup_info(backup_info)
        expected_env = {
            'BARMAN_PHASE': 'post',
            'BARMAN_VERSION': version,
            'BARMAN_SERVER': 'test_server',
            'BARMAN_CONFIGURATION': 'test_file',
            'BARMAN_HOOK': 'test_hook',
            'BARMAN_BACKUP_DIR': 'backup_directory',
            'BARMAN_BACKUP_ID': '123456789XYZ',
            'BARMAN_ERROR': 'Test error',
            'BARMAN_STATUS': 'FAILED',
            'BARMAN_PREVIOUS_ID': '',
        }
        script.run()
        assert command_mock.call_count == 1
        assert command_mock.call_args[1]['env_append'] == expected_env
开发者ID:huddler,项目名称:pgbarman,代码行数:33,代码来源:test_hooks.py

示例13: test012_cancel_status_cancelled

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
 def test012_cancel_status_cancelled(self):
     scan, session = MagicMock(), MagicMock()
     scan.status = IrmaScanStatus.cancelled
     label = IrmaScanStatus.label[scan.status]
     expected = "can not cancel scan in {} status".format(label)
     with self.assertRaises(IrmaValueError) as context:
         module.cancel(scan, session)
     self.assertEqual(str(context.exception), expected)
开发者ID:ufausther,项目名称:irma-frontend,代码行数:10,代码来源:test_scanctrl.py

示例14: test_format_int_status

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_format_int_status(self):
        req = MagicMock()
        resp = MagicMock()
        resp.status = 200

        hook_format(req, resp)

        self.assertEquals(resp.status, '200 OK')
开发者ID:ajiang38740,项目名称:jumpgate,代码行数:10,代码来源:test_hooks.py

示例15: test_hook_finished

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import status [as 别名]
    def test_hook_finished(self, m_log):
        self.scan.date = "scan_date"
        self.fw.scan = self.scan
        self.fw.file.sha256 = "sha256"
        self.fw.name = "filename"
        self.fw.file.timestamp_first_scan = "ts_first_scan"
        self.fw.file.timestamp_last_scan = "ts_last_scan"
        self.fw.file.size = "size"
        pr1, pr2 = MagicMock(), MagicMock()
        self.fw.probe_results = [pr1, pr2]
        pr1.name = "probe1"
        pr1.type = "antivirus"
        pr1.status = "status1"
        pr1.duration = "duration1"
        pr1.results = "results1"
        pr2.name = "probe2"
        pr2.type = "metadata"
        pr2.status = "status2"
        pr2.duration = None
        pr2.results = "results2"
        pr1.get_details.return_value = pr1
        pr2.get_details.return_value = pr2
        self.fw.hook_finished()

        expected1 = "[files_results] date: %s file_id: %s scan_id: %s "
        expected1 += "status: %s probes: %s submitter: %s submitter_id: %s"
        call1 = call(expected1,
                     'scan_date',
                     self.fw.external_id,
                     self.fw.scan.external_id, 'Clean', 'probe1, probe2',
                     'unknown', 'undefined')

        expected2 = '[av_results] date: %s av_name: "%s" '
        expected2 += "status: %d virus_name: \"%s\" file_id: %s "
        expected2 += "file_sha256: %s scan_id: %s duration: %f "
        expected2 += "submitter: %s submitter_id: %s"
        call2 = call(expected2,
                     'scan_date',
                     'probe1',
                     'status1',
                     'results1',
                     self.fw.external_id,
                     'sha256', self.fw.scan.external_id, 'duration1',
                     'unknown', 'undefined')

        expected3 = '[probe_results] date: %s name: "%s" '
        expected3 += "status: %d file_sha256: %s file_id: %s "
        expected3 += "duration: %f submitter: %s submitter_id: %s"
        call3 = call(expected3,
                     'scan_date',
                     'probe2',
                     'status2',
                     self.fw.external_id,
                     'sha256', 0, 'unknown', 'undefined')

        m_log.info.assert_has_calls([call1])
        m_log.info.assert_has_calls([call2])
        m_log.info.assert_has_calls([call3])
开发者ID:quarkslab,项目名称:irma,代码行数:60,代码来源:test_models_files_ext.py


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