Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(test): submit to protected branches #398

Merged
merged 11 commits into from
Apr 21, 2020
14 changes: 14 additions & 0 deletions tests/perforce_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ def perforce_workspace(request, perforce_connection, tmpdir):
change["Description"] = "Test submit"
p4.run_submit(change)

permissions = p4.fetch_protect()
permissions['Protections'] = [
'write user * * //...',
k-dovgan marked this conversation as resolved.
Show resolved Hide resolved
'list user * * -//spec/...',
'super user p4user * //...', # first three rows are default
'=write user p4user * -//depot/write-protected/...' # prohibit p4user to submit changes to this branch
]
p4.save_protect(permissions)

triggers = {'Triggers': [
'test.check change-submit //depot/trigger-protected/... "false"' # trigger to prevent any submits to this branch
]}
p4.save_triggers(triggers)

yield utils.Params(p4=p4,
client_name=client_name,
depot=depot,
Expand Down
2 changes: 0 additions & 2 deletions tests/test_p4_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def p4_submit_environment(perforce_workspace, tmpdir):


def test_fail_changing_non_checked_out_file(p4_submit_environment):

target_file = p4_submit_environment.nonwritable_file
text = utils.randomize_name("This is change ")
with pytest.raises(IOError) as excinfo:
Expand All @@ -24,7 +23,6 @@ def test_fail_changing_non_checked_out_file(p4_submit_environment):


def test_success_changing_checked_out_file(p4_submit_environment):

target_file = p4_submit_environment.nonwritable_file

p4_submit_environment.p4.run("edit", str(target_file))
Expand Down
24 changes: 24 additions & 0 deletions tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ def test_error_no_repo(submit_environment, stdout_checker):
stdout_checker.assert_has_calls_with_param("Workspace 'non_existing_client' doesn't exist!")


@pytest.fixture()
def p4_submit_environment(perforce_workspace, tmpdir):
yield perforce_utils.P4Environment(perforce_workspace, tmpdir, test_type="submit")


@pytest.mark.parametrize("branch", ["write-protected", "trigger-protected"])
def test_fail_forbidden_branch(p4_submit_environment, branch):
protected_dir = p4_submit_environment.vcs_cooking_dir.mkdir(branch)
file_to_add = protected_dir.join("new_file.txt")
text = "This is a new line in the file"
file_to_add.write(text + "\n")

settings = copy.deepcopy(p4_submit_environment.settings)
setattr(settings.Submit, "reconcile_list", [unicode(file_to_add)])

assert universum.run(settings)

p4 = p4_submit_environment.p4
# make sure submitter didn't leave any pending CLs in the workspace
assert not p4.run_changes("-c", p4_submit_environment.client_name, "-s", "pending")
# make sure submitter didn't leave any pending changes in default CL
assert not p4.run_opened("-C", p4_submit_environment.client_name)


class SubmitterParameters(object):
def __init__(self, stdout_checker, environment):
self.stdout_checker = stdout_checker
Expand Down