##// END OF EJS Templates
test: fixes for tests for PR versions.
marcink -
r1373:0a5c49a9 default
parent child Browse files
Show More
@@ -24,7 +24,8 b' from rhodecode.lib.vcs.nodes import File'
24 from rhodecode.model.db import User
24 from rhodecode.model.db import User
25 from rhodecode.model.pull_request import PullRequestModel
25 from rhodecode.model.pull_request import PullRequestModel
26 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
26 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
27 from rhodecode.api.tests.utils import (build_data, api_call)
27 from rhodecode.api.tests.utils import (
28 build_data, api_call, assert_ok, assert_error)
28
29
29
30
30 @pytest.mark.usefixtures("testuser_api", "app")
31 @pytest.mark.usefixtures("testuser_api", "app")
@@ -74,8 +75,7 b' class TestUpdatePullRequest(object):'
74 expected = 'pull request `{}` update failed, pull request ' \
75 expected = 'pull request `{}` update failed, pull request ' \
75 'is closed'.format(pull_request.pull_request_id)
76 'is closed'.format(pull_request.pull_request_id)
76
77
77 response_json = response.json['error']
78 assert_error(id_, expected, response.body)
78 assert response_json == expected
79
79
80 @pytest.mark.backends("git", "hg")
80 @pytest.mark.backends("git", "hg")
81 def test_api_update_update_commits(
81 def test_api_update_update_commits(
@@ -90,9 +90,11 b' class TestUpdatePullRequest(object):'
90 pr_util.update_source_repository(head='c')
90 pr_util.update_source_repository(head='c')
91 repo = pull_request.source_repo.scm_instance()
91 repo = pull_request.source_repo.scm_instance()
92 commits = [x for x in repo.get_commits()]
92 commits = [x for x in repo.get_commits()]
93 print commits
93
94
94 added_commit_id = commits[-1].raw_id # c commit
95 added_commit_id = commits[-1].raw_id # c commit
95 common_commits = commits[1].raw_id # b commit is common ancestor
96 common_commit_id = commits[1].raw_id # b commit is common ancestor
97 total_commits = [added_commit_id, common_commit_id]
96
98
97 id_, params = build_data(
99 id_, params = build_data(
98 self.apikey, 'update_pull_request',
100 self.apikey, 'update_pull_request',
@@ -107,12 +109,13 b' class TestUpdatePullRequest(object):'
107 pull_request.pull_request_id),
109 pull_request.pull_request_id),
108 "pull_request": response.json['result']['pull_request'],
110 "pull_request": response.json['result']['pull_request'],
109 "updated_commits": {"added": [added_commit_id],
111 "updated_commits": {"added": [added_commit_id],
110 "common": [common_commits], "removed": []},
112 "common": [common_commit_id],
113 "total": total_commits,
114 "removed": []},
111 "updated_reviewers": {"added": [], "removed": []},
115 "updated_reviewers": {"added": [], "removed": []},
112 }
116 }
113
117
114 response_json = response.json['result']
118 assert_ok(id_, expected, response.body)
115 assert response_json == expected
116
119
117 @pytest.mark.backends("git", "hg")
120 @pytest.mark.backends("git", "hg")
118 def test_api_update_change_reviewers(
121 def test_api_update_change_reviewers(
@@ -139,8 +142,7 b' class TestUpdatePullRequest(object):'
139 "updated_reviewers": {"added": added, "removed": removed},
142 "updated_reviewers": {"added": added, "removed": removed},
140 }
143 }
141
144
142 response_json = response.json['result']
145 assert_ok(id_, expected, response.body)
143 assert response_json == expected
144
146
145 @pytest.mark.backends("git", "hg")
147 @pytest.mark.backends("git", "hg")
146 def test_api_update_bad_user_in_reviewers(self, pr_util):
148 def test_api_update_bad_user_in_reviewers(self, pr_util):
@@ -155,8 +157,7 b' class TestUpdatePullRequest(object):'
155
157
156 expected = 'user `bad_name` does not exist'
158 expected = 'user `bad_name` does not exist'
157
159
158 response_json = response.json['error']
160 assert_error(id_, expected, response.body)
159 assert response_json == expected
160
161
161 @pytest.mark.backends("git", "hg")
162 @pytest.mark.backends("git", "hg")
162 def test_api_update_repo_error(self, pr_util):
163 def test_api_update_repo_error(self, pr_util):
@@ -184,9 +185,7 b' class TestUpdatePullRequest(object):'
184 response = api_call(self.app, params)
185 response = api_call(self.app, params)
185
186
186 expected = 'pull request `999999` does not exist'
187 expected = 'pull request `999999` does not exist'
187
188 assert_error(id_, expected, response.body)
188 response_json = response.json['error']
189 assert response_json == expected
190
189
191 @pytest.mark.backends("git", "hg")
190 @pytest.mark.backends("git", "hg")
192 def test_api_update_pull_request_no_perms_to_update(
191 def test_api_update_pull_request_no_perms_to_update(
@@ -203,5 +202,4 b' class TestUpdatePullRequest(object):'
203 expected = ('pull request `%s` update failed, '
202 expected = ('pull request `%s` update failed, '
204 'no permission to update.') % pull_request.pull_request_id
203 'no permission to update.') % pull_request.pull_request_id
205
204
206 response_json = response.json['error']
205 assert_error(id_, expected, response.body)
207 assert response_json == expected
@@ -356,8 +356,11 b' class TestPullRequestModel:'
356 assert commit_ids == pull_request.revisions + [pull_request.merge_rev]
356 assert commit_ids == pull_request.revisions + [pull_request.merge_rev]
357
357
358 def test_get_diff_from_pr_version(self, pull_request):
358 def test_get_diff_from_pr_version(self, pull_request):
359 source_repo = pull_request.source_repo
360 source_ref_id = pull_request.source_ref_parts.commit_id
361 target_ref_id = pull_request.target_ref_parts.commit_id
359 diff = PullRequestModel()._get_diff_from_pr_or_version(
362 diff = PullRequestModel()._get_diff_from_pr_or_version(
360 pull_request, context=6)
363 source_repo, source_ref_id, target_ref_id, context=6)
361 assert 'file_1' in diff.raw
364 assert 'file_1' in diff.raw
362
365
363 def test_generate_title_returns_unicode(self):
366 def test_generate_title_returns_unicode(self):
@@ -803,10 +806,13 b' def test_link_comments_to_version_only_u'
803
806
804
807
805 def test_calculate_commits():
808 def test_calculate_commits():
806 change = PullRequestModel()._calculate_commit_id_changes(
809 old_ids = [1, 2, 3]
807 set([1, 2, 3]), set([1, 3, 4, 5]))
810 new_ids = [1, 3, 4, 5]
808 assert (set([4, 5]), set([1, 3]), set([2])) == (
811 change = PullRequestModel()._calculate_commit_id_changes(old_ids, new_ids)
809 change.added, change.common, change.removed)
812 assert change.added == [4, 5]
813 assert change.common == [1, 3]
814 assert change.removed == [2]
815 assert change.total == [1, 3, 4, 5]
810
816
811
817
812 def assert_inline_comments(pull_request, visible=None, outdated=None):
818 def assert_inline_comments(pull_request, visible=None, outdated=None):
@@ -55,8 +55,11 b' class TestGetDiffForPrOrVersion(object):'
55 return pull_request
55 return pull_request
56
56
57 def assert_diff_can_be_fetched(self, pr_or_version):
57 def assert_diff_can_be_fetched(self, pr_or_version):
58 source_repo = pr_or_version.source_repo
59 source_ref_id = pr_or_version.source_ref_parts.commit_id
60 target_ref_id = pr_or_version.target_ref_parts.commit_id
58 diff = PullRequestModel()._get_diff_from_pr_or_version(
61 diff = PullRequestModel()._get_diff_from_pr_or_version(
59 pr_or_version, context=6)
62 source_repo, source_ref_id, target_ref_id, context=6)
60 assert 'file_b' in diff.raw
63 assert 'file_b' in diff.raw
61
64
62 def assert_commit_cannot_be_accessed(
65 def assert_commit_cannot_be_accessed(
General Comments 0
You need to be logged in to leave comments. Login now