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


Python MagicMock.service方法代码示例

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


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

示例1: test_generate_pipeline_success_with_no_opts

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_generate_pipeline_success_with_no_opts(mock_generate_pipeline, mock_validate_service_name):
    # paasta generate succeeds when service name provided as arg
    mock_validate_service_name.return_value = None
    args = MagicMock()
    args.service = "fake_service"
    assert paasta_generate_pipeline(args) is None
    mock_generate_pipeline.assert_called_once_with(service="fake_service", soa_dir=ANY)
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:test_cmds_generate_pipeline.py

示例2: test_status_calls_sergeants

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_get_deploy_info,
    mock_figure_out_service_name,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    pipeline = [{'instancename': 'cluster.instance'}]
    deploy_info = {'pipeline': pipeline}
    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1']
    mock_get_deploy_info.return_value = deploy_info
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.verbose = False
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args)
    mock_get_actual_deployments.assert_called_once_with(service)
    mock_get_deploy_info.assert_called_once_with(service)
    mock_report_status.assert_called_once_with(
        service, planned_deployments, actual_deployments, None, False)
开发者ID:nickrobinson,项目名称:paasta,代码行数:36,代码来源:test_cmds_status.py

示例3: test_status_calls_sergeants

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
):
    service = "fake_service"
    mock_figure_out_service_name.return_value = service

    planned_deployments = ["cluster1.instance1", "cluster1.instance2", "cluster2.instance1"]
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {"fake_service:paasta-cluster.instance": "this_is_a_sha"}
    mock_get_actual_deployments.return_value = actual_deployments

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args)
    mock_get_actual_deployments.assert_called_once_with(service)
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        verbose=0,
    )
开发者ID:carriercomm,项目名称:paasta,代码行数:35,代码来源:test_cmds_status.py

示例4: test_paasta_generate_pipeline_success_guesses_service_name

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_paasta_generate_pipeline_success_guesses_service_name(
    mock_generate_pipeline, mock_guess_service_name, mock_validate_service_name
):
    # paasta generate succeeds when service name must be guessed
    mock_guess_service_name.return_value = "fake_service"
    mock_validate_service_name.return_value = None
    args = MagicMock()
    args.service = None
    assert paasta_generate_pipeline(args) is None
    mock_generate_pipeline.assert_called_once_with(service="fake_service", soa_dir=ANY)
开发者ID:somic,项目名称:paasta,代码行数:12,代码来源:test_cmds_generate_pipeline.py

示例5: test_itest_works_when_service_name_starts_with_services_dash

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_itest_works_when_service_name_starts_with_services_dash(
    mock_docker_image, mock_exit, mock_log, mock_build_docker_tag, mock_run, mock_validate_service_name
):
    mock_docker_image.return_value = True
    mock_build_docker_tag.return_value = "unused_docker_tag"
    mock_run.return_value = (0, "Yeeehaaa")
    args = MagicMock()
    args.service = "services-fake_service"
    args.commit = "unused"
    assert paasta_itest(args) is None
    mock_build_docker_tag.assert_called_once_with("fake_service", "unused")
开发者ID:sayi21cn,项目名称:paasta,代码行数:13,代码来源:test_cmds_itest.py

示例6: test_push_to_registry_works_when_service_name_starts_with_services_dash

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_push_to_registry_works_when_service_name_starts_with_services_dash(
    mock_build_command,
    mock_log,
    mock_run,
    mock_validate_service_name,
):
    mock_run.return_value = (0, 'Success')
    args = MagicMock()
    args.service = 'fake_service'
    args.commit = 'unused'
    assert paasta_push_to_registry(args) == 0
    mock_build_command.assert_called_once_with('fake_service', 'unused')
开发者ID:RedCobbler,项目名称:paasta,代码行数:14,代码来源:test_cmds_push_to_registry.py

示例7: test_paasta_generate_pipeline_success_no_opts

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_paasta_generate_pipeline_success_no_opts(
        mock_generate_pipeline,
        mock_guess_service_name,
        mock_validate_service_name):
    # paasta generate succeeds when service name must be guessed
    mock_guess_service_name.return_value = 'fake_service'
    mock_validate_service_name.return_value = None
    args = MagicMock()
    args.service = None
    args.soa_dir = '/fake/soa/dir'
    assert paasta_generate_pipeline(args) is None
    mock_generate_pipeline.assert_called_once_with(service='fake_service', soa_dir='/fake/soa/dir')
开发者ID:RedCobbler,项目名称:paasta,代码行数:14,代码来源:test_cmds_generate_pipeline.py

示例8: test_paasta_generate_pipeline_service_not_found

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_paasta_generate_pipeline_service_not_found(mock_stdout, mock_guess_service_name, mock_validate_service_name):
    # paasta generate cannot guess service name and none is provided

    mock_guess_service_name.return_value = "not_a_service"
    mock_validate_service_name.side_effect = NoSuchService(None)

    args = MagicMock()
    args.service = None
    expected_output = "%s\n" % NoSuchService.GUESS_ERROR_MSG

    assert paasta_generate_pipeline(args) == 1
    output = mock_stdout.getvalue().decode("utf-8")
    assert output == expected_output
开发者ID:somic,项目名称:paasta,代码行数:15,代码来源:test_cmds_generate_pipeline.py

示例9: test_itest_works_when_service_name_starts_with_services_dash

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_itest_works_when_service_name_starts_with_services_dash(
    mock_docker_image,
    mock_log,
    mock_build_docker_tag,
    mock_run,
    mock_validate_service_name,
):
    mock_docker_image.return_value = True
    mock_build_docker_tag.return_value = 'unused_docker_tag'
    mock_run.return_value = (0, 'Yeeehaaa')
    args = MagicMock()
    args.service = 'services-fake_service'
    args.commit = 'unused'
    assert paasta_itest(args) is 0
    mock_build_docker_tag.assert_called_once_with('fake_service', 'unused')
开发者ID:RedCobbler,项目名称:paasta,代码行数:17,代码来源:test_cmds_itest.py

示例10: test_status_arg_service_not_found

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_arg_service_not_found(mock_stdout, mock_guess_service_name, mock_validate_service_name):
    # paasta_status with no args and non-service directory results in error
    mock_guess_service_name.return_value = "not_a_service"
    error = NoSuchService("fake_service")
    mock_validate_service_name.side_effect = error
    expected_output = str(error) + "\n"

    args = MagicMock()
    args.service = False

    # Fail if exit(1) does not get called
    with raises(SystemExit) as sys_exit:
        paasta_status(args)

    output = mock_stdout.getvalue()
    assert sys_exit.value.code == 1
    assert output == expected_output
开发者ID:carriercomm,项目名称:paasta,代码行数:19,代码来源:test_cmds_status.py

示例11: test_paasta_generate_pipeline_service_not_found

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_paasta_generate_pipeline_service_not_found(mock_stdout, mock_guess_service_name, mock_validate_service_name):
    # paasta generate cannot guess service name and none is provided

    mock_guess_service_name.return_value = "not_a_service"
    mock_validate_service_name.side_effect = NoSuchService(None)

    args = MagicMock()
    args.service = None
    expected_output = "%s\n" % NoSuchService.GUESS_ERROR_MSG

    # Fail if exit(1) does not get called
    with raises(SystemExit) as sys_exit:
        paasta_generate_pipeline(args)

    output = mock_stdout.getvalue()
    assert sys_exit.value.code == 1
    assert output == expected_output
开发者ID:neurogenesis,项目名称:paasta,代码行数:19,代码来源:test_cmds_generate_pipeline.py

示例12: test_status_pending_pipeline_build_message

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_pending_pipeline_build_message(
    mock_stdout, mock_get_actual_deployments, mock_get_deploy_info, mock_figure_out_service_name
):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = "fake_service"
    mock_figure_out_service_name.return_value = service
    pipeline = [{"instancename": "cluster.instance"}]
    mock_get_deploy_info.return_value = {"pipeline": pipeline}

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service

    paasta_status(args)
    output = mock_stdout.getvalue()
    assert expected_output in output
开发者ID:carriercomm,项目名称:paasta,代码行数:21,代码来源:test_cmds_status.py

示例13: test_status_calls_sergeants

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_calls_sergeants(
    mock_stdout,
    mock_report_status,
    mock_get_planned_deployments,
    mock_get_actual_deployments,
    mock_figure_out_service_name,
    mock_load_system_paasta_config,
):
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service

    planned_deployments = [
        'cluster1.instance1', 'cluster1.instance2', 'cluster2.instance1']
    mock_get_planned_deployments.return_value = planned_deployments

    actual_deployments = {
        'fake_service:paasta-cluster.instance': 'this_is_a_sha'
    }
    mock_get_actual_deployments.return_value = actual_deployments
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    args = MagicMock()
    args.service = service
    args.clusters = None
    args.instances = None
    args.verbose = False
    args.soa_dir = '/fake/soa/dir'
    paasta_status(args)

    mock_figure_out_service_name.assert_called_once_with(args, '/fake/soa/dir')
    mock_get_actual_deployments.assert_called_once_with(service, '/fake/soa/dir')
    mock_report_status.assert_called_once_with(
        service=service,
        deploy_pipeline=planned_deployments,
        actual_deployments=actual_deployments,
        cluster_whitelist=[],
        instance_whitelist=[],
        system_paasta_config=fake_system_paasta_config,
        verbose=0,
    )
开发者ID:EvanKrall,项目名称:paasta,代码行数:43,代码来源:test_cmds_status.py

示例14: test_status_pending_pipeline_build_message

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_status_pending_pipeline_build_message(
        mock_stdout, mock_get_actual_deployments, mock_get_deploy_info,
        mock_figure_out_service_name, mock_load_system_paasta_config):
    # If deployments.json is missing SERVICE, output the appropriate message
    service = 'fake_service'
    mock_figure_out_service_name.return_value = service
    pipeline = [{'instancename': 'cluster.instance'}]
    mock_get_deploy_info.return_value = {'pipeline': pipeline}
    fake_system_paasta_config = utils.SystemPaastaConfig({}, '/fake/config')
    mock_load_system_paasta_config.return_value = fake_system_paasta_config

    actual_deployments = {}
    mock_get_actual_deployments.return_value = actual_deployments
    expected_output = missing_deployments_message(service)

    args = MagicMock()
    args.service = service

    paasta_status(args)
    output = mock_stdout.getvalue()
    assert expected_output in output
开发者ID:EvanKrall,项目名称:paasta,代码行数:23,代码来源:test_cmds_status.py

示例15: test_rerun_validations

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import service [as 别名]
def test_rerun_validations(test_case):
    with contextlib.nested(
        patch('sys.stdout', new_callable=StringIO, autospec=None),
        patch('paasta_tools.cli.cmds.rerun.figure_out_service_name', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.list_clusters', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.get_actual_deployments', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.get_planned_deployments', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.execute_chronos_rerun_on_remote_master', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.chronos_tools.load_chronos_job_config', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.chronos_tools.uses_time_variables', autospec=True),
        patch('paasta_tools.cli.cmds.rerun._get_default_execution_date', autospec=True),
        patch('paasta_tools.cli.cmds.rerun.load_system_paasta_config', autospec=True),
    ) as (
        mock_stdout,
        mock_figure_out_service_name,
        mock_list_clusters,
        mock_get_actual_deployments,
        mock_get_planned_deployments,
        mock_execute_rerun_remote,
        mock_load_chronos_job_config,
        mock_uses_time_variables,
        mock_get_default_execution_date,
        mock_load_system_paasta_config,
    ):

        (rerun_args,
         mock_figure_out_service_name.return_value,
         mock_list_clusters.return_value,
         mock_get_actual_deployments.return_value,
         mock_get_planned_deployments.return_value,
         mock_uses_time_variables.return_value,
         expected_output) = test_case

        mock_load_chronos_job_config.return_value = {}
        default_date = datetime.datetime(2002, 2, 2, 2, 2, 2, 2)
        mock_get_default_execution_date.return_value = default_date
        mock_execute_rerun_remote.return_value = (0, '')
        mock_load_system_paasta_config.return_value = SystemPaastaConfig({}, '/fake/config')

        args = MagicMock()
        args.service = rerun_args[0]
        args.instance = rerun_args[1]
        args.clusters = rerun_args[2]
        if rerun_args[3]:
            args.execution_date = datetime.datetime.strptime(rerun_args[3], EXECUTION_DATE_FORMAT)
        else:
            args.execution_date = None
        args.verbose = 0

        paasta_rerun(args)

        # No --execution_date argument, but that's ok: the job doesn't use time vars interpolation.
        # Check if the backend rerun command was called with the default date.
        if args.execution_date is None and not mock_uses_time_variables.return_value:
            assert mock_execute_rerun_remote.call_args[1]['execution_date'] \
                == default_date.strftime(EXECUTION_DATE_FORMAT)

        # The job does use time vars interpolation. Make sure the User supplied date was used.
        if args.execution_date is not None and mock_uses_time_variables.return_value:
            assert mock_execute_rerun_remote.call_args[1]['execution_date'] == _user_supplied_execution_date

        output = mock_stdout.getvalue().decode('utf-8')
        assert expected_output in output
开发者ID:somic,项目名称:paasta,代码行数:65,代码来源:test_cmds_rerun.py


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