def test_merge_one_branch_noff_1_commit_behind(stdout_checker, http_request_checker, git_poll_environment): # initialize working directory with initial data assert universum.run(git_poll_environment.settings) == 0 # ACT # make a branch from polled git_poll_environment.server.make_branch("test_branch") # make change to the polled branch git_poll_environment.server.switch_branch( git_poll_environment.server.target_branch) change_to_polled = git_poll_environment.server.commit_new_file() # make change to created test branch git_poll_environment.server.switch_branch("test_branch") changes_to_branch = git_poll_environment.server.commit_new_file() # merge test branch to the polled git_poll_environment.server.switch_branch( git_poll_environment.server.target_branch) git_poll_environment.server.merge_branch("test_branch", fast_forward=False) merge_commit_id = git_poll_environment.server.get_last_commit() # ASSERT # run poll again and trigger the url twice assert universum.run(git_poll_environment.settings) == 0 assert_polled_commits([change_to_polled, merge_commit_id], stdout_checker, http_request_checker) stdout_checker.assert_absent_calls_with_param("==> Detected commit " + changes_to_branch)
def test_merge_ff_commit_merged_from_polled(stdout_checker, http_request_checker, git_poll_environment): # initialize working directory with initial data assert universum.run(git_poll_environment.settings) == 0 # ACT # make a branch from polled git_poll_environment.server.make_branch("test_branch") # make a change to the polled branch git_poll_environment.server.switch_branch( git_poll_environment.server.target_branch) change_to_polled = git_poll_environment.server.make_a_change() # make a change to created test branch git_poll_environment.server.switch_branch("test_branch") change_to_branch = git_poll_environment.server.commit_new_file() # merge polled branch to the current # fast-forward is not possible in this case git_poll_environment.server.merge_branch( git_poll_environment.server.target_branch, fast_forward=False) merge_commit_to_branch = git_poll_environment.server.get_last_commit() # merge test branch to the polled using fast forward git_poll_environment.server.switch_branch( git_poll_environment.server.target_branch) git_poll_environment.server.merge_branch("test_branch", fast_forward=True) # ASSERT # run poll again and trigger the url twice assert universum.run(git_poll_environment.settings) == 0 assert_polled_commits([change_to_polled, change_to_branch], stdout_checker, http_request_checker) stdout_checker.assert_absent_calls_with_param("==> Detected commit " + merge_commit_to_branch)
def test_merge_two_subsequent_branches_noff(stdout_checker, http_request_checker, git_poll_environment): # initialize working directory with initial data assert universum.run(git_poll_environment.settings) == 0 # ACT # make changes in polled branch change_to_polled = git_poll_environment.server.make_a_change() # make a branch from polled and add 1 new commit changes_to_first_branch = make_branch_with_changes( git_poll_environment.server, "test_branch1", 1) # make a branch from test_branch1 and add 1 new commit changes_to_second_branch = make_branch_with_changes( git_poll_environment.server, "test_branch2", 1) # merge created branch to the polled using fast-forward option git_poll_environment.server.merge_branch("test_branch2", fast_forward=False) merge_commit_id = git_poll_environment.server.get_last_commit() # ASSERT # run poll again and trigger the url twice assert universum.run(git_poll_environment.settings) == 0 assert_polled_commits([change_to_polled] + [merge_commit_id], stdout_checker, http_request_checker) stdout_checker.assert_absent_calls_with_param("==> Detected commit " + changes_to_first_branch[0]) stdout_checker.assert_absent_calls_with_param("==> Detected commit " + changes_to_second_branch[0])
def test_merge_two_subsequent_branches_ff(stdout_checker, http_request_checker, git_poll_environment): # initialize working directory with initial data assert universum.run(git_poll_environment.settings) == 0 # ACT # make changes in polled branch change_to_polled = git_poll_environment.server.commit_new_file() # make a branch from polled and add 1 new commit changes_to_first_branch = make_branch_with_changes( git_poll_environment.server, "test_branch1", 1) # make a branch from test_branch and add 1 new commit changes_to_second_branch = make_branch_with_changes( git_poll_environment.server, "test_branch2", 1, branch_from="test_branch1") # merge created branch to the polled using fast-forward option git_poll_environment.server.merge_branch("test_branch2", fast_forward=True) # ASSERT # run poll again and trigger the url twice assert universum.run(git_poll_environment.settings) == 0 assert_polled_commits([change_to_polled] + changes_to_first_branch + changes_to_second_branch, stdout_checker, http_request_checker)
def test_submit_error_no_repo(submit_environment, stdout_checker): settings = copy.deepcopy(submit_environment.settings) if settings.Vcs.type == "git": settings.ProjectDirectory.project_root = "non_existing_repo" universum.run(settings) stdout_checker.assert_has_calls_with_param("No such directory") else: settings.PerforceSubmitVcs.client = "non_existing_client" universum.run(settings) stdout_checker.assert_has_calls_with_param( "Workspace 'non_existing_client' doesn't exist!")
def test_poll_success_one_change(poll_parameters, poll_environment): parameters = poll_parameters(poll_environment) # initialize working directory with initial data assert universum.run(parameters.poll_settings) == 0 # make change in workspace change = parameters.make_a_change() # run poll again and trigger the url assert universum.run(parameters.poll_settings) == 0 parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change) parameters.http_request_checker.assert_request_was_made({"cl": [change]})
def test_p4_error_revert(perforce_environment, stdout_checker, capsys): p4 = perforce_environment.p4 p4_file = perforce_environment.repo_file config = """ from _universum.configuration_support import Variations configs = Variations([dict(name="Restrict changes", command=["chmod", "-R", "555", "."]), dict(name="Check", command=["ls", "-la"])]) """ p4.run_edit(perforce_environment.depot) p4_file.write(config) change = p4.fetch_change() change["Description"] = "CL for shelving" shelve_cl = p4.save_change(change)[0].split()[1] p4.run_shelve("-fc", shelve_cl) settings = perforce_environment.settings settings.Launcher.output = "console" settings.PerforceMainVcs.shelve_cls = [shelve_cl] settings.Launcher.config_path = p4_file.basename result = universum.run(settings) # Clean up the directory at once to make sure it doesn't remain non-writable even if some assert fails perforce_environment.temp_dir.chmod(0777, rec=1) perforce_environment.temp_dir.remove(rec=1) assert result != 0 # The following checks make sure all following actions were triggered despite unsuccessful: # full revert, client deleting and sources clean up stdout_checker.assert_has_calls_with_param("Errors during command execution( \"p4 revert //...\" )") stdout_checker.assert_has_calls_with_param( "Errors during command execution( \"p4 client -d {}\" )".format(perforce_environment.client_name)) assert "[Errno 13] Permission denied" in capsys.readouterr().err
def test_unicode(vcs, test_type, perforce_workspace, git_client, unicode_dir): if vcs == "git": # change git client root dir to unicode path work_dir = unicode_dir.mkdir("client") git_client.repo = git.Repo.clone_from(git_client.server.url, unicode(work_dir).encode("utf8")) git_client.root_directory = work_dir env = git_utils.GitEnvironment(git_client, unicode_dir, test_type=test_type) elif vcs == "p4": # change workspace root dir to unicode path root = unicode_dir.mkdir("workspace") client = perforce_workspace.p4.fetch_client( perforce_workspace.client_name) client["Root"] = unicode(root).encode("utf8") perforce_workspace.root_directory = root perforce_workspace.p4.save_client(client) perforce_workspace.p4.run_sync("-f", "//depot/...") env = perforce_utils.P4Environment(perforce_workspace, unicode_dir, test_type=test_type) else: assert False, "Unsupported vcs type" if test_type == "submit": temp_file = env.vcs_cooking_dir.join( utils.randomize_name("new_file") + ".txt") temp_file.write("This is a new file" + "\n") env.settings.Submit.reconcile_list = [unicode(temp_file)] res = universum.run(env.settings) assert res == 0
def test_poll_changes_several_times(poll_parameters, poll_environment): parameters = poll_parameters(poll_environment) # initialize working directory with initial data assert universum.run(parameters.poll_settings) == 0 # make changes in workspace change1 = parameters.make_a_change() change2 = parameters.make_a_change() # run poll and trigger the urls assert universum.run(parameters.poll_settings) == 0 parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change1) parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change2) parameters.http_request_checker.assert_request_was_made({"cl": [change1]}) parameters.http_request_checker.assert_request_was_made({"cl": [change2]}) # make more changes in workspace parameters.stdout_checker.reset() parameters.http_request_checker.reset() change3 = parameters.make_a_change() change4 = parameters.make_a_change() # run poll and trigger urls for the new changes only assert universum.run(parameters.poll_settings) == 0 parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change3) parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change4) parameters.stdout_checker.assert_absent_calls_with_param( "==> Detected commit " + change1) parameters.stdout_checker.assert_absent_calls_with_param( "==> Detected commit " + change2) parameters.http_request_checker.assert_request_was_made({"cl": [change3]}) parameters.http_request_checker.assert_request_was_made({"cl": [change4]}) parameters.http_request_checker.assert_request_was_not_made( {"cl": [change1]}) parameters.http_request_checker.assert_request_was_not_made( {"cl": [change2]})
def submit_path_list(self, path_list, **kwargs): settings = copy.deepcopy(self.submit_settings) setattr(settings.Submit, "reconcile_list", path_list) if kwargs: for key in kwargs: setattr(settings.Submit, key, kwargs[key]) return universum.run(settings)
def test_unicode_main_local_vcs(unicode_dir): work_dir = unicode_dir.mkdir("local_sources") work_dir.join("source_file").write("Source file contents") env = utils.TestEnvironment(unicode_dir, "main") env.settings.Vcs.type = "none" env.settings.LocalMainVcs.source_dir = unicode(work_dir) res = universum.run(env.settings) assert res == 0
def test_max_number_commits(stdout_checker, http_request_checker, git_poll_environment): # initialize working directory with initial data assert universum.run(git_poll_environment.settings) == 0 # ACT # make changes in polled branch allowed_commits_number = git_poll_environment.settings.Poll.max_number changes_to_polled = [ git_poll_environment.server.commit_new_file() for _ in range(allowed_commits_number + 1) ] # ASSERT # run poll again and trigger the url twice assert universum.run(git_poll_environment.settings) == 0 assert_polled_commits(changes_to_polled[1:], stdout_checker, http_request_checker) # Ensure that oldest commit is beyond "allowed_commits_number" and is not polled stdout_checker.assert_absent_calls_with_param("==> Detected commit " + changes_to_polled[0])
def test_poll_error_one_change(poll_parameters, poll_environment): parameters = poll_parameters(poll_environment) # initialize working directory with initial data assert universum.run(parameters.poll_settings) == 0 # stop server parameters.http_request_checker.stop() # make change in workspace change = parameters.make_a_change() # run poll again and fail triggering url because there is no server assert universum.run(parameters.poll_settings) != 0 parameters.stdout_checker.assert_has_calls_with_param( "==> Detected commit " + change) # there is no listening server parameters.log_exception_checker.assert_has_calls_with_param( "[Errno 111] Connection refused")