Show More
@@ -1,193 +1,192 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import re |
|
22 | 22 | |
|
23 | 23 | import pytest |
|
24 | 24 | |
|
25 | 25 | from rhodecode.controllers.changelog import DEFAULT_CHANGELOG_SIZE |
|
26 | 26 | from rhodecode.tests import url, TestController |
|
27 | 27 | from rhodecode.tests.utils import AssertResponse |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | MATCH_HASH = re.compile(r'<span class="commit_hash">r(\d+):[\da-f]+</span>') |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | class TestChangelogController(TestController): |
|
34 | 34 | |
|
35 | 35 | def test_index(self, backend): |
|
36 | 36 | self.log_user() |
|
37 | 37 | response = self.app.get(url(controller='changelog', action='index', |
|
38 | 38 | repo_name=backend.repo_name)) |
|
39 | 39 | |
|
40 | 40 | first_idx = -1 |
|
41 | 41 | last_idx = -DEFAULT_CHANGELOG_SIZE |
|
42 | 42 | self.assert_commit_range_on_page( |
|
43 | 43 | response, first_idx, last_idx, backend) |
|
44 | 44 | |
|
45 | 45 | @pytest.mark.backends("hg", "git") |
|
46 | 46 | def test_index_filtered_by_branch(self, backend): |
|
47 | 47 | self.log_user() |
|
48 | 48 | self.app.get( |
|
49 | 49 | url( |
|
50 | 50 | controller='changelog', |
|
51 | 51 | action='index', |
|
52 | 52 | repo_name=backend.repo_name, |
|
53 | 53 | branch=backend.default_branch_name), |
|
54 | 54 | status=200) |
|
55 | 55 | |
|
56 | 56 | @pytest.mark.backends("svn") |
|
57 | 57 | def test_index_filtered_by_branch_svn(self, autologin_user, backend): |
|
58 | 58 | repo = backend['svn-simple-layout'] |
|
59 | 59 | response = self.app.get( |
|
60 | 60 | url( |
|
61 | 61 | controller='changelog', |
|
62 | 62 | action='index', |
|
63 | 63 | repo_name=repo.repo_name, |
|
64 | 64 | branch='trunk'), |
|
65 | 65 | status=200) |
|
66 | 66 | |
|
67 | 67 | self.assert_commits_on_page( |
|
68 | 68 | response, indexes=[15, 12, 7, 3, 2, 1]) |
|
69 | 69 | |
|
70 | 70 | def test_index_filtered_by_wrong_branch(self, backend): |
|
71 | 71 | self.log_user() |
|
72 | 72 | branch = 'wrong-branch-name' |
|
73 | 73 | response = self.app.get( |
|
74 | 74 | url( |
|
75 | 75 | controller='changelog', |
|
76 | 76 | action='index', |
|
77 | 77 | repo_name=backend.repo_name, |
|
78 | 78 | branch=branch), |
|
79 | 79 | status=302) |
|
80 | 80 | expected_url = '/{repo}/changelog/{branch}'.format( |
|
81 | 81 | repo=backend.repo_name, branch=branch) |
|
82 | 82 | assert expected_url in response.location |
|
83 | 83 | response = response.follow() |
|
84 | 84 | expected_warning = 'Branch {} is not found.'.format(branch) |
|
85 | assert_response = AssertResponse(response) | |
|
86 | assert_response.element_contains('.alert-warning', expected_warning) | |
|
85 | assert expected_warning in response.body | |
|
87 | 86 | |
|
88 | 87 | def assert_commits_on_page(self, response, indexes): |
|
89 | 88 | found_indexes = [int(idx) for idx in MATCH_HASH.findall(response.body)] |
|
90 | 89 | assert found_indexes == indexes |
|
91 | 90 | |
|
92 | 91 | @pytest.mark.xfail_backends("svn", reason="Depends on branch support") |
|
93 | 92 | def test_index_filtered_by_branch_with_merges( |
|
94 | 93 | self, autologin_user, backend): |
|
95 | 94 | |
|
96 | 95 | # Note: The changelog of branch "b" does not contain the commit "a1" |
|
97 | 96 | # although this is a parent of commit "b1". And branch "b" has commits |
|
98 | 97 | # which have a smaller index than commit "a1". |
|
99 | 98 | commits = [ |
|
100 | 99 | {'message': 'a'}, |
|
101 | 100 | {'message': 'b', 'branch': 'b'}, |
|
102 | 101 | {'message': 'a1', 'parents': ['a']}, |
|
103 | 102 | {'message': 'b1', 'branch': 'b', 'parents': ['b', 'a1']}, |
|
104 | 103 | ] |
|
105 | 104 | backend.create_repo(commits) |
|
106 | 105 | |
|
107 | 106 | self.app.get( |
|
108 | 107 | url('changelog_home', |
|
109 | 108 | controller='changelog', |
|
110 | 109 | action='index', |
|
111 | 110 | repo_name=backend.repo_name, |
|
112 | 111 | branch='b'), |
|
113 | 112 | status=200) |
|
114 | 113 | |
|
115 | 114 | @pytest.mark.backends("hg") |
|
116 | 115 | def test_index_closed_branches(self, autologin_user, backend): |
|
117 | 116 | repo = backend['closed_branch'] |
|
118 | 117 | response = self.app.get( |
|
119 | 118 | url( |
|
120 | 119 | controller='changelog', |
|
121 | 120 | action='index', |
|
122 | 121 | repo_name=repo.repo_name, |
|
123 | 122 | branch='experimental'), |
|
124 | 123 | status=200) |
|
125 | 124 | |
|
126 | 125 | self.assert_commits_on_page( |
|
127 | 126 | response, indexes=[3, 1]) |
|
128 | 127 | |
|
129 | 128 | def test_index_pagination(self, backend): |
|
130 | 129 | self.log_user() |
|
131 | 130 | # pagination, walk up to page 6 |
|
132 | 131 | changelog_url = url( |
|
133 | 132 | controller='changelog', action='index', |
|
134 | 133 | repo_name=backend.repo_name) |
|
135 | 134 | for page in range(1, 7): |
|
136 | 135 | response = self.app.get(changelog_url, {'page': page}) |
|
137 | 136 | |
|
138 | 137 | first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1 |
|
139 | 138 | last_idx = -DEFAULT_CHANGELOG_SIZE * page |
|
140 | 139 | self.assert_commit_range_on_page(response, first_idx, last_idx, backend) |
|
141 | 140 | |
|
142 | 141 | def assert_commit_range_on_page( |
|
143 | 142 | self, response, first_idx, last_idx, backend): |
|
144 | 143 | input_template = ( |
|
145 | 144 | """<input class="commit-range" id="%(raw_id)s" """ |
|
146 | 145 | """name="%(raw_id)s" type="checkbox" value="1" />""" |
|
147 | 146 | ) |
|
148 | 147 | commit_span_template = """<span class="commit_hash">r%s:%s</span>""" |
|
149 | 148 | repo = backend.repo |
|
150 | 149 | |
|
151 | 150 | first_commit_on_page = repo.get_commit(commit_idx=first_idx) |
|
152 | 151 | response.mustcontain( |
|
153 | 152 | input_template % {'raw_id': first_commit_on_page.raw_id}) |
|
154 | 153 | response.mustcontain(commit_span_template % ( |
|
155 | 154 | first_commit_on_page.idx, first_commit_on_page.short_id) |
|
156 | 155 | ) |
|
157 | 156 | |
|
158 | 157 | last_commit_on_page = repo.get_commit(commit_idx=last_idx) |
|
159 | 158 | response.mustcontain( |
|
160 | 159 | input_template % {'raw_id': last_commit_on_page.raw_id}) |
|
161 | 160 | response.mustcontain(commit_span_template % ( |
|
162 | 161 | last_commit_on_page.idx, last_commit_on_page.short_id) |
|
163 | 162 | ) |
|
164 | 163 | |
|
165 | 164 | first_commit_of_next_page = repo.get_commit(commit_idx=last_idx - 1) |
|
166 | 165 | first_span_of_next_page = commit_span_template % ( |
|
167 | 166 | first_commit_of_next_page.idx, first_commit_of_next_page.short_id) |
|
168 | 167 | assert first_span_of_next_page not in response |
|
169 | 168 | |
|
170 | 169 | def test_index_with_filenode(self, backend): |
|
171 | 170 | self.log_user() |
|
172 | 171 | response = self.app.get(url( |
|
173 | 172 | controller='changelog', action='index', revision='tip', |
|
174 | 173 | f_path='/vcs/exceptions.py', repo_name=backend.repo_name)) |
|
175 | 174 | |
|
176 | 175 | # history commits messages |
|
177 | 176 | response.mustcontain('Added exceptions module, this time for real') |
|
178 | 177 | response.mustcontain('Added not implemented hg backend test case') |
|
179 | 178 | response.mustcontain('Added BaseChangeset class') |
|
180 | 179 | |
|
181 | 180 | def test_index_with_filenode_that_is_dirnode(self, backend): |
|
182 | 181 | self.log_user() |
|
183 | 182 | response = self.app.get(url(controller='changelog', action='index', |
|
184 | 183 | revision='tip', f_path='/tests', |
|
185 | 184 | repo_name=backend.repo_name)) |
|
186 | 185 | assert response.status == '302 Found' |
|
187 | 186 | |
|
188 | 187 | def test_index_with_filenode_not_existing(self, backend): |
|
189 | 188 | self.log_user() |
|
190 | 189 | response = self.app.get(url(controller='changelog', action='index', |
|
191 | 190 | revision='tip', f_path='/wrong_path', |
|
192 | 191 | repo_name=backend.repo_name)) |
|
193 | 192 | assert response.status == '302 Found' |
General Comments 0
You need to be logged in to leave comments.
Login now