##// END OF EJS Templates
tests: Add new argument to tests using '_create_reference_items' method.
Martin Bornhold -
r460:4151e600 default
parent child Browse files
Show More
@@ -1,514 +1,518 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 import os
22 import os
23
23
24 import mock
24 import mock
25 import pytest
25 import pytest
26
26
27 from rhodecode.controllers import summary
27 from rhodecode.controllers import summary
28 from rhodecode.lib import vcs
28 from rhodecode.lib import vcs
29 from rhodecode.lib import helpers as h
29 from rhodecode.lib import helpers as h
30 from rhodecode.lib.compat import OrderedDict
30 from rhodecode.lib.compat import OrderedDict
31 from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
31 from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
32 from rhodecode.model.db import Repository
32 from rhodecode.model.db import Repository
33 from rhodecode.model.meta import Session
33 from rhodecode.model.meta import Session
34 from rhodecode.model.repo import RepoModel
34 from rhodecode.model.repo import RepoModel
35 from rhodecode.model.scm import ScmModel
35 from rhodecode.model.scm import ScmModel
36 from rhodecode.tests import (
36 from rhodecode.tests import (
37 TestController, url, HG_REPO, assert_session_flash, TESTS_TMP_PATH)
37 TestController, url, HG_REPO, assert_session_flash, TESTS_TMP_PATH)
38 from rhodecode.tests.fixture import Fixture
38 from rhodecode.tests.fixture import Fixture
39 from rhodecode.tests.utils import AssertResponse
39 from rhodecode.tests.utils import AssertResponse
40
40
41
41
42 fixture = Fixture()
42 fixture = Fixture()
43
43
44
44
45 class TestSummaryController(TestController):
45 class TestSummaryController(TestController):
46 def test_index(self, backend):
46 def test_index(self, backend):
47 self.log_user()
47 self.log_user()
48 repo_id = backend.repo.repo_id
48 repo_id = backend.repo.repo_id
49 repo_name = backend.repo_name
49 repo_name = backend.repo_name
50 with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy',
50 with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy',
51 return_value=False):
51 return_value=False):
52 response = self.app.get(url('summary_home', repo_name=repo_name))
52 response = self.app.get(url('summary_home', repo_name=repo_name))
53
53
54 # repo type
54 # repo type
55 response.mustcontain(
55 response.mustcontain(
56 '<i class="icon-%s">' % (backend.alias, )
56 '<i class="icon-%s">' % (backend.alias, )
57 )
57 )
58 # public/private
58 # public/private
59 response.mustcontain(
59 response.mustcontain(
60 """<i class="icon-unlock-alt">"""
60 """<i class="icon-unlock-alt">"""
61 )
61 )
62
62
63 # clone url...
63 # clone url...
64 response.mustcontain(
64 response.mustcontain(
65 'id="clone_url" readonly="readonly"'
65 'id="clone_url" readonly="readonly"'
66 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
66 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
67 response.mustcontain(
67 response.mustcontain(
68 'id="clone_url_id" readonly="readonly"'
68 'id="clone_url_id" readonly="readonly"'
69 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
69 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
70
70
71 def test_index_svn_without_proxy(self, backend_svn):
71 def test_index_svn_without_proxy(self, backend_svn):
72 self.log_user()
72 self.log_user()
73 repo_id = backend_svn.repo.repo_id
73 repo_id = backend_svn.repo.repo_id
74 repo_name = backend_svn.repo_name
74 repo_name = backend_svn.repo_name
75 response = self.app.get(url('summary_home', repo_name=repo_name))
75 response = self.app.get(url('summary_home', repo_name=repo_name))
76 # clone url...
76 # clone url...
77 response.mustcontain(
77 response.mustcontain(
78 'id="clone_url" disabled'
78 'id="clone_url" disabled'
79 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
79 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
80 response.mustcontain(
80 response.mustcontain(
81 'id="clone_url_id" disabled'
81 'id="clone_url_id" disabled'
82 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
82 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
83
83
84 def test_index_with_trailing_slash(self, autologin_user, backend):
84 def test_index_with_trailing_slash(self, autologin_user, backend):
85 repo_id = backend.repo.repo_id
85 repo_id = backend.repo.repo_id
86 repo_name = backend.repo_name
86 repo_name = backend.repo_name
87 with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy',
87 with mock.patch('rhodecode.lib.helpers.is_svn_without_proxy',
88 return_value=False):
88 return_value=False):
89 response = self.app.get(
89 response = self.app.get(
90 url('summary_home', repo_name=repo_name) + '/',
90 url('summary_home', repo_name=repo_name) + '/',
91 status=200)
91 status=200)
92
92
93 # clone url...
93 # clone url...
94 response.mustcontain(
94 response.mustcontain(
95 'id="clone_url" readonly="readonly"'
95 'id="clone_url" readonly="readonly"'
96 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
96 ' value="http://test_admin@test.example.com:80/%s"' % (repo_name, ))
97 response.mustcontain(
97 response.mustcontain(
98 'id="clone_url_id" readonly="readonly"'
98 'id="clone_url_id" readonly="readonly"'
99 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
99 ' value="http://test_admin@test.example.com:80/_%s"' % (repo_id, ))
100
100
101 def test_index_by_id(self, backend):
101 def test_index_by_id(self, backend):
102 self.log_user()
102 self.log_user()
103 repo_id = backend.repo.repo_id
103 repo_id = backend.repo.repo_id
104 response = self.app.get(url(
104 response = self.app.get(url(
105 'summary_home', repo_name='_%s' % (repo_id,)))
105 'summary_home', repo_name='_%s' % (repo_id,)))
106
106
107 # repo type
107 # repo type
108 response.mustcontain(
108 response.mustcontain(
109 '<i class="icon-%s">' % (backend.alias, )
109 '<i class="icon-%s">' % (backend.alias, )
110 )
110 )
111 # public/private
111 # public/private
112 response.mustcontain(
112 response.mustcontain(
113 """<i class="icon-unlock-alt">"""
113 """<i class="icon-unlock-alt">"""
114 )
114 )
115
115
116 def test_index_by_repo_having_id_path_in_name_hg(self):
116 def test_index_by_repo_having_id_path_in_name_hg(self):
117 self.log_user()
117 self.log_user()
118 fixture.create_repo(name='repo_1')
118 fixture.create_repo(name='repo_1')
119 response = self.app.get(url('summary_home', repo_name='repo_1'))
119 response = self.app.get(url('summary_home', repo_name='repo_1'))
120
120
121 try:
121 try:
122 response.mustcontain("repo_1")
122 response.mustcontain("repo_1")
123 finally:
123 finally:
124 RepoModel().delete(Repository.get_by_repo_name('repo_1'))
124 RepoModel().delete(Repository.get_by_repo_name('repo_1'))
125 Session().commit()
125 Session().commit()
126
126
127 def test_index_with_anonymous_access_disabled(self):
127 def test_index_with_anonymous_access_disabled(self):
128 with fixture.anon_access(False):
128 with fixture.anon_access(False):
129 response = self.app.get(url('summary_home', repo_name=HG_REPO),
129 response = self.app.get(url('summary_home', repo_name=HG_REPO),
130 status=302)
130 status=302)
131 assert 'login' in response.location
131 assert 'login' in response.location
132
132
133 def _enable_stats(self, repo):
133 def _enable_stats(self, repo):
134 r = Repository.get_by_repo_name(repo)
134 r = Repository.get_by_repo_name(repo)
135 r.enable_statistics = True
135 r.enable_statistics = True
136 Session().add(r)
136 Session().add(r)
137 Session().commit()
137 Session().commit()
138
138
139 expected_trending = {
139 expected_trending = {
140 'hg': {
140 'hg': {
141 "py": {"count": 68, "desc": ["Python"]},
141 "py": {"count": 68, "desc": ["Python"]},
142 "rst": {"count": 16, "desc": ["Rst"]},
142 "rst": {"count": 16, "desc": ["Rst"]},
143 "css": {"count": 2, "desc": ["Css"]},
143 "css": {"count": 2, "desc": ["Css"]},
144 "sh": {"count": 2, "desc": ["Bash"]},
144 "sh": {"count": 2, "desc": ["Bash"]},
145 "bat": {"count": 1, "desc": ["Batch"]},
145 "bat": {"count": 1, "desc": ["Batch"]},
146 "cfg": {"count": 1, "desc": ["Ini"]},
146 "cfg": {"count": 1, "desc": ["Ini"]},
147 "html": {"count": 1, "desc": ["EvoqueHtml", "Html"]},
147 "html": {"count": 1, "desc": ["EvoqueHtml", "Html"]},
148 "ini": {"count": 1, "desc": ["Ini"]},
148 "ini": {"count": 1, "desc": ["Ini"]},
149 "js": {"count": 1, "desc": ["Javascript"]},
149 "js": {"count": 1, "desc": ["Javascript"]},
150 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]}
150 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]}
151 },
151 },
152 'git': {
152 'git': {
153 "py": {"count": 68, "desc": ["Python"]},
153 "py": {"count": 68, "desc": ["Python"]},
154 "rst": {"count": 16, "desc": ["Rst"]},
154 "rst": {"count": 16, "desc": ["Rst"]},
155 "css": {"count": 2, "desc": ["Css"]},
155 "css": {"count": 2, "desc": ["Css"]},
156 "sh": {"count": 2, "desc": ["Bash"]},
156 "sh": {"count": 2, "desc": ["Bash"]},
157 "bat": {"count": 1, "desc": ["Batch"]},
157 "bat": {"count": 1, "desc": ["Batch"]},
158 "cfg": {"count": 1, "desc": ["Ini"]},
158 "cfg": {"count": 1, "desc": ["Ini"]},
159 "html": {"count": 1, "desc": ["EvoqueHtml", "Html"]},
159 "html": {"count": 1, "desc": ["EvoqueHtml", "Html"]},
160 "ini": {"count": 1, "desc": ["Ini"]},
160 "ini": {"count": 1, "desc": ["Ini"]},
161 "js": {"count": 1, "desc": ["Javascript"]},
161 "js": {"count": 1, "desc": ["Javascript"]},
162 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]}
162 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]}
163 },
163 },
164 'svn': {
164 'svn': {
165 "py": {"count": 75, "desc": ["Python"]},
165 "py": {"count": 75, "desc": ["Python"]},
166 "rst": {"count": 16, "desc": ["Rst"]},
166 "rst": {"count": 16, "desc": ["Rst"]},
167 "html": {"count": 11, "desc": ["EvoqueHtml", "Html"]},
167 "html": {"count": 11, "desc": ["EvoqueHtml", "Html"]},
168 "css": {"count": 2, "desc": ["Css"]},
168 "css": {"count": 2, "desc": ["Css"]},
169 "bat": {"count": 1, "desc": ["Batch"]},
169 "bat": {"count": 1, "desc": ["Batch"]},
170 "cfg": {"count": 1, "desc": ["Ini"]},
170 "cfg": {"count": 1, "desc": ["Ini"]},
171 "ini": {"count": 1, "desc": ["Ini"]},
171 "ini": {"count": 1, "desc": ["Ini"]},
172 "js": {"count": 1, "desc": ["Javascript"]},
172 "js": {"count": 1, "desc": ["Javascript"]},
173 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]},
173 "makefile": {"count": 1, "desc": ["Makefile", "Makefile"]},
174 "sh": {"count": 1, "desc": ["Bash"]}
174 "sh": {"count": 1, "desc": ["Bash"]}
175 },
175 },
176 }
176 }
177
177
178 def test_repo_stats(self, backend, xhr_header):
178 def test_repo_stats(self, backend, xhr_header):
179 self.log_user()
179 self.log_user()
180 response = self.app.get(
180 response = self.app.get(
181 url('repo_stats',
181 url('repo_stats',
182 repo_name=backend.repo_name, commit_id='tip'),
182 repo_name=backend.repo_name, commit_id='tip'),
183 extra_environ=xhr_header,
183 extra_environ=xhr_header,
184 status=200)
184 status=200)
185 assert re.match(r'6[\d\.]+ KiB', response.json['size'])
185 assert re.match(r'6[\d\.]+ KiB', response.json['size'])
186
186
187 def test_repo_stats_code_stats_enabled(self, backend, xhr_header):
187 def test_repo_stats_code_stats_enabled(self, backend, xhr_header):
188 self.log_user()
188 self.log_user()
189 repo_name = backend.repo_name
189 repo_name = backend.repo_name
190
190
191 # codes stats
191 # codes stats
192 self._enable_stats(repo_name)
192 self._enable_stats(repo_name)
193 ScmModel().mark_for_invalidation(repo_name)
193 ScmModel().mark_for_invalidation(repo_name)
194
194
195 response = self.app.get(
195 response = self.app.get(
196 url('repo_stats',
196 url('repo_stats',
197 repo_name=backend.repo_name, commit_id='tip'),
197 repo_name=backend.repo_name, commit_id='tip'),
198 extra_environ=xhr_header,
198 extra_environ=xhr_header,
199 status=200)
199 status=200)
200
200
201 expected_data = self.expected_trending[backend.alias]
201 expected_data = self.expected_trending[backend.alias]
202 returned_stats = response.json['code_stats']
202 returned_stats = response.json['code_stats']
203 for k, v in expected_data.items():
203 for k, v in expected_data.items():
204 assert v == returned_stats[k]
204 assert v == returned_stats[k]
205
205
206 def test_repo_refs_data(self, backend):
206 def test_repo_refs_data(self, backend):
207 response = self.app.get(
207 response = self.app.get(
208 url('repo_refs_data', repo_name=backend.repo_name),
208 url('repo_refs_data', repo_name=backend.repo_name),
209 status=200)
209 status=200)
210
210
211 # Ensure that there is the correct amount of items in the result
211 # Ensure that there is the correct amount of items in the result
212 repo = backend.repo.scm_instance()
212 repo = backend.repo.scm_instance()
213 data = response.json['results']
213 data = response.json['results']
214 items = sum(len(section['children']) for section in data)
214 items = sum(len(section['children']) for section in data)
215 repo_refs = len(repo.branches) + len(repo.tags) + len(repo.bookmarks)
215 repo_refs = len(repo.branches) + len(repo.tags) + len(repo.bookmarks)
216 assert items == repo_refs
216 assert items == repo_refs
217
217
218 def test_index_shows_missing_requirements_message(
218 def test_index_shows_missing_requirements_message(
219 self, backend, autologin_user):
219 self, backend, autologin_user):
220 repo_name = backend.repo_name
220 repo_name = backend.repo_name
221 scm_patcher = mock.patch.object(
221 scm_patcher = mock.patch.object(
222 Repository, 'scm_instance', side_effect=RepositoryRequirementError)
222 Repository, 'scm_instance', side_effect=RepositoryRequirementError)
223
223
224 with scm_patcher:
224 with scm_patcher:
225 response = self.app.get(url('summary_home', repo_name=repo_name))
225 response = self.app.get(url('summary_home', repo_name=repo_name))
226 assert_response = AssertResponse(response)
226 assert_response = AssertResponse(response)
227 assert_response.element_contains(
227 assert_response.element_contains(
228 '.main .alert-warning strong', 'Missing requirements')
228 '.main .alert-warning strong', 'Missing requirements')
229 assert_response.element_contains(
229 assert_response.element_contains(
230 '.main .alert-warning',
230 '.main .alert-warning',
231 'These commits cannot be displayed, because this repository'
231 'These commits cannot be displayed, because this repository'
232 ' uses the Mercurial largefiles extension, which was not enabled.')
232 ' uses the Mercurial largefiles extension, which was not enabled.')
233
233
234 def test_missing_requirements_page_does_not_contains_switch_to(
234 def test_missing_requirements_page_does_not_contains_switch_to(
235 self, backend):
235 self, backend):
236 self.log_user()
236 self.log_user()
237 repo_name = backend.repo_name
237 repo_name = backend.repo_name
238 scm_patcher = mock.patch.object(
238 scm_patcher = mock.patch.object(
239 Repository, 'scm_instance', side_effect=RepositoryRequirementError)
239 Repository, 'scm_instance', side_effect=RepositoryRequirementError)
240
240
241 with scm_patcher:
241 with scm_patcher:
242 response = self.app.get(url('summary_home', repo_name=repo_name))
242 response = self.app.get(url('summary_home', repo_name=repo_name))
243 response.mustcontain(no='Switch To')
243 response.mustcontain(no='Switch To')
244
244
245
245
246 @pytest.mark.usefixtures('pylonsapp')
246 @pytest.mark.usefixtures('pylonsapp')
247 class TestSwitcherReferenceData:
247 class TestSwitcherReferenceData:
248
248
249 def test_creates_reference_urls_based_on_name(self):
249 def test_creates_reference_urls_based_on_name(self):
250 references = {
250 references = {
251 'name': 'commit_id',
251 'name': 'commit_id',
252 }
252 }
253 controller = summary.SummaryController()
253 controller = summary.SummaryController()
254 is_svn = False
254 is_svn = False
255 result = controller._switcher_reference_data(
255 result = controller._switcher_reference_data(
256 'repo_name', references, is_svn)
256 'repo_name', references, is_svn)
257 expected_url = h.url(
257 expected_url = h.url(
258 'files_home', repo_name='repo_name', revision='name',
258 'files_home', repo_name='repo_name', revision='name',
259 at='name')
259 at='name')
260 assert result[0]['files_url'] == expected_url
260 assert result[0]['files_url'] == expected_url
261
261
262 def test_urls_contain_commit_id_if_slash_in_name(self):
262 def test_urls_contain_commit_id_if_slash_in_name(self):
263 references = {
263 references = {
264 'name/with/slash': 'commit_id',
264 'name/with/slash': 'commit_id',
265 }
265 }
266 controller = summary.SummaryController()
266 controller = summary.SummaryController()
267 is_svn = False
267 is_svn = False
268 result = controller._switcher_reference_data(
268 result = controller._switcher_reference_data(
269 'repo_name', references, is_svn)
269 'repo_name', references, is_svn)
270 expected_url = h.url(
270 expected_url = h.url(
271 'files_home', repo_name='repo_name', revision='commit_id',
271 'files_home', repo_name='repo_name', revision='commit_id',
272 at='name/with/slash')
272 at='name/with/slash')
273 assert result[0]['files_url'] == expected_url
273 assert result[0]['files_url'] == expected_url
274
274
275 def test_adds_reference_to_path_for_svn(self):
275 def test_adds_reference_to_path_for_svn(self):
276 references = {
276 references = {
277 'name/with/slash': 'commit_id',
277 'name/with/slash': 'commit_id',
278 }
278 }
279 controller = summary.SummaryController()
279 controller = summary.SummaryController()
280 is_svn = True
280 is_svn = True
281 result = controller._switcher_reference_data(
281 result = controller._switcher_reference_data(
282 'repo_name', references, is_svn)
282 'repo_name', references, is_svn)
283 expected_url = h.url(
283 expected_url = h.url(
284 'files_home', repo_name='repo_name', f_path='name/with/slash',
284 'files_home', repo_name='repo_name', f_path='name/with/slash',
285 revision='commit_id', at='name/with/slash')
285 revision='commit_id', at='name/with/slash')
286 assert result[0]['files_url'] == expected_url
286 assert result[0]['files_url'] == expected_url
287
287
288
288
289 @pytest.mark.usefixtures('pylonsapp')
289 @pytest.mark.usefixtures('pylonsapp')
290 class TestCreateReferenceData:
290 class TestCreateReferenceData:
291
291
292 @pytest.fixture
292 @pytest.fixture
293 def example_refs(self):
293 def example_refs(self):
294 section_1_refs = OrderedDict((('a', 'a_id'), ('b', 'b_id')))
294 section_1_refs = OrderedDict((('a', 'a_id'), ('b', 'b_id')))
295 example_refs = [
295 example_refs = [
296 ('section_1', section_1_refs, 't1'),
296 ('section_1', section_1_refs, 't1'),
297 ('section_2', {'c': 'c_id'}, 't2'),
297 ('section_2', {'c': 'c_id'}, 't2'),
298 ]
298 ]
299 return example_refs
299 return example_refs
300
300
301 def test_generates_refs_based_on_commit_ids(self, example_refs):
301 def test_generates_refs_based_on_commit_ids(self, example_refs):
302 repo = mock.Mock()
302 repo = mock.Mock()
303 repo.name = 'test-repo'
303 repo.name = 'test-repo'
304 repo.alias = 'git'
304 repo.alias = 'git'
305 controller = summary.SummaryController()
305 controller = summary.SummaryController()
306
306
307 result = controller._create_reference_data(repo, example_refs)
307 result = controller._create_reference_data(repo, example_refs)
308
308
309 expected_result = [
309 expected_result = [
310 {
310 {
311 'children': [
311 'children': [
312 {
312 {
313 'id': 'a', 'raw_id': 'a_id', 'text': 'a', 'type': 't1',
313 'id': 'a', 'raw_id': 'a_id', 'text': 'a', 'type': 't1',
314 'files_url': '/test-repo/files/a/?at=a'
314 'files_url': '/test-repo/files/a/?at=a'
315 },
315 },
316 {
316 {
317 'id': 'b', 'raw_id': 'b_id', 'text': 'b', 'type': 't1',
317 'id': 'b', 'raw_id': 'b_id', 'text': 'b', 'type': 't1',
318 'files_url': '/test-repo/files/b/?at=b'
318 'files_url': '/test-repo/files/b/?at=b'
319 }
319 }
320 ],
320 ],
321 'text': 'section_1'
321 'text': 'section_1'
322 },
322 },
323 {
323 {
324 'children': [
324 'children': [
325 {
325 {
326 'id': 'c', 'raw_id': 'c_id', 'text': 'c', 'type': 't2',
326 'id': 'c', 'raw_id': 'c_id', 'text': 'c', 'type': 't2',
327 'files_url': '/test-repo/files/c/?at=c'
327 'files_url': '/test-repo/files/c/?at=c'
328 }
328 }
329 ],
329 ],
330 'text': 'section_2'
330 'text': 'section_2'
331 }]
331 }]
332 assert result == expected_result
332 assert result == expected_result
333
333
334 def test_generates_refs_with_path_for_svn(self, example_refs):
334 def test_generates_refs_with_path_for_svn(self, example_refs):
335 repo = mock.Mock()
335 repo = mock.Mock()
336 repo.name = 'test-repo'
336 repo.name = 'test-repo'
337 repo.alias = 'svn'
337 repo.alias = 'svn'
338 controller = summary.SummaryController()
338 controller = summary.SummaryController()
339 result = controller._create_reference_data(repo, example_refs)
339 result = controller._create_reference_data(repo, example_refs)
340
340
341 expected_result = [
341 expected_result = [
342 {
342 {
343 'children': [
343 'children': [
344 {
344 {
345 'id': 'a@a_id', 'raw_id': 'a_id',
345 'id': 'a@a_id', 'raw_id': 'a_id',
346 'text': 'a', 'type': 't1',
346 'text': 'a', 'type': 't1',
347 'files_url': '/test-repo/files/a_id/a?at=a'
347 'files_url': '/test-repo/files/a_id/a?at=a'
348 },
348 },
349 {
349 {
350 'id': 'b@b_id', 'raw_id': 'b_id',
350 'id': 'b@b_id', 'raw_id': 'b_id',
351 'text': 'b', 'type': 't1',
351 'text': 'b', 'type': 't1',
352 'files_url': '/test-repo/files/b_id/b?at=b'
352 'files_url': '/test-repo/files/b_id/b?at=b'
353 }
353 }
354 ],
354 ],
355 'text': 'section_1'
355 'text': 'section_1'
356 },
356 },
357 {
357 {
358 'children': [
358 'children': [
359 {
359 {
360 'id': 'c@c_id', 'raw_id': 'c_id',
360 'id': 'c@c_id', 'raw_id': 'c_id',
361 'text': 'c', 'type': 't2',
361 'text': 'c', 'type': 't2',
362 'files_url': '/test-repo/files/c_id/c?at=c'
362 'files_url': '/test-repo/files/c_id/c?at=c'
363 }
363 }
364 ],
364 ],
365 'text': 'section_2'
365 'text': 'section_2'
366 }
366 }
367 ]
367 ]
368 assert result == expected_result
368 assert result == expected_result
369
369
370
370
371 @pytest.mark.usefixtures("app")
371 @pytest.mark.usefixtures("app")
372 class TestRepoLocation:
372 class TestRepoLocation:
373
373
374 @pytest.mark.parametrize("suffix", [u'', u'Δ…Δ™Ε‚'], ids=['', 'non-ascii'])
374 @pytest.mark.parametrize("suffix", [u'', u'Δ…Δ™Ε‚'], ids=['', 'non-ascii'])
375 def test_manual_delete(self, autologin_user, backend, suffix, csrf_token):
375 def test_manual_delete(self, autologin_user, backend, suffix, csrf_token):
376 repo = backend.create_repo(name_suffix=suffix)
376 repo = backend.create_repo(name_suffix=suffix)
377 repo_name = repo.repo_name
377 repo_name = repo.repo_name
378
378
379 # delete from file system
379 # delete from file system
380 RepoModel()._delete_filesystem_repo(repo)
380 RepoModel()._delete_filesystem_repo(repo)
381
381
382 # test if the repo is still in the database
382 # test if the repo is still in the database
383 new_repo = RepoModel().get_by_repo_name(repo_name)
383 new_repo = RepoModel().get_by_repo_name(repo_name)
384 assert new_repo.repo_name == repo_name
384 assert new_repo.repo_name == repo_name
385
385
386 # check if repo is not in the filesystem
386 # check if repo is not in the filesystem
387 assert not repo_on_filesystem(repo_name)
387 assert not repo_on_filesystem(repo_name)
388 self.assert_repo_not_found_redirect(repo_name)
388 self.assert_repo_not_found_redirect(repo_name)
389
389
390 def assert_repo_not_found_redirect(self, repo_name):
390 def assert_repo_not_found_redirect(self, repo_name):
391 # run the check page that triggers the other flash message
391 # run the check page that triggers the other flash message
392 response = self.app.get(url('repo_check_home', repo_name=repo_name))
392 response = self.app.get(url('repo_check_home', repo_name=repo_name))
393 assert_session_flash(
393 assert_session_flash(
394 response, 'The repository at %s cannot be located.' % repo_name)
394 response, 'The repository at %s cannot be located.' % repo_name)
395
395
396
396
397 def repo_on_filesystem(repo_name):
397 def repo_on_filesystem(repo_name):
398 try:
398 try:
399 vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
399 vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name))
400 return True
400 return True
401 except Exception:
401 except Exception:
402 return False
402 return False
403
403
404
404
405 class TestCreateFilesUrl(object):
405 class TestCreateFilesUrl(object):
406 def test_creates_non_svn_url(self):
406 def test_creates_non_svn_url(self):
407 controller = summary.SummaryController()
407 controller = summary.SummaryController()
408 repo = mock.Mock()
408 repo = mock.Mock()
409 repo.name = 'abcde'
409 repo.name = 'abcde'
410 full_repo_name = 'test-repo-group/' + repo.name
410 full_repo_name = 'test-repo-group/' + repo.name
411 ref_name = 'branch1'
411 ref_name = 'branch1'
412 raw_id = 'deadbeef0123456789'
412 raw_id = 'deadbeef0123456789'
413 is_svn = False
413 is_svn = False
414
414
415 with mock.patch.object(summary.h, 'url') as url_mock:
415 with mock.patch.object(summary.h, 'url') as url_mock:
416 result = controller._create_files_url(
416 result = controller._create_files_url(
417 repo, full_repo_name, ref_name, raw_id, is_svn)
417 repo, full_repo_name, ref_name, raw_id, is_svn)
418 url_mock.assert_called_once_with(
418 url_mock.assert_called_once_with(
419 'files_home', repo_name=full_repo_name, f_path='',
419 'files_home', repo_name=full_repo_name, f_path='',
420 revision=ref_name, at=ref_name)
420 revision=ref_name, at=ref_name)
421 assert result == url_mock.return_value
421 assert result == url_mock.return_value
422
422
423 def test_creates_svn_url(self):
423 def test_creates_svn_url(self):
424 controller = summary.SummaryController()
424 controller = summary.SummaryController()
425 repo = mock.Mock()
425 repo = mock.Mock()
426 repo.name = 'abcde'
426 repo.name = 'abcde'
427 full_repo_name = 'test-repo-group/' + repo.name
427 full_repo_name = 'test-repo-group/' + repo.name
428 ref_name = 'branch1'
428 ref_name = 'branch1'
429 raw_id = 'deadbeef0123456789'
429 raw_id = 'deadbeef0123456789'
430 is_svn = True
430 is_svn = True
431
431
432 with mock.patch.object(summary.h, 'url') as url_mock:
432 with mock.patch.object(summary.h, 'url') as url_mock:
433 result = controller._create_files_url(
433 result = controller._create_files_url(
434 repo, full_repo_name, ref_name, raw_id, is_svn)
434 repo, full_repo_name, ref_name, raw_id, is_svn)
435 url_mock.assert_called_once_with(
435 url_mock.assert_called_once_with(
436 'files_home', repo_name=full_repo_name, f_path=ref_name,
436 'files_home', repo_name=full_repo_name, f_path=ref_name,
437 revision=raw_id, at=ref_name)
437 revision=raw_id, at=ref_name)
438 assert result == url_mock.return_value
438 assert result == url_mock.return_value
439
439
440 def test_name_has_slashes(self):
440 def test_name_has_slashes(self):
441 controller = summary.SummaryController()
441 controller = summary.SummaryController()
442 repo = mock.Mock()
442 repo = mock.Mock()
443 repo.name = 'abcde'
443 repo.name = 'abcde'
444 full_repo_name = 'test-repo-group/' + repo.name
444 full_repo_name = 'test-repo-group/' + repo.name
445 ref_name = 'branch1/branch2'
445 ref_name = 'branch1/branch2'
446 raw_id = 'deadbeef0123456789'
446 raw_id = 'deadbeef0123456789'
447 is_svn = False
447 is_svn = False
448
448
449 with mock.patch.object(summary.h, 'url') as url_mock:
449 with mock.patch.object(summary.h, 'url') as url_mock:
450 result = controller._create_files_url(
450 result = controller._create_files_url(
451 repo, full_repo_name, ref_name, raw_id, is_svn)
451 repo, full_repo_name, ref_name, raw_id, is_svn)
452 url_mock.assert_called_once_with(
452 url_mock.assert_called_once_with(
453 'files_home', repo_name=full_repo_name, f_path='', revision=raw_id,
453 'files_home', repo_name=full_repo_name, f_path='', revision=raw_id,
454 at=ref_name)
454 at=ref_name)
455 assert result == url_mock.return_value
455 assert result == url_mock.return_value
456
456
457
457
458 class TestReferenceItems(object):
458 class TestReferenceItems(object):
459 repo = mock.Mock()
459 repo = mock.Mock()
460 repo.name = 'pytest-repo'
461 repo_full_name = 'pytest-repo-group/' + repo.name
460 ref_type = 'branch'
462 ref_type = 'branch'
461 fake_url = '/abcde/'
463 fake_url = '/abcde/'
462
464
463 @staticmethod
465 @staticmethod
464 def _format_function(name, id_):
466 def _format_function(name, id_):
465 return 'format_function_{}_{}'.format(name, id_)
467 return 'format_function_{}_{}'.format(name, id_)
466
468
467 def test_creates_required_amount_of_items(self):
469 def test_creates_required_amount_of_items(self):
468 amount = 100
470 amount = 100
469 refs = {
471 refs = {
470 'ref{}'.format(i): '{0:040d}'.format(i)
472 'ref{}'.format(i): '{0:040d}'.format(i)
471 for i in range(amount)
473 for i in range(amount)
472 }
474 }
473
475
474 controller = summary.SummaryController()
476 controller = summary.SummaryController()
475
477
476 url_patcher = mock.patch.object(
478 url_patcher = mock.patch.object(
477 controller, '_create_files_url')
479 controller, '_create_files_url')
478 svn_patcher = mock.patch.object(
480 svn_patcher = mock.patch.object(
479 summary.h, 'is_svn', return_value=False)
481 summary.h, 'is_svn', return_value=False)
480
482
481 with url_patcher as url_mock, svn_patcher:
483 with url_patcher as url_mock, svn_patcher:
482 result = controller._create_reference_items(
484 result = controller._create_reference_items(
483 self.repo, refs, self.ref_type, self._format_function)
485 self.repo, self.repo_full_name, refs, self.ref_type,
486 self._format_function)
484 assert len(result) == amount
487 assert len(result) == amount
485 assert url_mock.call_count == amount
488 assert url_mock.call_count == amount
486
489
487 def test_single_item_details(self):
490 def test_single_item_details(self):
488 ref_name = 'ref1'
491 ref_name = 'ref1'
489 ref_id = 'deadbeef'
492 ref_id = 'deadbeef'
490 refs = {
493 refs = {
491 ref_name: ref_id
494 ref_name: ref_id
492 }
495 }
493
496
494 controller = summary.SummaryController()
497 controller = summary.SummaryController()
495 url_patcher = mock.patch.object(
498 url_patcher = mock.patch.object(
496 controller, '_create_files_url', return_value=self.fake_url)
499 controller, '_create_files_url', return_value=self.fake_url)
497 svn_patcher = mock.patch.object(
500 svn_patcher = mock.patch.object(
498 summary.h, 'is_svn', return_value=False)
501 summary.h, 'is_svn', return_value=False)
499
502
500 with url_patcher as url_mock, svn_patcher:
503 with url_patcher as url_mock, svn_patcher:
501 result = controller._create_reference_items(
504 result = controller._create_reference_items(
502 self.repo, refs, self.ref_type, self._format_function)
505 self.repo, self.repo_full_name, refs, self.ref_type,
506 self._format_function)
503
507
504 url_mock.assert_called_once_with(self.repo, ref_name, ref_id, False)
508 url_mock.assert_called_once_with(self.repo, ref_name, ref_id, False)
505 expected_result = [
509 expected_result = [
506 {
510 {
507 'text': ref_name,
511 'text': ref_name,
508 'id': self._format_function(ref_name, ref_id),
512 'id': self._format_function(ref_name, ref_id),
509 'raw_id': ref_id,
513 'raw_id': ref_id,
510 'type': self.ref_type,
514 'type': self.ref_type,
511 'files_url': self.fake_url
515 'files_url': self.fake_url
512 }
516 }
513 ]
517 ]
514 assert result == expected_result
518 assert result == expected_result
General Comments 0
You need to be logged in to leave comments. Login now