Пример #1
0
def test_run_all(setup):

    args = {
        'command': 'run',
        'path': 'tests/projects',
        'stage': 'test',
        'targets': "p2",
        'all_targets': True
    }

    mock_dict['mock_subprocess_run'] = 0
    setup.setattr(subprocess, 'run', mock_subprocess_run)
    commands.run(args)
    assert mock_dict['mock_subprocess_run'] == 2
Пример #2
0
def test_run_p1_p3(setup):

    args = {
        'command': 'run',
        'path': 'tests/projects',
        'stage': 'test',
        'targets': "p1 p3",
        'all_targets': False,
        'recursive_deps': False
    }

    mock_dict['mock_subprocess_run'] = 0
    setup.setattr(subprocess, 'run', mock_subprocess_run)
    commands.run(args)
    assert mock_dict['mock_subprocess_run'] == 1
Пример #3
0
def test_run_test_from_citool(setup):

    args = {
        'command': 'run',
        'path': 'tests/projects',
        'stage': 'test',
        'targets': None,
        'all_targets': False,
        'ci_tool': 'gitlab',
        'recursive_deps': False
    }

    mock_dict['mock_subprocess_run'] = 0
    setup.setenv('CI_COMMIT_REF_NAME', 'master')
    setup.setattr(subprocess, 'run', mock_subprocess_run)
    commands.run(args)
    assert mock_dict['mock_subprocess_run'] == 2
Пример #4
0
def test_run_p3_fails(setup):

    args = {
        'command': 'run',
        'path': 'tests/projects',
        'stage': 'failure',
        'targets': "p3",
        'all_targets': False,
        'recursive_deps': False
    }

    mock_dict['mock_subprocess_run'] = 0
    mock_dict['mock_sys_exit'] = 0
    setup.setattr(subprocess, 'run', mock_subprocess_run)
    setup.setattr(sys, 'exit', mock_sys_exit)
    commands.run(args)
    assert mock_dict['mock_subprocess_run'] == 1
    assert mock_dict['mock_sys_exit'] == 1
Пример #5
0
def test_run_deploy_from_citool(setup):
    args = {
        'command': 'run',
        'path': 'tests/projects',
        'stage': 'deploy',
        'env':
        ['DEPLOY_VAR=DEPLOY_VAR', 'DEPLOY_ENV_VAR=$DEPLOY_ENV_VAR_VALUE'],
        'targets': None,
        'all_targets': False,
        'ci_tool': 'gitlab',
        'recursive_deps': False
    }

    mock_dict['mock_subprocess_run'] = 0
    setup.setenv('CI_COMMIT_REF_NAME', 'master')
    setup.setenv('DEPLOY_ENV_VAR_VALUE', 'Valor de DEPLOY_ENV_VAR_VALUE')
    setup.setattr(subprocess, 'run', mock_subprocess_run)
    commands.run(args)
    assert mock_dict['mock_subprocess_run'] == 2
Пример #6
0
    parser_run.add_argument(
        '-t',
        '--targets',
        help='A list of target project names to run the provided stage, '
        'separated by blank spaces (use quotes around the string).')
    parser_run.add_argument(
        '--all-targets',
        action='store_true',
        help='Set all the projects as target, and ignore --targets argument.')

    parser_integration = subparsers.add_parser('integration')
    # TODO: Complete the integration part. Useful or treated as one more stage?

    args = vars(parser.parse_args())

    try:
        Repo(os.getcwd())
    except Exception as e:
        parser.error(
            f"ERROR: You must be in the root path of a git repository: {e}.")

    if args['command'] == 'init':
        commands.init(args)
    if args['command'] == 'info':
        commands.info(args)
    elif args['command'] == 'run':
        commands.run(args)
    elif args['command'] == 'integration':
        commands.integration(args)
    else:
        print(parser.parse_args('-h'))