test: fixes for tests for PR versions.
This commit is contained in:
parent
5e35e36e4f
commit
23ff2e2325
3 changed files with 29 additions and 22 deletions
|
|
@ -24,7 +24,8 @@ from rhodecode.lib.vcs.nodes import FileNode
|
|||
from rhodecode.model.db import User
|
||||
from rhodecode.model.pull_request import PullRequestModel
|
||||
from rhodecode.tests import TEST_USER_ADMIN_LOGIN
|
||||
from rhodecode.api.tests.utils import (build_data, api_call)
|
||||
from rhodecode.api.tests.utils import (
|
||||
build_data, api_call, assert_ok, assert_error)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("testuser_api", "app")
|
||||
|
|
@ -74,8 +75,7 @@ class TestUpdatePullRequest(object):
|
|||
expected = 'pull request `{}` update failed, pull request ' \
|
||||
'is closed'.format(pull_request.pull_request_id)
|
||||
|
||||
response_json = response.json['error']
|
||||
assert response_json == expected
|
||||
assert_error(id_, expected, response.body)
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_update_update_commits(
|
||||
|
|
@ -90,9 +90,11 @@ class TestUpdatePullRequest(object):
|
|||
pr_util.update_source_repository(head='c')
|
||||
repo = pull_request.source_repo.scm_instance()
|
||||
commits = [x for x in repo.get_commits()]
|
||||
print commits
|
||||
|
||||
added_commit_id = commits[-1].raw_id # c commit
|
||||
common_commits = commits[1].raw_id # b commit is common ancestor
|
||||
common_commit_id = commits[1].raw_id # b commit is common ancestor
|
||||
total_commits = [added_commit_id, common_commit_id]
|
||||
|
||||
id_, params = build_data(
|
||||
self.apikey, 'update_pull_request',
|
||||
|
|
@ -107,12 +109,13 @@ class TestUpdatePullRequest(object):
|
|||
pull_request.pull_request_id),
|
||||
"pull_request": response.json['result']['pull_request'],
|
||||
"updated_commits": {"added": [added_commit_id],
|
||||
"common": [common_commits], "removed": []},
|
||||
"common": [common_commit_id],
|
||||
"total": total_commits,
|
||||
"removed": []},
|
||||
"updated_reviewers": {"added": [], "removed": []},
|
||||
}
|
||||
|
||||
response_json = response.json['result']
|
||||
assert response_json == expected
|
||||
assert_ok(id_, expected, response.body)
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_update_change_reviewers(
|
||||
|
|
@ -139,8 +142,7 @@ class TestUpdatePullRequest(object):
|
|||
"updated_reviewers": {"added": added, "removed": removed},
|
||||
}
|
||||
|
||||
response_json = response.json['result']
|
||||
assert response_json == expected
|
||||
assert_ok(id_, expected, response.body)
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_update_bad_user_in_reviewers(self, pr_util):
|
||||
|
|
@ -155,8 +157,7 @@ class TestUpdatePullRequest(object):
|
|||
|
||||
expected = 'user `bad_name` does not exist'
|
||||
|
||||
response_json = response.json['error']
|
||||
assert response_json == expected
|
||||
assert_error(id_, expected, response.body)
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_update_repo_error(self, pr_util):
|
||||
|
|
@ -184,9 +185,7 @@ class TestUpdatePullRequest(object):
|
|||
response = api_call(self.app, params)
|
||||
|
||||
expected = 'pull request `999999` does not exist'
|
||||
|
||||
response_json = response.json['error']
|
||||
assert response_json == expected
|
||||
assert_error(id_, expected, response.body)
|
||||
|
||||
@pytest.mark.backends("git", "hg")
|
||||
def test_api_update_pull_request_no_perms_to_update(
|
||||
|
|
@ -203,5 +202,4 @@ class TestUpdatePullRequest(object):
|
|||
expected = ('pull request `%s` update failed, '
|
||||
'no permission to update.') % pull_request.pull_request_id
|
||||
|
||||
response_json = response.json['error']
|
||||
assert response_json == expected
|
||||
assert_error(id_, expected, response.body)
|
||||
|
|
|
|||
|
|
@ -356,8 +356,11 @@ class TestPullRequestModel:
|
|||
assert commit_ids == pull_request.revisions + [pull_request.merge_rev]
|
||||
|
||||
def test_get_diff_from_pr_version(self, pull_request):
|
||||
source_repo = pull_request.source_repo
|
||||
source_ref_id = pull_request.source_ref_parts.commit_id
|
||||
target_ref_id = pull_request.target_ref_parts.commit_id
|
||||
diff = PullRequestModel()._get_diff_from_pr_or_version(
|
||||
pull_request, context=6)
|
||||
source_repo, source_ref_id, target_ref_id, context=6)
|
||||
assert 'file_1' in diff.raw
|
||||
|
||||
def test_generate_title_returns_unicode(self):
|
||||
|
|
@ -803,10 +806,13 @@ def test_link_comments_to_version_only_updates_unlinked_comments(pr_util):
|
|||
|
||||
|
||||
def test_calculate_commits():
|
||||
change = PullRequestModel()._calculate_commit_id_changes(
|
||||
set([1, 2, 3]), set([1, 3, 4, 5]))
|
||||
assert (set([4, 5]), set([1, 3]), set([2])) == (
|
||||
change.added, change.common, change.removed)
|
||||
old_ids = [1, 2, 3]
|
||||
new_ids = [1, 3, 4, 5]
|
||||
change = PullRequestModel()._calculate_commit_id_changes(old_ids, new_ids)
|
||||
assert change.added == [4, 5]
|
||||
assert change.common == [1, 3]
|
||||
assert change.removed == [2]
|
||||
assert change.total == [1, 3, 4, 5]
|
||||
|
||||
|
||||
def assert_inline_comments(pull_request, visible=None, outdated=None):
|
||||
|
|
|
|||
|
|
@ -55,8 +55,11 @@ class TestGetDiffForPrOrVersion(object):
|
|||
return pull_request
|
||||
|
||||
def assert_diff_can_be_fetched(self, pr_or_version):
|
||||
source_repo = pr_or_version.source_repo
|
||||
source_ref_id = pr_or_version.source_ref_parts.commit_id
|
||||
target_ref_id = pr_or_version.target_ref_parts.commit_id
|
||||
diff = PullRequestModel()._get_diff_from_pr_or_version(
|
||||
pr_or_version, context=6)
|
||||
source_repo, source_ref_id, target_ref_id, context=6)
|
||||
assert 'file_b' in diff.raw
|
||||
|
||||
def assert_commit_cannot_be_accessed(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue