Show More
@@ -1,689 +1,691 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import mock |
|
21 | import mock | |
22 | import pytest |
|
22 | import pytest | |
23 |
|
23 | |||
24 | from rhodecode.lib.vcs.backends.base import EmptyCommit |
|
24 | from rhodecode.lib.vcs.backends.base import EmptyCommit | |
25 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError |
|
25 | from rhodecode.lib.vcs.exceptions import RepositoryRequirementError | |
26 | from rhodecode.model.db import Repository |
|
26 | from rhodecode.model.db import Repository | |
27 | from rhodecode.model.scm import ScmModel |
|
27 | from rhodecode.model.scm import ScmModel | |
28 | from rhodecode.tests import url, TEST_USER_ADMIN_LOGIN, assert_session_flash |
|
28 | from rhodecode.tests import url, TEST_USER_ADMIN_LOGIN, assert_session_flash | |
29 | from rhodecode.tests.utils import AssertResponse |
|
29 | from rhodecode.tests.utils import AssertResponse | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | @pytest.mark.usefixtures("autologin_user", "app") |
|
32 | @pytest.mark.usefixtures("autologin_user", "app") | |
33 | class TestCompareController: |
|
33 | class TestCompareController: | |
34 |
|
34 | |||
35 |
@pytest.mark.xfail_backends("svn", " |
|
35 | @pytest.mark.xfail_backends("svn", reason="Requires pull") | |
36 | def test_compare_remote_with_different_commit_indexes(self, backend): |
|
36 | def test_compare_remote_with_different_commit_indexes(self, backend): | |
37 | # Preparing the following repository structure: |
|
37 | # Preparing the following repository structure: | |
38 | # |
|
38 | # | |
39 | # Origin repository has two commits: |
|
39 | # Origin repository has two commits: | |
40 | # |
|
40 | # | |
41 | # 0 1 |
|
41 | # 0 1 | |
42 | # A -- D |
|
42 | # A -- D | |
43 | # |
|
43 | # | |
44 | # The fork of it has a few more commits and "D" has a commit index |
|
44 | # The fork of it has a few more commits and "D" has a commit index | |
45 | # which does not exist in origin. |
|
45 | # which does not exist in origin. | |
46 | # |
|
46 | # | |
47 | # 0 1 2 3 4 |
|
47 | # 0 1 2 3 4 | |
48 | # A -- -- -- D -- E |
|
48 | # A -- -- -- D -- E | |
49 | # \- B -- C |
|
49 | # \- B -- C | |
50 | # |
|
50 | # | |
51 |
|
51 | |||
52 | fork = backend.create_repo() |
|
52 | fork = backend.create_repo() | |
53 |
|
53 | |||
54 | # prepare fork |
|
54 | # prepare fork | |
55 | commit0 = _commit_change( |
|
55 | commit0 = _commit_change( | |
56 | fork.repo_name, filename='file1', content='A', |
|
56 | fork.repo_name, filename='file1', content='A', | |
57 | message='A', vcs_type=backend.alias, parent=None, newfile=True) |
|
57 | message='A', vcs_type=backend.alias, parent=None, newfile=True) | |
58 |
|
58 | |||
59 | commit1 = _commit_change( |
|
59 | commit1 = _commit_change( | |
60 | fork.repo_name, filename='file1', content='B', |
|
60 | fork.repo_name, filename='file1', content='B', | |
61 | message='B, child of A', vcs_type=backend.alias, parent=commit0) |
|
61 | message='B, child of A', vcs_type=backend.alias, parent=commit0) | |
62 |
|
62 | |||
63 | _commit_change( # commit 2 |
|
63 | _commit_change( # commit 2 | |
64 | fork.repo_name, filename='file1', content='C', |
|
64 | fork.repo_name, filename='file1', content='C', | |
65 | message='C, child of B', vcs_type=backend.alias, parent=commit1) |
|
65 | message='C, child of B', vcs_type=backend.alias, parent=commit1) | |
66 |
|
66 | |||
67 | commit3 = _commit_change( |
|
67 | commit3 = _commit_change( | |
68 | fork.repo_name, filename='file1', content='D', |
|
68 | fork.repo_name, filename='file1', content='D', | |
69 | message='D, child of A', vcs_type=backend.alias, parent=commit0) |
|
69 | message='D, child of A', vcs_type=backend.alias, parent=commit0) | |
70 |
|
70 | |||
71 | commit4 = _commit_change( |
|
71 | commit4 = _commit_change( | |
72 | fork.repo_name, filename='file1', content='E', |
|
72 | fork.repo_name, filename='file1', content='E', | |
73 | message='E, child of D', vcs_type=backend.alias, parent=commit3) |
|
73 | message='E, child of D', vcs_type=backend.alias, parent=commit3) | |
74 |
|
74 | |||
75 | # prepare origin repository, taking just the history up to D |
|
75 | # prepare origin repository, taking just the history up to D | |
76 | origin = backend.create_repo() |
|
76 | origin = backend.create_repo() | |
77 |
|
77 | |||
78 | origin_repo = origin.scm_instance(cache=False) |
|
78 | origin_repo = origin.scm_instance(cache=False) | |
79 | origin_repo.config.clear_section('hooks') |
|
79 | origin_repo.config.clear_section('hooks') | |
80 | origin_repo.pull(fork.repo_full_path, commit_ids=[commit3.raw_id]) |
|
80 | origin_repo.pull(fork.repo_full_path, commit_ids=[commit3.raw_id]) | |
81 |
|
81 | |||
82 | # Verify test fixture setup |
|
82 | # Verify test fixture setup | |
|
83 | # This does not work for git | |||
|
84 | if backend.alias != 'git': | |||
83 | assert 5 == len(fork.scm_instance().commit_ids) |
|
85 | assert 5 == len(fork.scm_instance().commit_ids) | |
84 | assert 2 == len(origin_repo.commit_ids) |
|
86 | assert 2 == len(origin_repo.commit_ids) | |
85 |
|
87 | |||
86 | # Comparing the revisions |
|
88 | # Comparing the revisions | |
87 | response = self.app.get( |
|
89 | response = self.app.get( | |
88 | url('compare_url', |
|
90 | url('compare_url', | |
89 | repo_name=origin.repo_name, |
|
91 | repo_name=origin.repo_name, | |
90 | source_ref_type="rev", |
|
92 | source_ref_type="rev", | |
91 | source_ref=commit3.raw_id, |
|
93 | source_ref=commit3.raw_id, | |
92 | target_repo=fork.repo_name, |
|
94 | target_repo=fork.repo_name, | |
93 | target_ref_type="rev", |
|
95 | target_ref_type="rev", | |
94 | target_ref=commit4.raw_id, |
|
96 | target_ref=commit4.raw_id, | |
95 | merge='1',)) |
|
97 | merge='1',)) | |
96 |
|
98 | |||
97 | compare_page = ComparePage(response) |
|
99 | compare_page = ComparePage(response) | |
98 | compare_page.contains_commits([commit4]) |
|
100 | compare_page.contains_commits([commit4]) | |
99 |
|
101 | |||
100 | @pytest.mark.xfail_backends("svn", reason="Depends on branch support") |
|
102 | @pytest.mark.xfail_backends("svn", reason="Depends on branch support") | |
101 | def test_compare_forks_on_branch_extra_commits(self, backend): |
|
103 | def test_compare_forks_on_branch_extra_commits(self, backend): | |
102 | repo1 = backend.create_repo() |
|
104 | repo1 = backend.create_repo() | |
103 |
|
105 | |||
104 | # commit something ! |
|
106 | # commit something ! | |
105 | commit0 = _commit_change( |
|
107 | commit0 = _commit_change( | |
106 | repo1.repo_name, filename='file1', content='line1\n', |
|
108 | repo1.repo_name, filename='file1', content='line1\n', | |
107 | message='commit1', vcs_type=backend.alias, parent=None, |
|
109 | message='commit1', vcs_type=backend.alias, parent=None, | |
108 | newfile=True) |
|
110 | newfile=True) | |
109 |
|
111 | |||
110 | # fork this repo |
|
112 | # fork this repo | |
111 | repo2 = backend.create_fork() |
|
113 | repo2 = backend.create_fork() | |
112 |
|
114 | |||
113 | # add two extra commit into fork |
|
115 | # add two extra commit into fork | |
114 | commit1 = _commit_change( |
|
116 | commit1 = _commit_change( | |
115 | repo2.repo_name, filename='file1', content='line1\nline2\n', |
|
117 | repo2.repo_name, filename='file1', content='line1\nline2\n', | |
116 | message='commit2', vcs_type=backend.alias, parent=commit0) |
|
118 | message='commit2', vcs_type=backend.alias, parent=commit0) | |
117 |
|
119 | |||
118 | commit2 = _commit_change( |
|
120 | commit2 = _commit_change( | |
119 | repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
121 | repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', | |
120 | message='commit3', vcs_type=backend.alias, parent=commit1) |
|
122 | message='commit3', vcs_type=backend.alias, parent=commit1) | |
121 |
|
123 | |||
122 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME |
|
124 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME | |
123 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME |
|
125 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME | |
124 |
|
126 | |||
125 | response = self.app.get( |
|
127 | response = self.app.get( | |
126 | url('compare_url', |
|
128 | url('compare_url', | |
127 | repo_name=repo1.repo_name, |
|
129 | repo_name=repo1.repo_name, | |
128 | source_ref_type="branch", |
|
130 | source_ref_type="branch", | |
129 | source_ref=commit_id2, |
|
131 | source_ref=commit_id2, | |
130 | target_repo=repo2.repo_name, |
|
132 | target_repo=repo2.repo_name, | |
131 | target_ref_type="branch", |
|
133 | target_ref_type="branch", | |
132 | target_ref=commit_id1, |
|
134 | target_ref=commit_id1, | |
133 | merge='1',)) |
|
135 | merge='1',)) | |
134 |
|
136 | |||
135 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2)) |
|
137 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2)) | |
136 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1)) |
|
138 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1)) | |
137 |
|
139 | |||
138 | compare_page = ComparePage(response) |
|
140 | compare_page = ComparePage(response) | |
139 | compare_page.contains_change_summary(1, 2, 0) |
|
141 | compare_page.contains_change_summary(1, 2, 0) | |
140 | compare_page.contains_commits([commit1, commit2]) |
|
142 | compare_page.contains_commits([commit1, commit2]) | |
141 | compare_page.contains_file_links_and_anchors([ |
|
143 | compare_page.contains_file_links_and_anchors([ | |
142 | ('file1', 'a_c--826e8142e6ba'), |
|
144 | ('file1', 'a_c--826e8142e6ba'), | |
143 | ]) |
|
145 | ]) | |
144 |
|
146 | |||
145 | # Swap is removed when comparing branches since it's a PR feature and |
|
147 | # Swap is removed when comparing branches since it's a PR feature and | |
146 | # it is then a preview mode |
|
148 | # it is then a preview mode | |
147 | compare_page.swap_is_hidden() |
|
149 | compare_page.swap_is_hidden() | |
148 | compare_page.target_source_are_disabled() |
|
150 | compare_page.target_source_are_disabled() | |
149 |
|
151 | |||
150 | @pytest.mark.xfail_backends("svn", reason="Depends on branch support") |
|
152 | @pytest.mark.xfail_backends("svn", reason="Depends on branch support") | |
151 | def test_compare_forks_on_branch_extra_commits_origin_has_incomming( |
|
153 | def test_compare_forks_on_branch_extra_commits_origin_has_incomming( | |
152 | self, backend): |
|
154 | self, backend): | |
153 | repo1 = backend.create_repo() |
|
155 | repo1 = backend.create_repo() | |
154 |
|
156 | |||
155 | # commit something ! |
|
157 | # commit something ! | |
156 | commit0 = _commit_change( |
|
158 | commit0 = _commit_change( | |
157 | repo1.repo_name, filename='file1', content='line1\n', |
|
159 | repo1.repo_name, filename='file1', content='line1\n', | |
158 | message='commit1', vcs_type=backend.alias, parent=None, |
|
160 | message='commit1', vcs_type=backend.alias, parent=None, | |
159 | newfile=True) |
|
161 | newfile=True) | |
160 |
|
162 | |||
161 | # fork this repo |
|
163 | # fork this repo | |
162 | repo2 = backend.create_fork() |
|
164 | repo2 = backend.create_fork() | |
163 |
|
165 | |||
164 | # now commit something to origin repo |
|
166 | # now commit something to origin repo | |
165 | _commit_change( |
|
167 | _commit_change( | |
166 | repo1.repo_name, filename='file2', content='line1file2\n', |
|
168 | repo1.repo_name, filename='file2', content='line1file2\n', | |
167 | message='commit2', vcs_type=backend.alias, parent=commit0, |
|
169 | message='commit2', vcs_type=backend.alias, parent=commit0, | |
168 | newfile=True) |
|
170 | newfile=True) | |
169 |
|
171 | |||
170 | # add two extra commit into fork |
|
172 | # add two extra commit into fork | |
171 | commit1 = _commit_change( |
|
173 | commit1 = _commit_change( | |
172 | repo2.repo_name, filename='file1', content='line1\nline2\n', |
|
174 | repo2.repo_name, filename='file1', content='line1\nline2\n', | |
173 | message='commit2', vcs_type=backend.alias, parent=commit0) |
|
175 | message='commit2', vcs_type=backend.alias, parent=commit0) | |
174 |
|
176 | |||
175 | commit2 = _commit_change( |
|
177 | commit2 = _commit_change( | |
176 | repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
178 | repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', | |
177 | message='commit3', vcs_type=backend.alias, parent=commit1) |
|
179 | message='commit3', vcs_type=backend.alias, parent=commit1) | |
178 |
|
180 | |||
179 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME |
|
181 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME | |
180 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME |
|
182 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME | |
181 |
|
183 | |||
182 | response = self.app.get( |
|
184 | response = self.app.get( | |
183 | url('compare_url', |
|
185 | url('compare_url', | |
184 | repo_name=repo1.repo_name, |
|
186 | repo_name=repo1.repo_name, | |
185 | source_ref_type="branch", |
|
187 | source_ref_type="branch", | |
186 | source_ref=commit_id2, |
|
188 | source_ref=commit_id2, | |
187 | target_repo=repo2.repo_name, |
|
189 | target_repo=repo2.repo_name, | |
188 | target_ref_type="branch", |
|
190 | target_ref_type="branch", | |
189 | target_ref=commit_id1, |
|
191 | target_ref=commit_id1, | |
190 | merge='1')) |
|
192 | merge='1')) | |
191 |
|
193 | |||
192 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2)) |
|
194 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2)) | |
193 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1)) |
|
195 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1)) | |
194 |
|
196 | |||
195 | compare_page = ComparePage(response) |
|
197 | compare_page = ComparePage(response) | |
196 | compare_page.contains_change_summary(1, 2, 0) |
|
198 | compare_page.contains_change_summary(1, 2, 0) | |
197 | compare_page.contains_commits([commit1, commit2]) |
|
199 | compare_page.contains_commits([commit1, commit2]) | |
198 | compare_page.contains_file_links_and_anchors([ |
|
200 | compare_page.contains_file_links_and_anchors([ | |
199 | ('file1', 'a_c--826e8142e6ba'), |
|
201 | ('file1', 'a_c--826e8142e6ba'), | |
200 | ]) |
|
202 | ]) | |
201 |
|
203 | |||
202 | # Swap is removed when comparing branches since it's a PR feature and |
|
204 | # Swap is removed when comparing branches since it's a PR feature and | |
203 | # it is then a preview mode |
|
205 | # it is then a preview mode | |
204 | compare_page.swap_is_hidden() |
|
206 | compare_page.swap_is_hidden() | |
205 | compare_page.target_source_are_disabled() |
|
207 | compare_page.target_source_are_disabled() | |
206 |
|
208 | |||
207 | @pytest.mark.xfail_backends("svn", "git") |
|
209 | @pytest.mark.xfail_backends("svn", "git") | |
208 | def test_compare_of_unrelated_forks(self, backend): |
|
210 | def test_compare_of_unrelated_forks(self, backend): | |
209 | # TODO: johbo: Fails for git due to some other issue it seems |
|
211 | # TODO: johbo: Fails for git due to some other issue it seems | |
210 | orig = backend.create_repo(number_of_commits=1) |
|
212 | orig = backend.create_repo(number_of_commits=1) | |
211 | fork = backend.create_repo(number_of_commits=1) |
|
213 | fork = backend.create_repo(number_of_commits=1) | |
212 |
|
214 | |||
213 | response = self.app.get( |
|
215 | response = self.app.get( | |
214 | url('compare_url', |
|
216 | url('compare_url', | |
215 | repo_name=orig.repo_name, |
|
217 | repo_name=orig.repo_name, | |
216 | action="compare", |
|
218 | action="compare", | |
217 | source_ref_type="rev", |
|
219 | source_ref_type="rev", | |
218 | source_ref="tip", |
|
220 | source_ref="tip", | |
219 | target_ref_type="rev", |
|
221 | target_ref_type="rev", | |
220 | target_ref="tip", |
|
222 | target_ref="tip", | |
221 | merge='1', |
|
223 | merge='1', | |
222 | target_repo=fork.repo_name), |
|
224 | target_repo=fork.repo_name), | |
223 | status=400) |
|
225 | status=400) | |
224 |
|
226 | |||
225 | response.mustcontain("Repositories unrelated.") |
|
227 | response.mustcontain("Repositories unrelated.") | |
226 |
|
228 | |||
227 | @pytest.mark.xfail_backends("svn", "git") |
|
229 | @pytest.mark.xfail_backends("svn", "git") | |
228 | def test_compare_cherry_pick_commits_from_bottom(self, backend): |
|
230 | def test_compare_cherry_pick_commits_from_bottom(self, backend): | |
229 |
|
231 | |||
230 | # repo1: |
|
232 | # repo1: | |
231 | # commit0: |
|
233 | # commit0: | |
232 | # commit1: |
|
234 | # commit1: | |
233 | # repo1-fork- in which we will cherry pick bottom commits |
|
235 | # repo1-fork- in which we will cherry pick bottom commits | |
234 | # commit0: |
|
236 | # commit0: | |
235 | # commit1: |
|
237 | # commit1: | |
236 | # commit2: x |
|
238 | # commit2: x | |
237 | # commit3: x |
|
239 | # commit3: x | |
238 | # commit4: x |
|
240 | # commit4: x | |
239 | # commit5: |
|
241 | # commit5: | |
240 | # make repo1, and commit1+commit2 |
|
242 | # make repo1, and commit1+commit2 | |
241 |
|
243 | |||
242 | repo1 = backend.create_repo() |
|
244 | repo1 = backend.create_repo() | |
243 |
|
245 | |||
244 | # commit something ! |
|
246 | # commit something ! | |
245 | commit0 = _commit_change( |
|
247 | commit0 = _commit_change( | |
246 | repo1.repo_name, filename='file1', content='line1\n', |
|
248 | repo1.repo_name, filename='file1', content='line1\n', | |
247 | message='commit1', vcs_type=backend.alias, parent=None, |
|
249 | message='commit1', vcs_type=backend.alias, parent=None, | |
248 | newfile=True) |
|
250 | newfile=True) | |
249 | commit1 = _commit_change( |
|
251 | commit1 = _commit_change( | |
250 | repo1.repo_name, filename='file1', content='line1\nline2\n', |
|
252 | repo1.repo_name, filename='file1', content='line1\nline2\n', | |
251 | message='commit2', vcs_type=backend.alias, parent=commit0) |
|
253 | message='commit2', vcs_type=backend.alias, parent=commit0) | |
252 |
|
254 | |||
253 | # fork this repo |
|
255 | # fork this repo | |
254 | repo2 = backend.create_fork() |
|
256 | repo2 = backend.create_fork() | |
255 |
|
257 | |||
256 | # now make commit3-6 |
|
258 | # now make commit3-6 | |
257 | commit2 = _commit_change( |
|
259 | commit2 = _commit_change( | |
258 | repo1.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
260 | repo1.repo_name, filename='file1', content='line1\nline2\nline3\n', | |
259 | message='commit3', vcs_type=backend.alias, parent=commit1) |
|
261 | message='commit3', vcs_type=backend.alias, parent=commit1) | |
260 | commit3 = _commit_change( |
|
262 | commit3 = _commit_change( | |
261 | repo1.repo_name, filename='file1', |
|
263 | repo1.repo_name, filename='file1', | |
262 | content='line1\nline2\nline3\nline4\n', message='commit4', |
|
264 | content='line1\nline2\nline3\nline4\n', message='commit4', | |
263 | vcs_type=backend.alias, parent=commit2) |
|
265 | vcs_type=backend.alias, parent=commit2) | |
264 | commit4 = _commit_change( |
|
266 | commit4 = _commit_change( | |
265 | repo1.repo_name, filename='file1', |
|
267 | repo1.repo_name, filename='file1', | |
266 | content='line1\nline2\nline3\nline4\nline5\n', message='commit5', |
|
268 | content='line1\nline2\nline3\nline4\nline5\n', message='commit5', | |
267 | vcs_type=backend.alias, parent=commit3) |
|
269 | vcs_type=backend.alias, parent=commit3) | |
268 | _commit_change( # commit 5 |
|
270 | _commit_change( # commit 5 | |
269 | repo1.repo_name, filename='file1', |
|
271 | repo1.repo_name, filename='file1', | |
270 | content='line1\nline2\nline3\nline4\nline5\nline6\n', |
|
272 | content='line1\nline2\nline3\nline4\nline5\nline6\n', | |
271 | message='commit6', vcs_type=backend.alias, parent=commit4) |
|
273 | message='commit6', vcs_type=backend.alias, parent=commit4) | |
272 |
|
274 | |||
273 | response = self.app.get( |
|
275 | response = self.app.get( | |
274 | url('compare_url', |
|
276 | url('compare_url', | |
275 | repo_name=repo2.repo_name, |
|
277 | repo_name=repo2.repo_name, | |
276 | source_ref_type="rev", |
|
278 | source_ref_type="rev", | |
277 | # parent of commit2, in target repo2 |
|
279 | # parent of commit2, in target repo2 | |
278 | source_ref=commit1.short_id, |
|
280 | source_ref=commit1.short_id, | |
279 | target_repo=repo1.repo_name, |
|
281 | target_repo=repo1.repo_name, | |
280 | target_ref_type="rev", |
|
282 | target_ref_type="rev", | |
281 | target_ref=commit4.short_id, |
|
283 | target_ref=commit4.short_id, | |
282 | merge='1',)) |
|
284 | merge='1',)) | |
283 | response.mustcontain('%s@%s' % (repo2.repo_name, commit1.short_id)) |
|
285 | response.mustcontain('%s@%s' % (repo2.repo_name, commit1.short_id)) | |
284 | response.mustcontain('%s@%s' % (repo1.repo_name, commit4.short_id)) |
|
286 | response.mustcontain('%s@%s' % (repo1.repo_name, commit4.short_id)) | |
285 |
|
287 | |||
286 | # files |
|
288 | # files | |
287 | compare_page = ComparePage(response) |
|
289 | compare_page = ComparePage(response) | |
288 | compare_page.contains_change_summary(1, 3, 0) |
|
290 | compare_page.contains_change_summary(1, 3, 0) | |
289 | compare_page.contains_commits([commit2, commit3, commit4]) |
|
291 | compare_page.contains_commits([commit2, commit3, commit4]) | |
290 | compare_page.contains_file_links_and_anchors([ |
|
292 | compare_page.contains_file_links_and_anchors([ | |
291 | ('file1', 'a_c--826e8142e6ba'), |
|
293 | ('file1', 'a_c--826e8142e6ba'), | |
292 | ]) |
|
294 | ]) | |
293 |
|
295 | |||
294 | @pytest.mark.xfail_backends("svn", "git") |
|
296 | @pytest.mark.xfail_backends("svn", "git") | |
295 | def test_compare_cherry_pick_commits_from_top(self, backend): |
|
297 | def test_compare_cherry_pick_commits_from_top(self, backend): | |
296 | # repo1: |
|
298 | # repo1: | |
297 | # commit0: |
|
299 | # commit0: | |
298 | # commit1: |
|
300 | # commit1: | |
299 | # repo1-fork- in which we will cherry pick bottom commits |
|
301 | # repo1-fork- in which we will cherry pick bottom commits | |
300 | # commit0: |
|
302 | # commit0: | |
301 | # commit1: |
|
303 | # commit1: | |
302 | # commit2: |
|
304 | # commit2: | |
303 | # commit3: x |
|
305 | # commit3: x | |
304 | # commit4: x |
|
306 | # commit4: x | |
305 | # commit5: x |
|
307 | # commit5: x | |
306 |
|
308 | |||
307 | # make repo1, and commit1+commit2 |
|
309 | # make repo1, and commit1+commit2 | |
308 | repo1 = backend.create_repo() |
|
310 | repo1 = backend.create_repo() | |
309 |
|
311 | |||
310 | # commit something ! |
|
312 | # commit something ! | |
311 | commit0 = _commit_change( |
|
313 | commit0 = _commit_change( | |
312 | repo1.repo_name, filename='file1', content='line1\n', |
|
314 | repo1.repo_name, filename='file1', content='line1\n', | |
313 | message='commit1', vcs_type=backend.alias, parent=None, |
|
315 | message='commit1', vcs_type=backend.alias, parent=None, | |
314 | newfile=True) |
|
316 | newfile=True) | |
315 | commit1 = _commit_change( |
|
317 | commit1 = _commit_change( | |
316 | repo1.repo_name, filename='file1', content='line1\nline2\n', |
|
318 | repo1.repo_name, filename='file1', content='line1\nline2\n', | |
317 | message='commit2', vcs_type=backend.alias, parent=commit0) |
|
319 | message='commit2', vcs_type=backend.alias, parent=commit0) | |
318 |
|
320 | |||
319 | # fork this repo |
|
321 | # fork this repo | |
320 | backend.create_fork() |
|
322 | backend.create_fork() | |
321 |
|
323 | |||
322 | # now make commit3-6 |
|
324 | # now make commit3-6 | |
323 | commit2 = _commit_change( |
|
325 | commit2 = _commit_change( | |
324 | repo1.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
326 | repo1.repo_name, filename='file1', content='line1\nline2\nline3\n', | |
325 | message='commit3', vcs_type=backend.alias, parent=commit1) |
|
327 | message='commit3', vcs_type=backend.alias, parent=commit1) | |
326 | commit3 = _commit_change( |
|
328 | commit3 = _commit_change( | |
327 | repo1.repo_name, filename='file1', |
|
329 | repo1.repo_name, filename='file1', | |
328 | content='line1\nline2\nline3\nline4\n', message='commit4', |
|
330 | content='line1\nline2\nline3\nline4\n', message='commit4', | |
329 | vcs_type=backend.alias, parent=commit2) |
|
331 | vcs_type=backend.alias, parent=commit2) | |
330 | commit4 = _commit_change( |
|
332 | commit4 = _commit_change( | |
331 | repo1.repo_name, filename='file1', |
|
333 | repo1.repo_name, filename='file1', | |
332 | content='line1\nline2\nline3\nline4\nline5\n', message='commit5', |
|
334 | content='line1\nline2\nline3\nline4\nline5\n', message='commit5', | |
333 | vcs_type=backend.alias, parent=commit3) |
|
335 | vcs_type=backend.alias, parent=commit3) | |
334 | commit5 = _commit_change( |
|
336 | commit5 = _commit_change( | |
335 | repo1.repo_name, filename='file1', |
|
337 | repo1.repo_name, filename='file1', | |
336 | content='line1\nline2\nline3\nline4\nline5\nline6\n', |
|
338 | content='line1\nline2\nline3\nline4\nline5\nline6\n', | |
337 | message='commit6', vcs_type=backend.alias, parent=commit4) |
|
339 | message='commit6', vcs_type=backend.alias, parent=commit4) | |
338 |
|
340 | |||
339 | response = self.app.get( |
|
341 | response = self.app.get( | |
340 | url('compare_url', |
|
342 | url('compare_url', | |
341 | repo_name=repo1.repo_name, |
|
343 | repo_name=repo1.repo_name, | |
342 | source_ref_type="rev", |
|
344 | source_ref_type="rev", | |
343 | # parent of commit3, not in source repo2 |
|
345 | # parent of commit3, not in source repo2 | |
344 | source_ref=commit2.short_id, |
|
346 | source_ref=commit2.short_id, | |
345 | target_ref_type="rev", |
|
347 | target_ref_type="rev", | |
346 | target_ref=commit5.short_id, |
|
348 | target_ref=commit5.short_id, | |
347 | merge='1',)) |
|
349 | merge='1',)) | |
348 |
|
350 | |||
349 | response.mustcontain('%s@%s' % (repo1.repo_name, commit2.short_id)) |
|
351 | response.mustcontain('%s@%s' % (repo1.repo_name, commit2.short_id)) | |
350 | response.mustcontain('%s@%s' % (repo1.repo_name, commit5.short_id)) |
|
352 | response.mustcontain('%s@%s' % (repo1.repo_name, commit5.short_id)) | |
351 |
|
353 | |||
352 | compare_page = ComparePage(response) |
|
354 | compare_page = ComparePage(response) | |
353 | compare_page.contains_change_summary(1, 3, 0) |
|
355 | compare_page.contains_change_summary(1, 3, 0) | |
354 | compare_page.contains_commits([commit3, commit4, commit5]) |
|
356 | compare_page.contains_commits([commit3, commit4, commit5]) | |
355 |
|
357 | |||
356 | # files |
|
358 | # files | |
357 | compare_page.contains_file_links_and_anchors([ |
|
359 | compare_page.contains_file_links_and_anchors([ | |
358 | ('file1', 'a_c--826e8142e6ba'), |
|
360 | ('file1', 'a_c--826e8142e6ba'), | |
359 | ]) |
|
361 | ]) | |
360 |
|
362 | |||
361 | @pytest.mark.xfail_backends("svn") |
|
363 | @pytest.mark.xfail_backends("svn") | |
362 | def test_compare_remote_branches(self, backend): |
|
364 | def test_compare_remote_branches(self, backend): | |
363 | repo1 = backend.repo |
|
365 | repo1 = backend.repo | |
364 | repo2 = backend.create_fork() |
|
366 | repo2 = backend.create_fork() | |
365 |
|
367 | |||
366 | commit_id1 = repo1.get_commit(commit_idx=3).raw_id |
|
368 | commit_id1 = repo1.get_commit(commit_idx=3).raw_id | |
367 | commit_id2 = repo1.get_commit(commit_idx=6).raw_id |
|
369 | commit_id2 = repo1.get_commit(commit_idx=6).raw_id | |
368 |
|
370 | |||
369 | response = self.app.get( |
|
371 | response = self.app.get( | |
370 | url('compare_url', |
|
372 | url('compare_url', | |
371 | repo_name=repo1.repo_name, |
|
373 | repo_name=repo1.repo_name, | |
372 | source_ref_type="rev", |
|
374 | source_ref_type="rev", | |
373 | source_ref=commit_id1, |
|
375 | source_ref=commit_id1, | |
374 | target_ref_type="rev", |
|
376 | target_ref_type="rev", | |
375 | target_ref=commit_id2, |
|
377 | target_ref=commit_id2, | |
376 | target_repo=repo2.repo_name, |
|
378 | target_repo=repo2.repo_name, | |
377 | merge='1',)) |
|
379 | merge='1',)) | |
378 |
|
380 | |||
379 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id1)) |
|
381 | response.mustcontain('%s@%s' % (repo1.repo_name, commit_id1)) | |
380 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id2)) |
|
382 | response.mustcontain('%s@%s' % (repo2.repo_name, commit_id2)) | |
381 |
|
383 | |||
382 | compare_page = ComparePage(response) |
|
384 | compare_page = ComparePage(response) | |
383 |
|
385 | |||
384 | # outgoing commits between those commits |
|
386 | # outgoing commits between those commits | |
385 | compare_page.contains_commits( |
|
387 | compare_page.contains_commits( | |
386 | [repo2.get_commit(commit_idx=x) for x in [4, 5, 6]]) |
|
388 | [repo2.get_commit(commit_idx=x) for x in [4, 5, 6]]) | |
387 |
|
389 | |||
388 | # files |
|
390 | # files | |
389 | compare_page.contains_file_links_and_anchors([ |
|
391 | compare_page.contains_file_links_and_anchors([ | |
390 | ('vcs/backends/hg.py', 'a_c--9c390eb52cd6'), |
|
392 | ('vcs/backends/hg.py', 'a_c--9c390eb52cd6'), | |
391 | ('vcs/backends/__init__.py', 'a_c--41b41c1f2796'), |
|
393 | ('vcs/backends/__init__.py', 'a_c--41b41c1f2796'), | |
392 | ('vcs/backends/base.py', 'a_c--2f574d260608'), |
|
394 | ('vcs/backends/base.py', 'a_c--2f574d260608'), | |
393 | ]) |
|
395 | ]) | |
394 |
|
396 | |||
395 | @pytest.mark.xfail_backends("svn") |
|
397 | @pytest.mark.xfail_backends("svn") | |
396 | def test_source_repo_new_commits_after_forking_simple_diff(self, backend): |
|
398 | def test_source_repo_new_commits_after_forking_simple_diff(self, backend): | |
397 | repo1 = backend.create_repo() |
|
399 | repo1 = backend.create_repo() | |
398 | r1_name = repo1.repo_name |
|
400 | r1_name = repo1.repo_name | |
399 |
|
401 | |||
400 | commit0 = _commit_change( |
|
402 | commit0 = _commit_change( | |
401 | repo=r1_name, filename='file1', |
|
403 | repo=r1_name, filename='file1', | |
402 | content='line1', message='commit1', vcs_type=backend.alias, |
|
404 | content='line1', message='commit1', vcs_type=backend.alias, | |
403 | newfile=True) |
|
405 | newfile=True) | |
404 | assert repo1.scm_instance().commit_ids == [commit0.raw_id] |
|
406 | assert repo1.scm_instance().commit_ids == [commit0.raw_id] | |
405 |
|
407 | |||
406 | # fork the repo1 |
|
408 | # fork the repo1 | |
407 | repo2 = backend.create_fork() |
|
409 | repo2 = backend.create_fork() | |
408 | assert repo2.scm_instance().commit_ids == [commit0.raw_id] |
|
410 | assert repo2.scm_instance().commit_ids == [commit0.raw_id] | |
409 |
|
411 | |||
410 | self.r2_id = repo2.repo_id |
|
412 | self.r2_id = repo2.repo_id | |
411 | r2_name = repo2.repo_name |
|
413 | r2_name = repo2.repo_name | |
412 |
|
414 | |||
413 | commit1 = _commit_change( |
|
415 | commit1 = _commit_change( | |
414 | repo=r2_name, filename='file1-fork', |
|
416 | repo=r2_name, filename='file1-fork', | |
415 | content='file1-line1-from-fork', message='commit1-fork', |
|
417 | content='file1-line1-from-fork', message='commit1-fork', | |
416 | vcs_type=backend.alias, parent=repo2.scm_instance()[-1], |
|
418 | vcs_type=backend.alias, parent=repo2.scm_instance()[-1], | |
417 | newfile=True) |
|
419 | newfile=True) | |
418 |
|
420 | |||
419 | commit2 = _commit_change( |
|
421 | commit2 = _commit_change( | |
420 | repo=r2_name, filename='file2-fork', |
|
422 | repo=r2_name, filename='file2-fork', | |
421 | content='file2-line1-from-fork', message='commit2-fork', |
|
423 | content='file2-line1-from-fork', message='commit2-fork', | |
422 | vcs_type=backend.alias, parent=commit1, |
|
424 | vcs_type=backend.alias, parent=commit1, | |
423 | newfile=True) |
|
425 | newfile=True) | |
424 |
|
426 | |||
425 | _commit_change( # commit 3 |
|
427 | _commit_change( # commit 3 | |
426 | repo=r2_name, filename='file3-fork', |
|
428 | repo=r2_name, filename='file3-fork', | |
427 | content='file3-line1-from-fork', message='commit3-fork', |
|
429 | content='file3-line1-from-fork', message='commit3-fork', | |
428 | vcs_type=backend.alias, parent=commit2, newfile=True) |
|
430 | vcs_type=backend.alias, parent=commit2, newfile=True) | |
429 |
|
431 | |||
430 | # compare ! |
|
432 | # compare ! | |
431 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME |
|
433 | commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME | |
432 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME |
|
434 | commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME | |
433 |
|
435 | |||
434 | response = self.app.get( |
|
436 | response = self.app.get( | |
435 | url('compare_url', |
|
437 | url('compare_url', | |
436 | repo_name=r2_name, |
|
438 | repo_name=r2_name, | |
437 | source_ref_type="branch", |
|
439 | source_ref_type="branch", | |
438 | source_ref=commit_id1, |
|
440 | source_ref=commit_id1, | |
439 | target_ref_type="branch", |
|
441 | target_ref_type="branch", | |
440 | target_ref=commit_id2, |
|
442 | target_ref=commit_id2, | |
441 | target_repo=r1_name, |
|
443 | target_repo=r1_name, | |
442 | merge='1',)) |
|
444 | merge='1',)) | |
443 |
|
445 | |||
444 | response.mustcontain('%s@%s' % (r2_name, commit_id1)) |
|
446 | response.mustcontain('%s@%s' % (r2_name, commit_id1)) | |
445 | response.mustcontain('%s@%s' % (r1_name, commit_id2)) |
|
447 | response.mustcontain('%s@%s' % (r1_name, commit_id2)) | |
446 | response.mustcontain('No files') |
|
448 | response.mustcontain('No files') | |
447 | response.mustcontain('No Commits') |
|
449 | response.mustcontain('No Commits') | |
448 |
|
450 | |||
449 | commit0 = _commit_change( |
|
451 | commit0 = _commit_change( | |
450 | repo=r1_name, filename='file2', |
|
452 | repo=r1_name, filename='file2', | |
451 | content='line1-added-after-fork', message='commit2-parent', |
|
453 | content='line1-added-after-fork', message='commit2-parent', | |
452 | vcs_type=backend.alias, parent=None, newfile=True) |
|
454 | vcs_type=backend.alias, parent=None, newfile=True) | |
453 |
|
455 | |||
454 | # compare ! |
|
456 | # compare ! | |
455 | response = self.app.get( |
|
457 | response = self.app.get( | |
456 | url('compare_url', |
|
458 | url('compare_url', | |
457 | repo_name=r2_name, |
|
459 | repo_name=r2_name, | |
458 | source_ref_type="branch", |
|
460 | source_ref_type="branch", | |
459 | source_ref=commit_id1, |
|
461 | source_ref=commit_id1, | |
460 | target_ref_type="branch", |
|
462 | target_ref_type="branch", | |
461 | target_ref=commit_id2, |
|
463 | target_ref=commit_id2, | |
462 | target_repo=r1_name, |
|
464 | target_repo=r1_name, | |
463 | merge='1',)) |
|
465 | merge='1',)) | |
464 |
|
466 | |||
465 | response.mustcontain('%s@%s' % (r2_name, commit_id1)) |
|
467 | response.mustcontain('%s@%s' % (r2_name, commit_id1)) | |
466 | response.mustcontain('%s@%s' % (r1_name, commit_id2)) |
|
468 | response.mustcontain('%s@%s' % (r1_name, commit_id2)) | |
467 |
|
469 | |||
468 | response.mustcontain("""commit2-parent""") |
|
470 | response.mustcontain("""commit2-parent""") | |
469 | response.mustcontain("""line1-added-after-fork""") |
|
471 | response.mustcontain("""line1-added-after-fork""") | |
470 | compare_page = ComparePage(response) |
|
472 | compare_page = ComparePage(response) | |
471 | compare_page.contains_change_summary(1, 1, 0) |
|
473 | compare_page.contains_change_summary(1, 1, 0) | |
472 |
|
474 | |||
473 | @pytest.mark.xfail_backends("svn") |
|
475 | @pytest.mark.xfail_backends("svn") | |
474 | def test_compare_commits(self, backend): |
|
476 | def test_compare_commits(self, backend): | |
475 | commit0 = backend.repo.get_commit(commit_idx=0) |
|
477 | commit0 = backend.repo.get_commit(commit_idx=0) | |
476 | commit1 = backend.repo.get_commit(commit_idx=1) |
|
478 | commit1 = backend.repo.get_commit(commit_idx=1) | |
477 |
|
479 | |||
478 | response = self.app.get( |
|
480 | response = self.app.get( | |
479 | url('compare_url', |
|
481 | url('compare_url', | |
480 | repo_name=backend.repo_name, |
|
482 | repo_name=backend.repo_name, | |
481 | source_ref_type="rev", |
|
483 | source_ref_type="rev", | |
482 | source_ref=commit0.raw_id, |
|
484 | source_ref=commit0.raw_id, | |
483 | target_ref_type="rev", |
|
485 | target_ref_type="rev", | |
484 | target_ref=commit1.raw_id, |
|
486 | target_ref=commit1.raw_id, | |
485 | merge='1',), |
|
487 | merge='1',), | |
486 | extra_environ={'HTTP_X_PARTIAL_XHR': '1'},) |
|
488 | extra_environ={'HTTP_X_PARTIAL_XHR': '1'},) | |
487 |
|
489 | |||
488 | # outgoing commits between those commits |
|
490 | # outgoing commits between those commits | |
489 | compare_page = ComparePage(response) |
|
491 | compare_page = ComparePage(response) | |
490 | compare_page.contains_commits(commits=[commit1], ancestors=[commit0]) |
|
492 | compare_page.contains_commits(commits=[commit1], ancestors=[commit0]) | |
491 |
|
493 | |||
492 | def test_errors_when_comparing_unknown_repo(self, backend): |
|
494 | def test_errors_when_comparing_unknown_repo(self, backend): | |
493 | repo = backend.repo |
|
495 | repo = backend.repo | |
494 | badrepo = 'badrepo' |
|
496 | badrepo = 'badrepo' | |
495 |
|
497 | |||
496 | response = self.app.get( |
|
498 | response = self.app.get( | |
497 | url('compare_url', |
|
499 | url('compare_url', | |
498 | repo_name=repo.repo_name, |
|
500 | repo_name=repo.repo_name, | |
499 | source_ref_type="rev", |
|
501 | source_ref_type="rev", | |
500 | source_ref='tip', |
|
502 | source_ref='tip', | |
501 | target_ref_type="rev", |
|
503 | target_ref_type="rev", | |
502 | target_ref='tip', |
|
504 | target_ref='tip', | |
503 | target_repo=badrepo, |
|
505 | target_repo=badrepo, | |
504 | merge='1',), |
|
506 | merge='1',), | |
505 | status=302) |
|
507 | status=302) | |
506 | redirected = response.follow() |
|
508 | redirected = response.follow() | |
507 | redirected.mustcontain('Could not find the other repo: %s' % badrepo) |
|
509 | redirected.mustcontain('Could not find the other repo: %s' % badrepo) | |
508 |
|
510 | |||
509 | def test_compare_not_in_preview_mode(self, backend_stub): |
|
511 | def test_compare_not_in_preview_mode(self, backend_stub): | |
510 | commit0 = backend_stub.repo.get_commit(commit_idx=0) |
|
512 | commit0 = backend_stub.repo.get_commit(commit_idx=0) | |
511 | commit1 = backend_stub.repo.get_commit(commit_idx=1) |
|
513 | commit1 = backend_stub.repo.get_commit(commit_idx=1) | |
512 |
|
514 | |||
513 | response = self.app.get(url('compare_url', |
|
515 | response = self.app.get(url('compare_url', | |
514 | repo_name=backend_stub.repo_name, |
|
516 | repo_name=backend_stub.repo_name, | |
515 | source_ref_type="rev", |
|
517 | source_ref_type="rev", | |
516 | source_ref=commit0.raw_id, |
|
518 | source_ref=commit0.raw_id, | |
517 | target_ref_type="rev", |
|
519 | target_ref_type="rev", | |
518 | target_ref=commit1.raw_id, |
|
520 | target_ref=commit1.raw_id, | |
519 | ),) |
|
521 | ),) | |
520 |
|
522 | |||
521 | # outgoing commits between those commits |
|
523 | # outgoing commits between those commits | |
522 | compare_page = ComparePage(response) |
|
524 | compare_page = ComparePage(response) | |
523 | compare_page.swap_is_visible() |
|
525 | compare_page.swap_is_visible() | |
524 | compare_page.target_source_are_enabled() |
|
526 | compare_page.target_source_are_enabled() | |
525 |
|
527 | |||
526 | def test_compare_of_fork_with_largefiles(self, backend_hg, settings_util): |
|
528 | def test_compare_of_fork_with_largefiles(self, backend_hg, settings_util): | |
527 | orig = backend_hg.create_repo(number_of_commits=1) |
|
529 | orig = backend_hg.create_repo(number_of_commits=1) | |
528 | fork = backend_hg.create_fork() |
|
530 | fork = backend_hg.create_fork() | |
529 |
|
531 | |||
530 | settings_util.create_repo_rhodecode_ui( |
|
532 | settings_util.create_repo_rhodecode_ui( | |
531 | orig, 'extensions', value='', key='largefiles', active=False) |
|
533 | orig, 'extensions', value='', key='largefiles', active=False) | |
532 | settings_util.create_repo_rhodecode_ui( |
|
534 | settings_util.create_repo_rhodecode_ui( | |
533 | fork, 'extensions', value='', key='largefiles', active=True) |
|
535 | fork, 'extensions', value='', key='largefiles', active=True) | |
534 |
|
536 | |||
535 | compare_module = ('rhodecode.lib.vcs.backends.hg.repository.' |
|
537 | compare_module = ('rhodecode.lib.vcs.backends.hg.repository.' | |
536 | 'MercurialRepository.compare') |
|
538 | 'MercurialRepository.compare') | |
537 | with mock.patch(compare_module) as compare_mock: |
|
539 | with mock.patch(compare_module) as compare_mock: | |
538 | compare_mock.side_effect = RepositoryRequirementError() |
|
540 | compare_mock.side_effect = RepositoryRequirementError() | |
539 |
|
541 | |||
540 | response = self.app.get( |
|
542 | response = self.app.get( | |
541 | url('compare_url', |
|
543 | url('compare_url', | |
542 | repo_name=orig.repo_name, |
|
544 | repo_name=orig.repo_name, | |
543 | action="compare", |
|
545 | action="compare", | |
544 | source_ref_type="rev", |
|
546 | source_ref_type="rev", | |
545 | source_ref="tip", |
|
547 | source_ref="tip", | |
546 | target_ref_type="rev", |
|
548 | target_ref_type="rev", | |
547 | target_ref="tip", |
|
549 | target_ref="tip", | |
548 | merge='1', |
|
550 | merge='1', | |
549 | target_repo=fork.repo_name), |
|
551 | target_repo=fork.repo_name), | |
550 | status=302) |
|
552 | status=302) | |
551 |
|
553 | |||
552 | assert_session_flash( |
|
554 | assert_session_flash( | |
553 | response, |
|
555 | response, | |
554 | 'Could not compare repos with different large file settings') |
|
556 | 'Could not compare repos with different large file settings') | |
555 |
|
557 | |||
556 |
|
558 | |||
557 | @pytest.mark.usefixtures("autologin_user") |
|
559 | @pytest.mark.usefixtures("autologin_user") | |
558 | class TestCompareControllerSvn: |
|
560 | class TestCompareControllerSvn: | |
559 |
|
561 | |||
560 | def test_supports_references_with_path(self, app, backend_svn): |
|
562 | def test_supports_references_with_path(self, app, backend_svn): | |
561 | repo = backend_svn['svn-simple-layout'] |
|
563 | repo = backend_svn['svn-simple-layout'] | |
562 | commit_id = repo.get_commit(commit_idx=-1).raw_id |
|
564 | commit_id = repo.get_commit(commit_idx=-1).raw_id | |
563 | response = app.get( |
|
565 | response = app.get( | |
564 | url('compare_url', |
|
566 | url('compare_url', | |
565 | repo_name=repo.repo_name, |
|
567 | repo_name=repo.repo_name, | |
566 | source_ref_type="tag", |
|
568 | source_ref_type="tag", | |
567 | source_ref="%s@%s" % ('tags/v0.1', commit_id), |
|
569 | source_ref="%s@%s" % ('tags/v0.1', commit_id), | |
568 | target_ref_type="tag", |
|
570 | target_ref_type="tag", | |
569 | target_ref="%s@%s" % ('tags/v0.2', commit_id), |
|
571 | target_ref="%s@%s" % ('tags/v0.2', commit_id), | |
570 | merge='1',), |
|
572 | merge='1',), | |
571 | status=200) |
|
573 | status=200) | |
572 |
|
574 | |||
573 | # Expecting no commits, since both paths are at the same revision |
|
575 | # Expecting no commits, since both paths are at the same revision | |
574 | response.mustcontain('No Commits') |
|
576 | response.mustcontain('No Commits') | |
575 |
|
577 | |||
576 | # Should find only one file changed when comparing those two tags |
|
578 | # Should find only one file changed when comparing those two tags | |
577 | response.mustcontain('example.py') |
|
579 | response.mustcontain('example.py') | |
578 | compare_page = ComparePage(response) |
|
580 | compare_page = ComparePage(response) | |
579 | compare_page.contains_change_summary(1, 5, 1) |
|
581 | compare_page.contains_change_summary(1, 5, 1) | |
580 |
|
582 | |||
581 | def test_shows_commits_if_different_ids(self, app, backend_svn): |
|
583 | def test_shows_commits_if_different_ids(self, app, backend_svn): | |
582 | repo = backend_svn['svn-simple-layout'] |
|
584 | repo = backend_svn['svn-simple-layout'] | |
583 | source_id = repo.get_commit(commit_idx=-6).raw_id |
|
585 | source_id = repo.get_commit(commit_idx=-6).raw_id | |
584 | target_id = repo.get_commit(commit_idx=-1).raw_id |
|
586 | target_id = repo.get_commit(commit_idx=-1).raw_id | |
585 | response = app.get( |
|
587 | response = app.get( | |
586 | url('compare_url', |
|
588 | url('compare_url', | |
587 | repo_name=repo.repo_name, |
|
589 | repo_name=repo.repo_name, | |
588 | source_ref_type="tag", |
|
590 | source_ref_type="tag", | |
589 | source_ref="%s@%s" % ('tags/v0.1', source_id), |
|
591 | source_ref="%s@%s" % ('tags/v0.1', source_id), | |
590 | target_ref_type="tag", |
|
592 | target_ref_type="tag", | |
591 | target_ref="%s@%s" % ('tags/v0.2', target_id), |
|
593 | target_ref="%s@%s" % ('tags/v0.2', target_id), | |
592 | merge='1',), |
|
594 | merge='1',), | |
593 | status=200) |
|
595 | status=200) | |
594 |
|
596 | |||
595 | # It should show commits |
|
597 | # It should show commits | |
596 | assert 'No Commits' not in response.body |
|
598 | assert 'No Commits' not in response.body | |
597 |
|
599 | |||
598 | # Should find only one file changed when comparing those two tags |
|
600 | # Should find only one file changed when comparing those two tags | |
599 | response.mustcontain('example.py') |
|
601 | response.mustcontain('example.py') | |
600 | compare_page = ComparePage(response) |
|
602 | compare_page = ComparePage(response) | |
601 | compare_page.contains_change_summary(1, 5, 1) |
|
603 | compare_page.contains_change_summary(1, 5, 1) | |
602 |
|
604 | |||
603 |
|
605 | |||
604 | class ComparePage(AssertResponse): |
|
606 | class ComparePage(AssertResponse): | |
605 | """ |
|
607 | """ | |
606 | Abstracts the page template from the tests |
|
608 | Abstracts the page template from the tests | |
607 | """ |
|
609 | """ | |
608 |
|
610 | |||
609 | def contains_file_links_and_anchors(self, files): |
|
611 | def contains_file_links_and_anchors(self, files): | |
610 | for filename, file_id in files: |
|
612 | for filename, file_id in files: | |
611 | self.contains_one_link(filename, '#' + file_id) |
|
613 | self.contains_one_link(filename, '#' + file_id) | |
612 | self.contains_one_anchor(file_id) |
|
614 | self.contains_one_anchor(file_id) | |
613 |
|
615 | |||
614 | def contains_change_summary(self, files_changed, inserted, deleted): |
|
616 | def contains_change_summary(self, files_changed, inserted, deleted): | |
615 | template = ( |
|
617 | template = ( | |
616 | "{files_changed} file{plural} changed: " |
|
618 | "{files_changed} file{plural} changed: " | |
617 | "{inserted} inserted, {deleted} deleted") |
|
619 | "{inserted} inserted, {deleted} deleted") | |
618 | self.response.mustcontain(template.format( |
|
620 | self.response.mustcontain(template.format( | |
619 | files_changed=files_changed, |
|
621 | files_changed=files_changed, | |
620 | plural="s" if files_changed > 1 else "", |
|
622 | plural="s" if files_changed > 1 else "", | |
621 | inserted=inserted, |
|
623 | inserted=inserted, | |
622 | deleted=deleted)) |
|
624 | deleted=deleted)) | |
623 |
|
625 | |||
624 | def contains_commits(self, commits, ancestors=None): |
|
626 | def contains_commits(self, commits, ancestors=None): | |
625 | response = self.response |
|
627 | response = self.response | |
626 |
|
628 | |||
627 | for commit in commits: |
|
629 | for commit in commits: | |
628 | # Expecting to see the commit message in an element which |
|
630 | # Expecting to see the commit message in an element which | |
629 | # has the ID "c-{commit.raw_id}" |
|
631 | # has the ID "c-{commit.raw_id}" | |
630 | self.element_contains('#c-' + commit.raw_id, commit.message) |
|
632 | self.element_contains('#c-' + commit.raw_id, commit.message) | |
631 | self.contains_one_link( |
|
633 | self.contains_one_link( | |
632 | 'r%s:%s' % (commit.idx, commit.short_id), |
|
634 | 'r%s:%s' % (commit.idx, commit.short_id), | |
633 | self._commit_url(commit)) |
|
635 | self._commit_url(commit)) | |
634 | if ancestors: |
|
636 | if ancestors: | |
635 | response.mustcontain('Ancestor') |
|
637 | response.mustcontain('Ancestor') | |
636 | for ancestor in ancestors: |
|
638 | for ancestor in ancestors: | |
637 | self.contains_one_link( |
|
639 | self.contains_one_link( | |
638 | ancestor.short_id, self._commit_url(ancestor)) |
|
640 | ancestor.short_id, self._commit_url(ancestor)) | |
639 |
|
641 | |||
640 | def _commit_url(self, commit): |
|
642 | def _commit_url(self, commit): | |
641 | return '/%s/changeset/%s' % (commit.repository.name, commit.raw_id) |
|
643 | return '/%s/changeset/%s' % (commit.repository.name, commit.raw_id) | |
642 |
|
644 | |||
643 | def swap_is_hidden(self): |
|
645 | def swap_is_hidden(self): | |
644 | assert '<a id="btn-swap"' not in self.response.text |
|
646 | assert '<a id="btn-swap"' not in self.response.text | |
645 |
|
647 | |||
646 | def swap_is_visible(self): |
|
648 | def swap_is_visible(self): | |
647 | assert '<a id="btn-swap"' in self.response.text |
|
649 | assert '<a id="btn-swap"' in self.response.text | |
648 |
|
650 | |||
649 | def target_source_are_disabled(self): |
|
651 | def target_source_are_disabled(self): | |
650 | response = self.response |
|
652 | response = self.response | |
651 | response.mustcontain("var enable_fields = false;") |
|
653 | response.mustcontain("var enable_fields = false;") | |
652 | response.mustcontain('.select2("enable", enable_fields)') |
|
654 | response.mustcontain('.select2("enable", enable_fields)') | |
653 |
|
655 | |||
654 | def target_source_are_enabled(self): |
|
656 | def target_source_are_enabled(self): | |
655 | response = self.response |
|
657 | response = self.response | |
656 | response.mustcontain("var enable_fields = true;") |
|
658 | response.mustcontain("var enable_fields = true;") | |
657 |
|
659 | |||
658 |
|
660 | |||
659 | def _commit_change( |
|
661 | def _commit_change( | |
660 | repo, filename, content, message, vcs_type, parent=None, |
|
662 | repo, filename, content, message, vcs_type, parent=None, | |
661 | newfile=False): |
|
663 | newfile=False): | |
662 | repo = Repository.get_by_repo_name(repo) |
|
664 | repo = Repository.get_by_repo_name(repo) | |
663 | _commit = parent |
|
665 | _commit = parent | |
664 | if not parent: |
|
666 | if not parent: | |
665 | _commit = EmptyCommit(alias=vcs_type) |
|
667 | _commit = EmptyCommit(alias=vcs_type) | |
666 |
|
668 | |||
667 | if newfile: |
|
669 | if newfile: | |
668 | nodes = { |
|
670 | nodes = { | |
669 | filename: { |
|
671 | filename: { | |
670 | 'content': content |
|
672 | 'content': content | |
671 | } |
|
673 | } | |
672 | } |
|
674 | } | |
673 | commit = ScmModel().create_nodes( |
|
675 | commit = ScmModel().create_nodes( | |
674 | user=TEST_USER_ADMIN_LOGIN, repo=repo, |
|
676 | user=TEST_USER_ADMIN_LOGIN, repo=repo, | |
675 | message=message, |
|
677 | message=message, | |
676 | nodes=nodes, |
|
678 | nodes=nodes, | |
677 | parent_commit=_commit, |
|
679 | parent_commit=_commit, | |
678 | author=TEST_USER_ADMIN_LOGIN, |
|
680 | author=TEST_USER_ADMIN_LOGIN, | |
679 | ) |
|
681 | ) | |
680 | else: |
|
682 | else: | |
681 | commit = ScmModel().commit_change( |
|
683 | commit = ScmModel().commit_change( | |
682 | repo=repo.scm_instance(), repo_name=repo.repo_name, |
|
684 | repo=repo.scm_instance(), repo_name=repo.repo_name, | |
683 | commit=parent, user=TEST_USER_ADMIN_LOGIN, |
|
685 | commit=parent, user=TEST_USER_ADMIN_LOGIN, | |
684 | author=TEST_USER_ADMIN_LOGIN, |
|
686 | author=TEST_USER_ADMIN_LOGIN, | |
685 | message=message, |
|
687 | message=message, | |
686 | content=content, |
|
688 | content=content, | |
687 | f_path=filename |
|
689 | f_path=filename | |
688 | ) |
|
690 | ) | |
689 | return commit |
|
691 | return commit |
General Comments 0
You need to be logged in to leave comments.
Login now