feature: adds test checking new pr settings flag, refactor tests
This commit is contained in:
parent
034a34da3f
commit
83ca0d54f2
1 changed files with 105 additions and 125 deletions
|
|
@ -17,6 +17,7 @@
|
|||
# and proprietary license terms, please see https://rhodecode.com/licenses/
|
||||
import logging
|
||||
import os
|
||||
from typing import List, Tuple
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
|
@ -44,7 +45,7 @@ from rhodecode.tests import (
|
|||
TEST_USER_ADMIN_LOGIN,
|
||||
TEST_USER_REGULAR_LOGIN,
|
||||
)
|
||||
from rhodecode.tests.fixtures.fixture_utils import PRTestUtility
|
||||
from rhodecode.tests.fixtures.fixture_utils import PRTestUtility, Backend
|
||||
from rhodecode.tests.routes import route_path
|
||||
|
||||
|
||||
|
|
@ -141,43 +142,19 @@ class TestPullrequestsView(object):
|
|||
source_ref = "branch:{branch}:{commit_id}".format(
|
||||
branch=backend.default_branch_name, commit_id=commit_ids["commit-1"]
|
||||
)
|
||||
|
||||
response = self.app.post(
|
||||
route_path("pullrequest_create", repo_name=source.repo_name),
|
||||
[
|
||||
("source_repo", source_repo_name),
|
||||
("source_ref", source_ref),
|
||||
("target_repo", target_repo_name),
|
||||
("target_ref", target_ref),
|
||||
("common_ancestor", commit_ids["initial-commit"]),
|
||||
("pullrequest_title", "Title"),
|
||||
("pullrequest_desc", "Description"),
|
||||
("description_renderer", "markdown"),
|
||||
("__start__", "review_members:sequence"),
|
||||
("__start__", "reviewer:mapping"),
|
||||
("user_id", "1"),
|
||||
("__start__", "reasons:sequence"),
|
||||
("reason", "Some reason"),
|
||||
("__end__", "reasons:sequence"),
|
||||
("__start__", "rules:sequence"),
|
||||
("__end__", "rules:sequence"),
|
||||
("mandatory", "False"),
|
||||
("__end__", "reviewer:mapping"),
|
||||
("__end__", "review_members:sequence"),
|
||||
("__start__", "revisions:sequence"),
|
||||
("revisions", commit_ids["commit-1"]),
|
||||
("__end__", "revisions:sequence"),
|
||||
("user", ""),
|
||||
("csrf_token", csrf_token),
|
||||
],
|
||||
status=302,
|
||||
pr_post_for_params = self._get_pr_create_post_form_params(
|
||||
csrf_token, source, target, revisions=[commit_ids["commit-1"]]
|
||||
)
|
||||
pr_post_for_params.extend(
|
||||
[
|
||||
("target_ref", target_ref),
|
||||
("source_ref", source_ref),
|
||||
("common_ancestor", commit_ids["initial-commit"]),
|
||||
]
|
||||
)
|
||||
pull_request_id, _ = self._create_pr_and_initial_validation(pr_post_for_params, source)
|
||||
|
||||
location = response.headers["Location"]
|
||||
|
||||
pull_request_id = location.rsplit("/", 1)[1]
|
||||
assert pull_request_id != "new"
|
||||
pull_request = PullRequest.get(int(pull_request_id))
|
||||
pull_request = PullRequest.get(pull_request_id)
|
||||
|
||||
pull_request_id = pull_request.pull_request_id
|
||||
|
||||
|
|
@ -354,6 +331,17 @@ class TestPullrequestsView(object):
|
|||
response.mustcontain(cb_context("LINE3"))
|
||||
response.mustcontain(cb_line("LINE4"))
|
||||
|
||||
def _create_pr_and_initial_validation(self, pr_post_for_params, source):
|
||||
response = self.app.post(
|
||||
route_path("pullrequest_create", repo_name=source.repo_name),
|
||||
pr_post_for_params,
|
||||
status=302,
|
||||
)
|
||||
location = response.headers["Location"]
|
||||
pull_request_id = location.rsplit("/", 1)[1]
|
||||
assert pull_request_id != "new"
|
||||
return int(pull_request_id), response
|
||||
|
||||
def test_close_status_visibility(self, pr_util, user_util, csrf_token):
|
||||
# Logout
|
||||
response = self.app.post(h.route_path("logout"), params={"csrf_token": csrf_token})
|
||||
|
|
@ -867,7 +855,7 @@ class TestPullrequestsView(object):
|
|||
)
|
||||
assert response.status_int == 403
|
||||
|
||||
def test_create_pull_request(self, backend, csrf_token):
|
||||
def test_create_pull_request_user_set_test_create_pull_request_to_true(self, backend, csrf_token):
|
||||
commits = [
|
||||
{"message": "ancestor"},
|
||||
{"message": "change"},
|
||||
|
|
@ -877,48 +865,82 @@ class TestPullrequestsView(object):
|
|||
target = backend.create_repo(heads=["ancestor"])
|
||||
source = backend.create_repo(heads=["change2"])
|
||||
|
||||
response = self.app.post(
|
||||
route_path("pullrequest_create", repo_name=source.repo_name),
|
||||
pr_post_for_params = self._get_pr_create_post_form_params(
|
||||
csrf_token, source, target, revisions=[commit_ids["change"], commit_ids["change2"]]
|
||||
)
|
||||
pr_post_for_params.extend(
|
||||
[
|
||||
("source_repo", source.repo_name),
|
||||
("close_branch_before_merging", "true"),
|
||||
("source_ref", "branch:default:" + commit_ids["change2"]),
|
||||
("target_repo", target.repo_name),
|
||||
("target_ref", "branch:default:" + commit_ids["ancestor"]),
|
||||
("common_ancestor", commit_ids["ancestor"]),
|
||||
("pullrequest_title", "Title"),
|
||||
("pullrequest_desc", "Description"),
|
||||
("description_renderer", "markdown"),
|
||||
("__start__", "review_members:sequence"),
|
||||
("__start__", "reviewer:mapping"),
|
||||
("user_id", "1"),
|
||||
("__start__", "reasons:sequence"),
|
||||
("reason", "Some reason"),
|
||||
("__end__", "reasons:sequence"),
|
||||
("__start__", "rules:sequence"),
|
||||
("__end__", "rules:sequence"),
|
||||
("mandatory", "False"),
|
||||
("__end__", "reviewer:mapping"),
|
||||
("__end__", "review_members:sequence"),
|
||||
("__start__", "revisions:sequence"),
|
||||
("revisions", commit_ids["change"]),
|
||||
("revisions", commit_ids["change2"]),
|
||||
("__end__", "revisions:sequence"),
|
||||
("user", ""),
|
||||
("csrf_token", csrf_token),
|
||||
],
|
||||
status=302,
|
||||
]
|
||||
)
|
||||
pull_request_id, _ = self._create_pr_and_initial_validation(pr_post_for_params, source)
|
||||
|
||||
pull_request = PullRequest.get(pull_request_id)
|
||||
|
||||
assert len(pull_request.settings) == 1
|
||||
assert pull_request.settings["close_branch_before_merging"]
|
||||
|
||||
def _get_pr_create_post_form_params(
|
||||
self, csrf_token: str, source: Backend, target: Backend, revisions: list, user_id: str = "1"
|
||||
):
|
||||
return [
|
||||
("source_repo", source.repo_name),
|
||||
("target_repo", target.repo_name),
|
||||
("pullrequest_title", "Title"),
|
||||
("pullrequest_desc", "Description"),
|
||||
("description_renderer", "markdown"),
|
||||
("__start__", "review_members:sequence"),
|
||||
("__start__", "reviewer:mapping"),
|
||||
("user_id", user_id),
|
||||
("__start__", "reasons:sequence"),
|
||||
("reason", "Some reason"),
|
||||
("__end__", "reasons:sequence"),
|
||||
("__start__", "rules:sequence"),
|
||||
("__end__", "rules:sequence"),
|
||||
("mandatory", "False"),
|
||||
("__end__", "reviewer:mapping"),
|
||||
("__end__", "review_members:sequence"),
|
||||
("__start__", "revisions:sequence"),
|
||||
*[("revisions", r) for r in revisions],
|
||||
("__end__", "revisions:sequence"),
|
||||
("user", ""),
|
||||
("csrf_token", csrf_token),
|
||||
]
|
||||
|
||||
def test_create_pull_request(self, backend, csrf_token):
|
||||
commits = [
|
||||
{"message": "ancestor"},
|
||||
{"message": "change"},
|
||||
{"message": "change2"},
|
||||
]
|
||||
commit_ids = backend.create_master_repo(commits)
|
||||
target = backend.create_repo(heads=["ancestor"])
|
||||
source = backend.create_repo(heads=["change2"])
|
||||
pr_post_for_params = self._get_pr_create_post_form_params(
|
||||
csrf_token, source, target, revisions=[commit_ids["change"], commit_ids["change2"]]
|
||||
)
|
||||
pr_post_for_params.extend(
|
||||
[
|
||||
("source_ref", "branch:default:" + commit_ids["change2"]),
|
||||
("target_ref", "branch:default:" + commit_ids["ancestor"]),
|
||||
("common_ancestor", commit_ids["ancestor"]),
|
||||
]
|
||||
)
|
||||
|
||||
location = response.headers["Location"]
|
||||
pull_request_id = location.rsplit("/", 1)[1]
|
||||
assert pull_request_id != "new"
|
||||
pull_request = PullRequest.get(int(pull_request_id))
|
||||
pull_request_id, _ = self._create_pr_and_initial_validation(pr_post_for_params, source)
|
||||
|
||||
pull_request = PullRequest.get(pull_request_id)
|
||||
|
||||
# check that we have now both revisions
|
||||
assert pull_request.revisions == [commit_ids["change2"], commit_ids["change"]]
|
||||
assert pull_request.source_ref == "branch:default:" + commit_ids["change2"]
|
||||
expected_target_ref = "branch:default:" + commit_ids["ancestor"]
|
||||
assert pull_request.target_ref == expected_target_ref
|
||||
assert len(pull_request.settings) == 1
|
||||
assert not pull_request.settings["close_branch_before_merging"]
|
||||
|
||||
def test_reviewer_notifications(self, backend, csrf_token):
|
||||
# We have to use the app.post for this test, so it will create the
|
||||
|
|
@ -945,42 +967,23 @@ class TestPullrequestsView(object):
|
|||
target = backend.create_repo(heads=["ancestor-child"])
|
||||
source = backend.create_repo(heads=["change"])
|
||||
|
||||
response = self.app.post(
|
||||
route_path("pullrequest_create", repo_name=source.repo_name),
|
||||
pr_post_for_params = self._get_pr_create_post_form_params(
|
||||
csrf_token, source, target, user_id="2", revisions=[commit_ids["change"]]
|
||||
)
|
||||
pr_post_for_params.extend(
|
||||
[
|
||||
("source_repo", source.repo_name),
|
||||
("source_ref", "branch:default:" + commit_ids["change"]),
|
||||
("target_repo", target.repo_name),
|
||||
("target_ref", "branch:default:" + commit_ids["ancestor-child"]),
|
||||
("common_ancestor", commit_ids["ancestor"]),
|
||||
("pullrequest_title", "Title"),
|
||||
("pullrequest_desc", "Description"),
|
||||
("description_renderer", "markdown"),
|
||||
("__start__", "review_members:sequence"),
|
||||
("__start__", "reviewer:mapping"),
|
||||
("user_id", "2"),
|
||||
("__start__", "reasons:sequence"),
|
||||
("reason", "Some reason"),
|
||||
("__end__", "reasons:sequence"),
|
||||
("__start__", "rules:sequence"),
|
||||
("__end__", "rules:sequence"),
|
||||
("mandatory", "False"),
|
||||
("__end__", "reviewer:mapping"),
|
||||
("__end__", "review_members:sequence"),
|
||||
("__start__", "revisions:sequence"),
|
||||
("revisions", commit_ids["change"]),
|
||||
("revisions",),
|
||||
("__end__", "revisions:sequence"),
|
||||
("user", ""),
|
||||
("csrf_token", csrf_token),
|
||||
],
|
||||
status=302,
|
||||
]
|
||||
)
|
||||
|
||||
location = response.headers["Location"]
|
||||
pull_request_id, _ = self._create_pr_and_initial_validation(pr_post_for_params, source)
|
||||
|
||||
pull_request_id = location.rsplit("/", 1)[1]
|
||||
assert pull_request_id != "new"
|
||||
pull_request = PullRequest.get(int(pull_request_id))
|
||||
pull_request = PullRequest.get(pull_request_id)
|
||||
|
||||
# Check that a notification was made
|
||||
notifications = Notification.query().filter(
|
||||
|
|
@ -1023,43 +1026,20 @@ class TestPullrequestsView(object):
|
|||
commit_ids = backend.create_master_repo(commits)
|
||||
target = backend.create_repo(heads=["ancestor-child"])
|
||||
source = backend.create_repo(heads=["change"])
|
||||
|
||||
response = self.app.post(
|
||||
route_path("pullrequest_create", repo_name=source.repo_name),
|
||||
pr_post_for_params = self._get_pr_create_post_form_params(
|
||||
csrf_token, source, target, revisions=[commit_ids["change"]]
|
||||
)
|
||||
pr_post_for_params.extend(
|
||||
[
|
||||
("source_repo", source.repo_name),
|
||||
("source_ref", "branch:default:" + commit_ids["change"]),
|
||||
("target_repo", target.repo_name),
|
||||
("target_ref", "branch:default:" + commit_ids["ancestor-child"]),
|
||||
("common_ancestor", commit_ids["ancestor"]),
|
||||
("pullrequest_title", "Title"),
|
||||
("pullrequest_desc", "Description"),
|
||||
("description_renderer", "markdown"),
|
||||
("__start__", "review_members:sequence"),
|
||||
("__start__", "reviewer:mapping"),
|
||||
("user_id", "1"),
|
||||
("__start__", "reasons:sequence"),
|
||||
("reason", "Some reason"),
|
||||
("__end__", "reasons:sequence"),
|
||||
("__start__", "rules:sequence"),
|
||||
("__end__", "rules:sequence"),
|
||||
("mandatory", "False"),
|
||||
("__end__", "reviewer:mapping"),
|
||||
("__end__", "review_members:sequence"),
|
||||
("__start__", "revisions:sequence"),
|
||||
("revisions", commit_ids["change"]),
|
||||
("__end__", "revisions:sequence"),
|
||||
("user", ""),
|
||||
("csrf_token", csrf_token),
|
||||
],
|
||||
status=302,
|
||||
]
|
||||
)
|
||||
|
||||
location = response.headers["Location"]
|
||||
pull_request_id, response = self._create_pr_and_initial_validation(pr_post_for_params, source)
|
||||
|
||||
pull_request_id = location.rsplit("/", 1)[1]
|
||||
assert pull_request_id != "new"
|
||||
pull_request = PullRequest.get(int(pull_request_id))
|
||||
pull_request = PullRequest.get(pull_request_id)
|
||||
|
||||
# target_ref has to point to the ancestor's commit_id in order to
|
||||
# show the correct diff
|
||||
|
|
@ -1153,7 +1133,7 @@ class TestPullrequestsView(object):
|
|||
mods = [
|
||||
(
|
||||
"_pre_push_hook",
|
||||
f"""
|
||||
"""
|
||||
return HookResponse(1, 'HOOK_TEST_FORBIDDEN')
|
||||
""",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue