##// END OF EJS Templates
tests: fixing changelog test for new notifications
lisaq -
r824:9a53b89b default
parent child Browse files
Show More
@@ -1,193 +1,192 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 re
21 import re
22
22
23 import pytest
23 import pytest
24
24
25 from rhodecode.controllers.changelog import DEFAULT_CHANGELOG_SIZE
25 from rhodecode.controllers.changelog import DEFAULT_CHANGELOG_SIZE
26 from rhodecode.tests import url, TestController
26 from rhodecode.tests import url, TestController
27 from rhodecode.tests.utils import AssertResponse
27 from rhodecode.tests.utils import AssertResponse
28
28
29
29
30 MATCH_HASH = re.compile(r'<span class="commit_hash">r(\d+):[\da-f]+</span>')
30 MATCH_HASH = re.compile(r'<span class="commit_hash">r(\d+):[\da-f]+</span>')
31
31
32
32
33 class TestChangelogController(TestController):
33 class TestChangelogController(TestController):
34
34
35 def test_index(self, backend):
35 def test_index(self, backend):
36 self.log_user()
36 self.log_user()
37 response = self.app.get(url(controller='changelog', action='index',
37 response = self.app.get(url(controller='changelog', action='index',
38 repo_name=backend.repo_name))
38 repo_name=backend.repo_name))
39
39
40 first_idx = -1
40 first_idx = -1
41 last_idx = -DEFAULT_CHANGELOG_SIZE
41 last_idx = -DEFAULT_CHANGELOG_SIZE
42 self.assert_commit_range_on_page(
42 self.assert_commit_range_on_page(
43 response, first_idx, last_idx, backend)
43 response, first_idx, last_idx, backend)
44
44
45 @pytest.mark.backends("hg", "git")
45 @pytest.mark.backends("hg", "git")
46 def test_index_filtered_by_branch(self, backend):
46 def test_index_filtered_by_branch(self, backend):
47 self.log_user()
47 self.log_user()
48 self.app.get(
48 self.app.get(
49 url(
49 url(
50 controller='changelog',
50 controller='changelog',
51 action='index',
51 action='index',
52 repo_name=backend.repo_name,
52 repo_name=backend.repo_name,
53 branch=backend.default_branch_name),
53 branch=backend.default_branch_name),
54 status=200)
54 status=200)
55
55
56 @pytest.mark.backends("svn")
56 @pytest.mark.backends("svn")
57 def test_index_filtered_by_branch_svn(self, autologin_user, backend):
57 def test_index_filtered_by_branch_svn(self, autologin_user, backend):
58 repo = backend['svn-simple-layout']
58 repo = backend['svn-simple-layout']
59 response = self.app.get(
59 response = self.app.get(
60 url(
60 url(
61 controller='changelog',
61 controller='changelog',
62 action='index',
62 action='index',
63 repo_name=repo.repo_name,
63 repo_name=repo.repo_name,
64 branch='trunk'),
64 branch='trunk'),
65 status=200)
65 status=200)
66
66
67 self.assert_commits_on_page(
67 self.assert_commits_on_page(
68 response, indexes=[15, 12, 7, 3, 2, 1])
68 response, indexes=[15, 12, 7, 3, 2, 1])
69
69
70 def test_index_filtered_by_wrong_branch(self, backend):
70 def test_index_filtered_by_wrong_branch(self, backend):
71 self.log_user()
71 self.log_user()
72 branch = 'wrong-branch-name'
72 branch = 'wrong-branch-name'
73 response = self.app.get(
73 response = self.app.get(
74 url(
74 url(
75 controller='changelog',
75 controller='changelog',
76 action='index',
76 action='index',
77 repo_name=backend.repo_name,
77 repo_name=backend.repo_name,
78 branch=branch),
78 branch=branch),
79 status=302)
79 status=302)
80 expected_url = '/{repo}/changelog/{branch}'.format(
80 expected_url = '/{repo}/changelog/{branch}'.format(
81 repo=backend.repo_name, branch=branch)
81 repo=backend.repo_name, branch=branch)
82 assert expected_url in response.location
82 assert expected_url in response.location
83 response = response.follow()
83 response = response.follow()
84 expected_warning = 'Branch {} is not found.'.format(branch)
84 expected_warning = 'Branch {} is not found.'.format(branch)
85 assert_response = AssertResponse(response)
85 assert expected_warning in response.body
86 assert_response.element_contains('.alert-warning', expected_warning)
87
86
88 def assert_commits_on_page(self, response, indexes):
87 def assert_commits_on_page(self, response, indexes):
89 found_indexes = [int(idx) for idx in MATCH_HASH.findall(response.body)]
88 found_indexes = [int(idx) for idx in MATCH_HASH.findall(response.body)]
90 assert found_indexes == indexes
89 assert found_indexes == indexes
91
90
92 @pytest.mark.xfail_backends("svn", reason="Depends on branch support")
91 @pytest.mark.xfail_backends("svn", reason="Depends on branch support")
93 def test_index_filtered_by_branch_with_merges(
92 def test_index_filtered_by_branch_with_merges(
94 self, autologin_user, backend):
93 self, autologin_user, backend):
95
94
96 # Note: The changelog of branch "b" does not contain the commit "a1"
95 # Note: The changelog of branch "b" does not contain the commit "a1"
97 # although this is a parent of commit "b1". And branch "b" has commits
96 # although this is a parent of commit "b1". And branch "b" has commits
98 # which have a smaller index than commit "a1".
97 # which have a smaller index than commit "a1".
99 commits = [
98 commits = [
100 {'message': 'a'},
99 {'message': 'a'},
101 {'message': 'b', 'branch': 'b'},
100 {'message': 'b', 'branch': 'b'},
102 {'message': 'a1', 'parents': ['a']},
101 {'message': 'a1', 'parents': ['a']},
103 {'message': 'b1', 'branch': 'b', 'parents': ['b', 'a1']},
102 {'message': 'b1', 'branch': 'b', 'parents': ['b', 'a1']},
104 ]
103 ]
105 backend.create_repo(commits)
104 backend.create_repo(commits)
106
105
107 self.app.get(
106 self.app.get(
108 url('changelog_home',
107 url('changelog_home',
109 controller='changelog',
108 controller='changelog',
110 action='index',
109 action='index',
111 repo_name=backend.repo_name,
110 repo_name=backend.repo_name,
112 branch='b'),
111 branch='b'),
113 status=200)
112 status=200)
114
113
115 @pytest.mark.backends("hg")
114 @pytest.mark.backends("hg")
116 def test_index_closed_branches(self, autologin_user, backend):
115 def test_index_closed_branches(self, autologin_user, backend):
117 repo = backend['closed_branch']
116 repo = backend['closed_branch']
118 response = self.app.get(
117 response = self.app.get(
119 url(
118 url(
120 controller='changelog',
119 controller='changelog',
121 action='index',
120 action='index',
122 repo_name=repo.repo_name,
121 repo_name=repo.repo_name,
123 branch='experimental'),
122 branch='experimental'),
124 status=200)
123 status=200)
125
124
126 self.assert_commits_on_page(
125 self.assert_commits_on_page(
127 response, indexes=[3, 1])
126 response, indexes=[3, 1])
128
127
129 def test_index_pagination(self, backend):
128 def test_index_pagination(self, backend):
130 self.log_user()
129 self.log_user()
131 # pagination, walk up to page 6
130 # pagination, walk up to page 6
132 changelog_url = url(
131 changelog_url = url(
133 controller='changelog', action='index',
132 controller='changelog', action='index',
134 repo_name=backend.repo_name)
133 repo_name=backend.repo_name)
135 for page in range(1, 7):
134 for page in range(1, 7):
136 response = self.app.get(changelog_url, {'page': page})
135 response = self.app.get(changelog_url, {'page': page})
137
136
138 first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1
137 first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1
139 last_idx = -DEFAULT_CHANGELOG_SIZE * page
138 last_idx = -DEFAULT_CHANGELOG_SIZE * page
140 self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
139 self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
141
140
142 def assert_commit_range_on_page(
141 def assert_commit_range_on_page(
143 self, response, first_idx, last_idx, backend):
142 self, response, first_idx, last_idx, backend):
144 input_template = (
143 input_template = (
145 """<input class="commit-range" id="%(raw_id)s" """
144 """<input class="commit-range" id="%(raw_id)s" """
146 """name="%(raw_id)s" type="checkbox" value="1" />"""
145 """name="%(raw_id)s" type="checkbox" value="1" />"""
147 )
146 )
148 commit_span_template = """<span class="commit_hash">r%s:%s</span>"""
147 commit_span_template = """<span class="commit_hash">r%s:%s</span>"""
149 repo = backend.repo
148 repo = backend.repo
150
149
151 first_commit_on_page = repo.get_commit(commit_idx=first_idx)
150 first_commit_on_page = repo.get_commit(commit_idx=first_idx)
152 response.mustcontain(
151 response.mustcontain(
153 input_template % {'raw_id': first_commit_on_page.raw_id})
152 input_template % {'raw_id': first_commit_on_page.raw_id})
154 response.mustcontain(commit_span_template % (
153 response.mustcontain(commit_span_template % (
155 first_commit_on_page.idx, first_commit_on_page.short_id)
154 first_commit_on_page.idx, first_commit_on_page.short_id)
156 )
155 )
157
156
158 last_commit_on_page = repo.get_commit(commit_idx=last_idx)
157 last_commit_on_page = repo.get_commit(commit_idx=last_idx)
159 response.mustcontain(
158 response.mustcontain(
160 input_template % {'raw_id': last_commit_on_page.raw_id})
159 input_template % {'raw_id': last_commit_on_page.raw_id})
161 response.mustcontain(commit_span_template % (
160 response.mustcontain(commit_span_template % (
162 last_commit_on_page.idx, last_commit_on_page.short_id)
161 last_commit_on_page.idx, last_commit_on_page.short_id)
163 )
162 )
164
163
165 first_commit_of_next_page = repo.get_commit(commit_idx=last_idx - 1)
164 first_commit_of_next_page = repo.get_commit(commit_idx=last_idx - 1)
166 first_span_of_next_page = commit_span_template % (
165 first_span_of_next_page = commit_span_template % (
167 first_commit_of_next_page.idx, first_commit_of_next_page.short_id)
166 first_commit_of_next_page.idx, first_commit_of_next_page.short_id)
168 assert first_span_of_next_page not in response
167 assert first_span_of_next_page not in response
169
168
170 def test_index_with_filenode(self, backend):
169 def test_index_with_filenode(self, backend):
171 self.log_user()
170 self.log_user()
172 response = self.app.get(url(
171 response = self.app.get(url(
173 controller='changelog', action='index', revision='tip',
172 controller='changelog', action='index', revision='tip',
174 f_path='/vcs/exceptions.py', repo_name=backend.repo_name))
173 f_path='/vcs/exceptions.py', repo_name=backend.repo_name))
175
174
176 # history commits messages
175 # history commits messages
177 response.mustcontain('Added exceptions module, this time for real')
176 response.mustcontain('Added exceptions module, this time for real')
178 response.mustcontain('Added not implemented hg backend test case')
177 response.mustcontain('Added not implemented hg backend test case')
179 response.mustcontain('Added BaseChangeset class')
178 response.mustcontain('Added BaseChangeset class')
180
179
181 def test_index_with_filenode_that_is_dirnode(self, backend):
180 def test_index_with_filenode_that_is_dirnode(self, backend):
182 self.log_user()
181 self.log_user()
183 response = self.app.get(url(controller='changelog', action='index',
182 response = self.app.get(url(controller='changelog', action='index',
184 revision='tip', f_path='/tests',
183 revision='tip', f_path='/tests',
185 repo_name=backend.repo_name))
184 repo_name=backend.repo_name))
186 assert response.status == '302 Found'
185 assert response.status == '302 Found'
187
186
188 def test_index_with_filenode_not_existing(self, backend):
187 def test_index_with_filenode_not_existing(self, backend):
189 self.log_user()
188 self.log_user()
190 response = self.app.get(url(controller='changelog', action='index',
189 response = self.app.get(url(controller='changelog', action='index',
191 revision='tip', f_path='/wrong_path',
190 revision='tip', f_path='/wrong_path',
192 repo_name=backend.repo_name))
191 repo_name=backend.repo_name))
193 assert response.status == '302 Found'
192 assert response.status == '302 Found'
General Comments 0
You need to be logged in to leave comments. Login now