def test_detect_same_name_projects():
    of = sh.OutputFile('test.log')
    filename = ('config/temp.yml')
    logger, tkonf = sh.setup_test_config(filename)
    assert tkonf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    tkonf.remove_from_container({'View': 'Shoreline'})
    tkonf.remove_from_container({'Job': 'truculent elk medallions'})
    assert not tkonf.has_item('View', 'Shoreline')
    assert not tkonf.has_item('Job', 'truculent elk medallions')
    ac_conf = tkonf.topLevel('AgileCentral')
    jenk_conf = tkonf.topLevel('Jenkins')
    bc = bsh.BLDConnector(tkonf, logger)
    agicen = bc.agicen_conn.agicen
    workspace_name = ac_conf['Workspace']
    project_name = jenk_conf['AgileCentral_DefaultBuildProject']
    response = agicen.get('Project',
                          fetch='Name',
                          workspace=workspace_name,
                          projectScopeDown=True,
                          pagesize=200)
    if response.errors or response.resultCount == 0:
        raise ConfigurationError(
            'Unable to locate a Project with the name: %s in the target Workspace'
            % project_name)

    assert bc.agicen_conn.duplicated_project_names[0] == 'Salamandra'
def test_jenkins_struct_with_bad_projects():
    of = sh.OutputFile('test.log')
    filename = "config/wallace_gf.yml"
    jenkins_struct = {
        'Jobs': [{
            'Job': 'Wendolene Ramsbottom',
            'AgileCentral_Project': 'Close Shave'
        }, {
            'Job': 'Lady Tottington',
            'AgileCentral_Project': 'The Curse of the Were-Rabbit'
        }, {
            'Job': 'Piella Bakewell',
            'AgileCentral_Project': 'A Matter of Loaf and Death'
        }]
    }

    logger, konf = sh.setup_config(filename, jenkins_struct)
    assert konf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    expectedErrPattern = "These projects mentioned in the config were not located in AgileCentral Workspace %s" % konf.topLevel(
        'AgileCentral')['Workspace']
    with pytest.raises(Exception) as excinfo:
        sh.BLDConnector(konf, logger)
    assert excinfo.typename == 'ConfigurationError'
    log_output = of.readlines()
    error_line = [line for line in log_output if 'ERROR' in line][0]
    assert re.search(expectedErrPattern, error_line) is not None
def test_validate_projects():
    of = sh.OutputFile('test.log')
    filename = "config/wallace_gf.yml"
    logger, konf = sh.setup_config(filename)
    assert konf.topLevels() == ['AgileCentral', 'Jenkins', 'Service']
    expectedErrPattern = "projects mentioned in the config were not located in AgileCentral Workspace"
    with pytest.raises(Exception) as excinfo:
        sh.BLDConnector(konf, logger)
    assert excinfo.typename == 'ConfigurationError'
    log_output = of.readlines()
    error_line = [line for line in log_output if 'ERROR' in line][0]
    assert re.search(expectedErrPattern, error_line) is not None
Beispiel #4
0
def test_shallow_depth_config():
    of = sh.OutputFile('log/inventory.log')
    t = datetime.now() - timedelta(days=365)
    ref_time = t.utctimetuple()
    jc = connect_to_jenkins(SHALLOW_CONFIG)
    assert jc.connect()
    #assert not jc.configItemsVetted()
    assert not jc.nonFullyPathedConfigItemsVetted()

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line][0]
    error = "these folders: 'dungeon'  were not present in the Jenkins inventory of Folders"
    assert re.search(error, error_lines) is not None
Beispiel #5
0
def test_deepy_depth_config():
    of = sh.OutputFile('log/inventory.log')
    t = datetime.now() - timedelta(days=365)
    ref_time = t.utctimetuple()
    jc = connect_to_jenkins(DEEP_CONFIG)
    assert jc.connect()
    #assert jc.configItemsVetted()
    assert jc.nonFullyPathedConfigItemsVetted()

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line]
    assert len(error_lines) == 0

    builds = jc.getRecentBuilds(ref_time)
    assert builds
def test_too_long_folder_path_for_small_maxDepth():
    log_file = 'log/%s.log' % LONG_JOHN_CONFIG.replace('.yml', '')
    os.path.exists(log_file) and os.remove(log_file)
    open(log_file, 'a').close()
    of = sh.OutputFile(log_file)
    expectedErrPattern = 'Validation failed'
    with pytest.raises(Exception) as excinfo:
        get_bld_connector(LONG_JOHN_CONFIG)
    actualErrVerbiage = excinfo.value.args[0]
    assert expectedErrPattern in actualErrVerbiage

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line][1]
    error = "Check if MaxDepth value .* in config is sufficient to reach these folders"
    mo = re.search(error, error_lines)
    assert mo is not None
def test_invalid_folder_path():
    log_file = 'log/%s.log' % POLPOT_CONFIG.replace('.yml', '')
    os.path.exists(log_file) and os.remove(log_file)
    open(log_file, 'a').close()
    of = sh.OutputFile(log_file)
    expectedErrPattern = 'Validation failed'
    with pytest.raises(Exception) as excinfo:
        get_bld_connector(POLPOT_CONFIG)
    actualErrVerbiage = excinfo.value.args[0]
    assert expectedErrPattern in actualErrVerbiage

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line][0]
    error = "were not present in the Jenkins inventory of Folders"
    mo = re.search(error, error_lines)
    assert mo is not None
def test_improperly_specified_folder_name_in_full_folder_path_env():
    log_file = 'log/%s.log' % BANG_CONFIG.replace('.yml', '')
    os.path.exists(log_file) and os.remove(log_file)
    open(log_file, 'a').close()
    of = sh.OutputFile(log_file)
    expectedErrPattern = 'Validation failed'
    with pytest.raises(Exception) as excinfo:
        get_bld_connector(BANG_CONFIG)
    actualErrVerbiage = excinfo.value.args[0]
    assert expectedErrPattern in actualErrVerbiage

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line][2]
    error = "Check if your Folder entries use the fully qualified path syntax"
    mo = re.search(error, error_lines)
    assert mo is not None
def test_folder_name_referenced_multiple_times_with_no_full_folder_path_config(
):
    log_file = 'log/%s.log' % DOS_WOMBATS_CONFIG.replace('.yml', '')
    os.path.exists(log_file) and os.remove(log_file)
    open(log_file, 'a').close()
    of = sh.OutputFile(log_file)
    expectedErrPattern = 'Validation failed'
    with pytest.raises(Exception) as excinfo:
        get_bld_connector(DOS_WOMBATS_CONFIG)
    actualErrVerbiage = excinfo.value.args[0]
    assert expectedErrPattern in actualErrVerbiage

    log_output = of.readlines()
    error_lines = [line for line in log_output if 'ERROR' in line]
    dupe_folder_line = [
        line for line in error_lines
        if 'Duplicated folder names: immovable wombats' in line
    ][0]
    full_path_line = [
        line for line in error_lines
        if 'You should use the FullFolderPath' in line
    ][0]
    assert dupe_folder_line
    assert full_path_line