Beispiel #1
0
def test_get_all_git_commit_history_between_provided_tags_beginning_tag_not_found(
        monkeypatch):
    monkeypatch.setenv('GITHUB_TOKEN', 'fake_token')
    current_test_directory = os.path.dirname(os.path.realpath(__file__))

    with open(current_test_directory + "/git_tag_mock_output_random.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        with pytest.raises(SystemExit):
            _b = MagicMock(BuildConfig)
            _b.json_config = mock_build_config_dict

            _gh = GitHub(config_override=_b, verify_repo=False)
            _gh.get_all_tags_and_shas_from_github = MagicMock(
                return_value=captured_tag_data)

            good_tag = [1, 99, 98]
            returned_commits = _gh.get_all_git_commit_history_between_provided_tags(
                good_tag)

    mock_printmsg_fn.assert_any_call(
        'GitHub', 'get_all_git_commit_history_between_provided_tags',
        "Version tag not "
        "found v1.99.98", 'ERROR')
Beispiel #2
0
def test_convert_semver_string_to_semver_tag_array_bad_format_missing_build_number(
):
    _github = GitHub(verify_repo=False)
    with pytest.raises(Exception) as exc:
        tag_array = _github.convert_semver_string_to_semver_tag_array(
            "v1.0.0+")
        assert True
Beispiel #3
0
def test_format_github_specific_release_notes_from_tracker_story_details_pass_one(
):

    _github = GitHub(verify_repo=False)

    release_notes = _github.format_github_specific_release_notes_from_tracker_story_details(
        story_details=None)

    assert release_notes == 'No Release Notes'
Beispiel #4
0
def test_verify_repo_existence():

    _github = GitHub(verify_repo=False)

    responses.add(responses.GET, "http://mygithub/my_org/my_repo", status=200)
    _github._verify_repo_existence("http://mygithub", "my_org", "my_repo",
                                   "my_token")

    assert len(responses.calls) == 1
Beispiel #5
0
def test_calculate_next_semver_first_release_major():
    _github = GitHub(verify_repo=False)
    tag_type = "release"
    bump_type = "major"
    highest_version_array = None
    new_tag_array = _github.calculate_next_semver(
        tag_type=tag_type,
        bump_type=bump_type,
        highest_version_array=highest_version_array)
    assert new_tag_array == [1, 0, 0, 0]
Beispiel #6
0
def test_calculate_next_semver_next_release_minor_with_minor():
    _github = GitHub(verify_repo=False)
    tag_type = "release"
    bump_type = "minor"
    highest_version_array = [0, 1, 1, 1]
    new_tag_array = _github.calculate_next_semver(
        tag_type=tag_type,
        bump_type=bump_type,
        highest_version_array=highest_version_array)
    assert new_tag_array == [0, 2, 0, 0]
Beispiel #7
0
def test_calculate_next_semver_first_snapshot():
    _github = GitHub(verify_repo=False)
    tag_type = "snapshot"
    bump_type = None
    highest_version_array = None
    new_tag_array = _github.calculate_next_semver(
        tag_type=tag_type,
        bump_type=bump_type,
        highest_version_array=highest_version_array)
    assert new_tag_array == [0, 0, 0, 1]
Beispiel #8
0
def test_calculate_next_semver_next_snapshot_after_release():
    _github = GitHub(verify_repo=False)
    tag_type = "snapshot"
    bump_type = "minor"
    highest_version_array = [0, 1, 0, 0]
    new_tag_array = _github.calculate_next_semver(
        tag_type=tag_type,
        bump_type=bump_type,
        highest_version_array=highest_version_array)
    assert new_tag_array == [0, 1, 0, 1]
Beispiel #9
0
def test_format_github_specific_release_notes_from_tracker_story_details():

    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/tracker_stories.json", 'r') as myfile:
        tracker_json_data = json.loads(myfile.read())

    release_notes = _github.format_github_specific_release_notes_from_tracker_story_details(
        story_details=tracker_json_data["stories"])

    assert len(release_notes) == 696
Beispiel #10
0
def test_get_highest_semver_snapshot_tag():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_last_was_release.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)
    highest_tag = _github.get_highest_semver_snapshot_tag()
    assert highest_tag == [0, 1, 0, 2]
Beispiel #11
0
def test_init_without_github_token(monkeypatch):
    if os.getenv('GITHUB_TOKEN'):
        monkeypatch.delenv('GITHUB_TOKEN')

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        _github = GitHub(verify_repo=False)
        _github._load_github_token()
    mock_printmsg_fn.assert_any_call(
        'GitHub', '_load_github_token',
        "No github token found.  If your repo doesn't allow anonymous "
        "access, some operations may fail. To define a token, please set "
        "environment variable 'GITHUB_TOKEN'", 'WARN')
Beispiel #12
0
def test_call_verify_tags_found_base_version():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_one_release.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().strip().split('\n')))
    assert _github._verify_tags_found(captured_tag_data, 0, 0, 'v1.2.3',
                                      True) == True
    assert _github._verify_tags_found(captured_tag_data, 0, 0, 'v1.2.4',
                                      True) == False
Beispiel #13
0
def test_does_semver_tag_not_exist():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_last_was_release.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)
    existing_tag = [0, 3, 0, 0]
    exists = _github._does_semver_tag_exist(existing_tag)
    assert exists == False
Beispiel #14
0
def test_call_verify_tags_found_multiple_snapshot_multiple_found():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_three_release.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().strip().split('\n')))
    assert _github._verify_tags_found(captured_tag_data, 10, 0, None,
                                      False) == True
    assert _github._verify_tags_found(captured_tag_data, 5, 0, None,
                                      False) == True
    assert _github._verify_tags_found(captured_tag_data, 12, 0, None,
                                      False) == False
Beispiel #15
0
def test_fetch_commit_history_for_repo_with_no_tags():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/github_commit_history_output.txt",
              'r') as myfile:
        captured_commit_history_data = json.loads(myfile.read())
    _github.get_all_commits_from_github = MagicMock(
        return_value=captured_commit_history_data)
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=[("v1.0.0", "c968da6")])
    commits_array = _github.get_all_git_commit_history_between_provided_tags(
        None)
    print(str(commits_array))
    assert len(commits_array) == 60
Beispiel #16
0
def test_call_get_all_tags_sorted():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_mock_output.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)
    all_tags = _github.get_all_semver_tags()
    # there are 176 tags in the file
    # but after tag format validation there are 131
    assert len(all_tags) == 131
Beispiel #17
0
def test_call_get_all_semver_tags_sorted_from_random():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_mock_output_random.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)
    all_tags = GitHub.get_all_semver_tags(_github)
    # assert the length, first and last
    assert len(all_tags) == 131
    assert all_tags[0] == [1, 67, 0, 0]
    assert all_tags[-1] == [0, 0, 0, 56]
Beispiel #18
0
def test_calculate_next_semver_tag_type_release_but_bad_bump_type():
    _github = GitHub(verify_repo=False)
    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        with pytest.raises(SystemExit) as exc:
            # tag type must be either "release" or "snapshot"
            tag_type = "release"
            bump_type = "bubba"
            highest_version_array = None
            _github.calculate_next_semver(
                tag_type=tag_type,
                bump_type=bump_type,
                highest_version_array=highest_version_array)
    mock_printmsg_fn.assert_called_with(
        'GitHub', 'calculate_next_semver', "Bump types can only be 'major', "
        "'minor' or 'bug', instead bubba was "
        "provided.")
Beispiel #19
0
def test_calculate_next_semver_no_tag_type():
    _github = GitHub(verify_repo=False)
    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        with pytest.raises(SystemExit) as exc:
            # tag type must be either "release" or "snapshot"
            tag_type = None
            bump_type = None
            highest_version_array = None
            _github.calculate_next_semver(
                tag_type=tag_type,
                bump_type=bump_type,
                highest_version_array=highest_version_array)
    mock_printmsg_fn.assert_called_with(
        'GitHub', 'calculate_next_semver',
        "Tag types can only be 'release' or "
        "'snapshot', instead None was provided.")
Beispiel #20
0
def test_get_highest_semver_snapshot_tag_from_base():
    _github = GitHub(verify_repo=False)
    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    #with open(current_test_directory + "/git_tag_mock_output.txt", 'r') as myfile:
    with open(
            current_test_directory + "/git_tag_unordered_manual_versions.txt",
            'r') as myfile:
        #captured_tag_data=myfile.read()
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)
    base_release_version = [0, 1, 0, 0]
    highest_tag = _github.get_highest_semver_array_snapshot_tag_from_base(
        base_release_version)
    assert highest_tag == [0, 1, 0, 2]
Beispiel #21
0
def test_get_all_git_commit_history_between_provided_tags_invalid_ending_tag(
        monkeypatch):
    monkeypatch.setenv('GITHUB_TOKEN', 'fake_token')

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        with pytest.raises(SystemExit):
            _b = MagicMock(BuildConfig)
            _b.json_config = mock_build_config_dict

            _gh = GitHub(config_override=_b, verify_repo=False)
            good_tag = [1, 0, 0]
            bad_tag = ['v', 1, 0, 0]
            _gh.get_all_git_commit_history_between_provided_tags(
                good_tag, bad_tag)

    mock_printmsg_fn.assert_called_with(
        'GitHub', 'get_all_git_commit_history_between_provided_tags',
        "Invalid ending version defined ['v', 1, 0, 0]", 'ERROR')
Beispiel #22
0
def test_verify_repo_does_not_existence():

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:

        _github = GitHub(verify_repo=False)

        responses.add(responses.GET,
                      "http://mygithub/my_org/my_repo",
                      status=201)
        with pytest.raises(SystemExit):
            _github._verify_repo_existence("http://mygithub", "my_org",
                                           "my_repo", "my_token")

        print(str(mock_printmsg_fn.mock_calls))
        mock_printmsg_fn.assert_called_with(
            "GitHub", "_verify_repo_existence",
            "Failed to access github location "
            "http://mygithub/my_org/my_repo\r\n Response: ", "ERROR")
        assert len(responses.calls) == 1
Beispiel #23
0
def test_get_git_previous_tag_snapshot():
    _github = GitHub(verify_repo=False)
    old_artifact_category = _github.config.artifact_category

    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/git_tag_mock_output_small.txt",
              'r') as myfile:
        captured_tag_data = list(
            map(lambda tag: (tag, 'sha'),
                myfile.read().split('\n')))
    _github.get_all_tags_and_shas_from_github = MagicMock(
        return_value=captured_tag_data)

    _github.config.artifact_category = 'snapshot'
    existing_tag = '1.67.0+10'
    previous_tag = _github.get_git_previous_tag(existing_tag)
    assert previous_tag == '1.67.0+9'

    existing_tag = '1.67.0+1'
    previous_tag = _github.get_git_previous_tag(existing_tag)
    assert previous_tag == '1.66.0+2'

    _github.config.artifact_category = 'release'
    existing_tag = '1.68.0'
    previous_tag = _github.get_git_previous_tag(existing_tag)
    assert previous_tag == '1.67.0'

    _github.config.artifact_category = old_artifact_category
Beispiel #24
0
def test_add_tag_and_release_notes_to_github():

    # this is pretty weak but also an indication that the
    # target method of testing is *too* big. Need to split out
    # add_tag_and_release_notes_to_github

    current_test_directory = os.path.dirname(os.path.realpath(__file__))
    with open(current_test_directory + "/tracker_stories.json", 'r') as myfile:
        tracker_json_data = json.loads(myfile.read())

    with patch('flow.utils.commons.execute_command', return_value="master\n"):
        _b = MagicMock(BuildConfig)
        _b.build_env_info = mock_build_config_dict['environments']['develop']
        _b.json_config = mock_build_config_dict
        _b.project_name = mock_build_config_dict['projectInfo']['name']
        _github = GitHub(config_override=_b, verify_repo=False)
        _github._verify_required_attributes()

        responses.add(
            responses.POST,
            "https://fakegithub.com/api/v3/repos/Org-GitHub/Repo-GitHub/releases",
            status=200)

        _github.add_tag_and_release_notes_to_github(
            [0, 0, 0, 1], tracker_json_data["stories"])

    assert len(responses.calls) == 1
Beispiel #25
0
def test_verify_required_attributes_missing_org(monkeypatch):
    monkeypatch.setenv('GITHUB_TOKEN', 'fake_token')

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        with pytest.raises(SystemExit):
            _b = MagicMock(BuildConfig)
            _b.json_config = mock_build_config_missing_org_dict

            _gh = GitHub(config_override=_b)

    mock_printmsg_fn.assert_called_with(
        'GitHub', '_verify_required_attributes',
        "The build config associated with "
        "github is missing, 'org'.", 'ERROR')
Beispiel #26
0
def test_convert_semver_string_to_semver_tag_array_snapshot():
    _github = GitHub(verify_repo=False)
    tag_array = _github.convert_semver_string_to_semver_tag_array("v1.2.3+4")
    assert tag_array == [1, 2, 3, 4]
Beispiel #27
0
def test_convert_semver_string_to_semver_tag_array_release():
    _github = GitHub(verify_repo=False)

    tag_array = _github.convert_semver_string_to_semver_tag_array("v1.2.3")
    assert tag_array == [1, 2, 3, 0]
Beispiel #28
0
def test_get_highest_semver_snapshot_tag_when_no_tags():
    _github = GitHub(verify_repo=False)
    _github.get_all_tags_and_shas_from_github = MagicMock(return_value=[])
    highest_tag = _github.get_highest_semver_release_tag()
    assert highest_tag is None
Beispiel #29
0
def test_convert_semver_string_to_semver_tag_array_bad_format():
    _github = GitHub(verify_repo=False)
    with pytest.raises(Exception) as exc:
        tag_array = _github.convert_semver_string_to_semver_tag_array(
            "homer_was_here")
        assert True
Beispiel #30
0
def test_no_initialize_object():
    _github = GitHub(verify_repo=False)
    assert _github is not None