Пример #1
0
def test_rename_label_twice(from_baseline):
    repo = from_baseline

    change_name = deepcopy(BASELINE)
    change_name[0]["oldname"] = change_name[0]["name"]
    change_name[0]["name"] = "new label name"

    # Apply the labels the first time.
    request = HandlerRequest(repository=repo, data=deepcopy(change_name))
    labels.apply(request)

    expected_labels = {label["name"]: label for label in change_name}

    round_one_labels = list(repo.get_labels())

    compare_label_data(actual=round_one_labels, expected=expected_labels)

    # Apply the labels a second time.
    # This means that the label with 'oldname' still has that setting.
    request = HandlerRequest(repository=repo, data=deepcopy(change_name))
    labels.apply(request)

    round_two_labels = list(repo.get_labels())

    compare_label_data(actual=round_two_labels, expected=expected_labels)
Пример #2
0
def test_repository(from_baseline, new_config):
    repo = from_baseline

    request = HandlerRequest(arepo=repo, data=deepcopy(new_config))
    repository.apply(request)

    compare_repository_data(repo=repo, expected=new_config)
Пример #3
0
def apply_baseline(repo):
    request = HandlerRequest(arepo=repo, data=deepcopy(BASELINE))

    repository.apply(request)
    baseline_wait()

    assert_baseline(repo)
Пример #4
0
def apply_baseline(repo: Repository, org: Organization):
    request = HandlerRequest(repository=repo,
                             data=deepcopy(BASELINE),
                             organization=org)
    teams.apply(request)
    baseline_wait()

    assert_baseline(repo)
Пример #5
0
def no_teams_but_return_to_baseline(integ_repo, github_client):
    repo = github_client.get_repo(integ_repo)
    org = github_client.get_organization(REPO_ORG)
    request = HandlerRequest(repository=repo, data=[], organization=org)
    teams.apply(request)
    current_teams = list(repo.get_teams())
    assert len(current_teams) == 0
    yield repo, org
    apply_baseline(repo, org)
Пример #6
0
def test_branch_protection(from_baseline, new_configs):
    repo = from_baseline

    request = HandlerRequest(arepo=repo, data=deepcopy(new_configs))
    branches.apply(request)

    expected_config = {config["name"]: config["protection"] for config in new_configs}

    actual_config = _get_branch_protections(repo, [branch["name"] for branch in new_configs])

    compare_branch_protection_data(actual=actual_config, expected=expected_config)
Пример #7
0
def test_labels(from_baseline, new_labels):
    repo = from_baseline

    request = HandlerRequest(repository=repo, data=deepcopy(new_labels))
    labels.apply(request)

    expected_labels = {label["name"]: label for label in new_labels}

    actual_labels = list(repo.get_labels())

    compare_label_data(actual=actual_labels, expected=expected_labels)
Пример #8
0
def test_private_repo_swap(private_integ_repo, agithub_client):
    owner, repo_name = private_integ_repo.split("/", 1)
    repo = getattr(getattr(agithub_client.repos, owner), repo_name)

    private_baseline = dict(
        description="this repo is used to test mattsb42/repo-manager",
        private=False)

    make_public_request = HandlerRequest(arepo=repo,
                                         data=deepcopy(private_baseline))
    repository.apply(make_public_request)

    compare_repository_data(repo=repo, expected=private_baseline)

    make_private_data = deepcopy(private_baseline)
    make_private_data["private"] = True
    make_private_request = HandlerRequest(arepo=repo,
                                          data=deepcopy(make_private_data))
    repository.apply(make_private_request)

    compare_repository_data(repo=repo, expected=make_private_data)
Пример #9
0
def push_bots_return_to_baseline(integ_repo, github_client, agithub_client):
    owner, repo_name = integ_repo.split("/", 1)
    arepo = getattr(getattr(agithub_client.repos, owner), repo_name)
    aorg = getattr(agithub_client.orgs, owner)
    repo = github_client.get_repo(integ_repo)
    org = github_client.get_organization(REPO_ORG)
    request = HandlerRequest(repository=repo,
                             data=[dict(name="bots", permission="push")],
                             organization=org)
    teams.apply(request)
    yield arepo, aorg
    apply_baseline(repo, org)
Пример #10
0
def test_rename_repository(integ_repo, agithub_client):
    owner, original_name = integ_repo.split("/", 1)
    new_name = original_name + "-name-change"

    repo = getattr(getattr(agithub_client.repos, owner), original_name)
    renamed_repo = getattr(getattr(agithub_client.repos, owner), new_name)

    rename_data = deepcopy(BASELINE)
    rename_data["name"] = new_name
    change_name_request = HandlerRequest(arepo=repo,
                                         data=deepcopy(rename_data))
    repository.apply(change_name_request)

    compare_repository_data(repo=renamed_repo, expected=rename_data)

    reset_data = deepcopy(BASELINE)
    reset_data["name"] = original_name
    reset_name_request = HandlerRequest(arepo=renamed_repo,
                                        data=deepcopy(reset_data))
    repository.apply(reset_name_request)

    compare_repository_data(repo=repo, expected=reset_data)
Пример #11
0
def test_teams(from_baseline, new_data):
    repo, org = from_baseline

    request = HandlerRequest(repository=repo,
                             data=deepcopy(new_data),
                             organization=org)

    teams.apply(request)

    expected_data = {team["name"]: team for team in new_data}

    team_data = list(repo.get_teams())

    compare_team_permissions(actual=team_data, expected=expected_data)
Пример #12
0
def test_milestones(from_baseline, new_milestones):
    repo = from_baseline

    request = HandlerRequest(repository=repo, data=deepcopy(new_milestones))
    milestones.apply(request)

    expected_milestones = {
        milestone["title"]: milestone
        for milestone in new_milestones
    }

    actual_milestones = list(repo.get_milestones(state="all"))

    compare_milestone_data(actual=actual_milestones,
                           expected=expected_milestones)
Пример #13
0
def test_collaborators(from_baseline, new_users, expected_invites):
    repo = from_baseline

    request = HandlerRequest(repository=repo, data=deepcopy(new_users))
    collaborators.apply(request)

    expected_user_invites = {
        user["username"]: user
        for user in expected_invites
    }
    expected_users = {
        user["username"]: user
        for user in new_users if user["username"] not in expected_user_invites
    }

    actual_users = list(repo.get_collaborators())
    invited_users = [
        invite.invitee for invite in repo.get_pending_invitations()
    ]

    compare_invite_data(actual=invited_users, expected=expected_user_invites)
    compare_collaborator_data(actual=actual_users, expected=expected_users)
Пример #14
0
def apply_baseline(repo: Repository):
    request = HandlerRequest(repository=repo, data=deepcopy(BASELINE))
    labels.apply(request)
    baseline_wait()

    assert_baseline(repo)