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