##// END OF EJS Templates
tests: fixed home tests with cached values
marcink -
r277:f422c79f default
parent child Browse files
Show More
@@ -1,379 +1,381 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 json
21 import json
22
22
23 from mock import patch
23 from mock import patch
24 import pytest
24 import pytest
25
25
26 import rhodecode
26 import rhodecode
27 from rhodecode.lib.utils import map_groups
27 from rhodecode.lib.utils import map_groups
28 from rhodecode.model.db import Repository, User, RepoGroup
28 from rhodecode.model.db import Repository, User, RepoGroup
29 from rhodecode.model.meta import Session
29 from rhodecode.model.meta import Session
30 from rhodecode.model.repo import RepoModel
30 from rhodecode.model.repo import RepoModel
31 from rhodecode.model.repo_group import RepoGroupModel
31 from rhodecode.model.repo_group import RepoGroupModel
32 from rhodecode.model.settings import SettingsModel
32 from rhodecode.model.settings import SettingsModel
33 from rhodecode.tests import TestController, url, TEST_USER_ADMIN_LOGIN
33 from rhodecode.tests import TestController, url, TEST_USER_ADMIN_LOGIN
34 from rhodecode.tests.fixture import Fixture
34 from rhodecode.tests.fixture import Fixture
35
35
36
36
37 fixture = Fixture()
37 fixture = Fixture()
38
38
39
39
40 class TestHomeController(TestController):
40 class TestHomeController(TestController):
41
41
42 def test_index(self):
42 def test_index(self):
43 self.log_user()
43 self.log_user()
44 response = self.app.get(url(controller='home', action='index'))
44 response = self.app.get(url(controller='home', action='index'))
45 # if global permission is set
45 # if global permission is set
46 response.mustcontain('Add Repository')
46 response.mustcontain('Add Repository')
47
47
48 # search for objects inside the JavaScript JSON
48 # search for objects inside the JavaScript JSON
49 for repo in Repository.getAll():
49 for repo in Repository.getAll():
50 response.mustcontain('"name_raw": "%s"' % repo.repo_name)
50 response.mustcontain('"name_raw": "%s"' % repo.repo_name)
51
51
52 def test_index_contains_backend_specific_details(self, backend):
52 def test_index_contains_backend_specific_details(self, backend):
53 self.log_user()
53 self.log_user()
54 response = self.app.get(url(controller='home', action='index'))
54 response = self.app.get(url(controller='home', action='index'))
55 tip = backend.repo.get_commit().raw_id
55 tip = backend.repo.get_commit().raw_id
56
56
57 # html in javascript variable:
57 # html in javascript variable:
58 response.mustcontain(r'<i class=\"icon-%s\"' % (backend.alias, ))
58 response.mustcontain(r'<i class=\"icon-%s\"' % (backend.alias, ))
59 response.mustcontain(r'href=\"/%s\"' % (backend.repo_name, ))
59 response.mustcontain(r'href=\"/%s\"' % (backend.repo_name, ))
60
60
61 response.mustcontain("""/%s/changeset/%s""" % (backend.repo_name, tip))
61 response.mustcontain("""/%s/changeset/%s""" % (backend.repo_name, tip))
62 response.mustcontain("""Added a symlink""")
62 response.mustcontain("""Added a symlink""")
63
63
64 def test_index_with_anonymous_access_disabled(self):
64 def test_index_with_anonymous_access_disabled(self):
65 with fixture.anon_access(False):
65 with fixture.anon_access(False):
66 response = self.app.get(url(controller='home', action='index'),
66 response = self.app.get(url(controller='home', action='index'),
67 status=302)
67 status=302)
68 assert 'login' in response.location
68 assert 'login' in response.location
69
69
70 def test_index_page_on_groups(self, autologin_user, repo_group):
70 def test_index_page_on_groups(self, autologin_user, repo_group):
71 response = self.app.get(url('repo_group_home', group_name='gr1'))
71 response = self.app.get(url('repo_group_home', group_name='gr1'))
72 response.mustcontain("gr1/repo_in_group")
72 response.mustcontain("gr1/repo_in_group")
73
73
74 def test_index_page_on_group_with_trailing_slash(
74 def test_index_page_on_group_with_trailing_slash(
75 self, autologin_user, repo_group):
75 self, autologin_user, repo_group):
76 response = self.app.get(url('repo_group_home', group_name='gr1') + '/')
76 response = self.app.get(url('repo_group_home', group_name='gr1') + '/')
77 response.mustcontain("gr1/repo_in_group")
77 response.mustcontain("gr1/repo_in_group")
78
78
79 @pytest.fixture(scope='class')
79 @pytest.fixture(scope='class')
80 def repo_group(self, request):
80 def repo_group(self, request):
81 gr = fixture.create_repo_group('gr1')
81 gr = fixture.create_repo_group('gr1')
82 fixture.create_repo(name='gr1/repo_in_group', repo_group=gr)
82 fixture.create_repo(name='gr1/repo_in_group', repo_group=gr)
83
83
84 @request.addfinalizer
84 @request.addfinalizer
85 def cleanup():
85 def cleanup():
86 RepoModel().delete('gr1/repo_in_group')
86 RepoModel().delete('gr1/repo_in_group')
87 RepoGroupModel().delete(repo_group='gr1', force_delete=True)
87 RepoGroupModel().delete(repo_group='gr1', force_delete=True)
88 Session().commit()
88 Session().commit()
89
89
90 def test_index_with_name_with_tags(self, autologin_user):
90 def test_index_with_name_with_tags(self, autologin_user):
91 user = User.get_by_username('test_admin')
91 user = User.get_by_username('test_admin')
92 user.name = '<img src="/image1" onload="alert(\'Hello, World!\');">'
92 user.name = '<img src="/image1" onload="alert(\'Hello, World!\');">'
93 user.lastname = (
93 user.lastname = (
94 '<img src="/image2" onload="alert(\'Hello, World!\');">')
94 '<img src="/image2" onload="alert(\'Hello, World!\');">')
95 Session().add(user)
95 Session().add(user)
96 Session().commit()
96 Session().commit()
97
97
98 response = self.app.get(url(controller='home', action='index'))
98 response = self.app.get(url(controller='home', action='index'))
99 response.mustcontain(
99 response.mustcontain(
100 '&lt;img src=&#34;/image1&#34; onload=&#34;'
100 '&lt;img src=&#34;/image1&#34; onload=&#34;'
101 'alert(&#39;Hello, World!&#39;);&#34;&gt;')
101 'alert(&#39;Hello, World!&#39;);&#34;&gt;')
102 response.mustcontain(
102 response.mustcontain(
103 '&lt;img src=&#34;/image2&#34; onload=&#34;'
103 '&lt;img src=&#34;/image2&#34; onload=&#34;'
104 'alert(&#39;Hello, World!&#39;);&#34;&gt;')
104 'alert(&#39;Hello, World!&#39;);&#34;&gt;')
105
105
106 @pytest.mark.parametrize("name, state", [
106 @pytest.mark.parametrize("name, state", [
107 ('Disabled', False),
107 ('Disabled', False),
108 ('Enabled', True),
108 ('Enabled', True),
109 ])
109 ])
110 def test_index_show_version(self, autologin_user, name, state):
110 def test_index_show_version(self, autologin_user, name, state):
111 version_string = 'RhodeCode Enterprise %s' % rhodecode.__version__
111 version_string = 'RhodeCode Enterprise %s' % rhodecode.__version__
112
112
113 show = SettingsModel().get_setting_by_name('show_version')
113 sett = SettingsModel().create_or_update_setting(
114 show.app_settings_value = state
114 'show_version', state, 'bool')
115 Session().add(show)
115 Session().add(sett)
116 Session().commit()
116 Session().commit()
117 SettingsModel().invalidate_settings_cache()
118
117 response = self.app.get(url(controller='home', action='index'))
119 response = self.app.get(url(controller='home', action='index'))
118 if state is True:
120 if state is True:
119 response.mustcontain(version_string)
121 response.mustcontain(version_string)
120 if state is False:
122 if state is False:
121 response.mustcontain(no=[version_string])
123 response.mustcontain(no=[version_string])
122
124
123
125
124 class TestUserAutocompleteData(TestController):
126 class TestUserAutocompleteData(TestController):
125 def test_returns_list_of_users(self, user_util):
127 def test_returns_list_of_users(self, user_util):
126 self.log_user()
128 self.log_user()
127 user = user_util.create_user(is_active=True)
129 user = user_util.create_user(is_active=True)
128 user_name = user.username
130 user_name = user.username
129 response = self.app.get(
131 response = self.app.get(
130 url(controller='home', action='user_autocomplete_data'),
132 url(controller='home', action='user_autocomplete_data'),
131 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
133 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
132 result = json.loads(response.body)
134 result = json.loads(response.body)
133 values = [suggestion['value'] for suggestion in result['suggestions']]
135 values = [suggestion['value'] for suggestion in result['suggestions']]
134 assert user_name in values
136 assert user_name in values
135
137
136 def test_returns_inactive_users_when_active_flag_sent(self, user_util):
138 def test_returns_inactive_users_when_active_flag_sent(self, user_util):
137 self.log_user()
139 self.log_user()
138 user = user_util.create_user(is_active=False)
140 user = user_util.create_user(is_active=False)
139 user_name = user.username
141 user_name = user.username
140 response = self.app.get(
142 response = self.app.get(
141 url(controller='home', action='user_autocomplete_data',
143 url(controller='home', action='user_autocomplete_data',
142 user_groups='true', active='0'),
144 user_groups='true', active='0'),
143 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
145 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
144 result = json.loads(response.body)
146 result = json.loads(response.body)
145 values = [suggestion['value'] for suggestion in result['suggestions']]
147 values = [suggestion['value'] for suggestion in result['suggestions']]
146 assert user_name in values
148 assert user_name in values
147
149
148 def test_returns_groups_when_user_groups_sent(self, user_util):
150 def test_returns_groups_when_user_groups_sent(self, user_util):
149 self.log_user()
151 self.log_user()
150 group = user_util.create_user_group(user_groups_active=True)
152 group = user_util.create_user_group(user_groups_active=True)
151 group_name = group.users_group_name
153 group_name = group.users_group_name
152 response = self.app.get(
154 response = self.app.get(
153 url(controller='home', action='user_autocomplete_data',
155 url(controller='home', action='user_autocomplete_data',
154 user_groups='true'),
156 user_groups='true'),
155 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
157 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
156 result = json.loads(response.body)
158 result = json.loads(response.body)
157 values = [suggestion['value'] for suggestion in result['suggestions']]
159 values = [suggestion['value'] for suggestion in result['suggestions']]
158 assert group_name in values
160 assert group_name in values
159
161
160 def test_result_is_limited_when_query_is_sent(self):
162 def test_result_is_limited_when_query_is_sent(self):
161 self.log_user()
163 self.log_user()
162 fake_result = [
164 fake_result = [
163 {
165 {
164 'first_name': 'John',
166 'first_name': 'John',
165 'value_display': 'hello{} (John Smith)'.format(i),
167 'value_display': 'hello{} (John Smith)'.format(i),
166 'icon_link': '/images/user14.png',
168 'icon_link': '/images/user14.png',
167 'value': 'hello{}'.format(i),
169 'value': 'hello{}'.format(i),
168 'last_name': 'Smith',
170 'last_name': 'Smith',
169 'username': 'hello{}'.format(i),
171 'username': 'hello{}'.format(i),
170 'id': i,
172 'id': i,
171 'value_type': u'user'
173 'value_type': u'user'
172 }
174 }
173 for i in range(10)
175 for i in range(10)
174 ]
176 ]
175 users_patcher = patch.object(
177 users_patcher = patch.object(
176 RepoModel, 'get_users', return_value=fake_result)
178 RepoModel, 'get_users', return_value=fake_result)
177 groups_patcher = patch.object(
179 groups_patcher = patch.object(
178 RepoModel, 'get_user_groups', return_value=fake_result)
180 RepoModel, 'get_user_groups', return_value=fake_result)
179
181
180 query = 'hello'
182 query = 'hello'
181 with users_patcher as users_mock, groups_patcher as groups_mock:
183 with users_patcher as users_mock, groups_patcher as groups_mock:
182 response = self.app.get(
184 response = self.app.get(
183 url(controller='home', action='user_autocomplete_data',
185 url(controller='home', action='user_autocomplete_data',
184 user_groups='true', query=query),
186 user_groups='true', query=query),
185 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
187 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
186
188
187 result = json.loads(response.body)
189 result = json.loads(response.body)
188 users_mock.assert_called_once_with(
190 users_mock.assert_called_once_with(
189 name_contains=query, only_active=True)
191 name_contains=query, only_active=True)
190 groups_mock.assert_called_once_with(
192 groups_mock.assert_called_once_with(
191 name_contains=query, only_active=True)
193 name_contains=query, only_active=True)
192 assert len(result['suggestions']) == 20
194 assert len(result['suggestions']) == 20
193
195
194
196
195 def assert_and_get_content(result):
197 def assert_and_get_content(result):
196 repos = []
198 repos = []
197 groups = []
199 groups = []
198 commits = []
200 commits = []
199 for data in result:
201 for data in result:
200 for data_item in data['children']:
202 for data_item in data['children']:
201 assert data_item['id']
203 assert data_item['id']
202 assert data_item['text']
204 assert data_item['text']
203 assert data_item['url']
205 assert data_item['url']
204 if data_item['type'] == 'repo':
206 if data_item['type'] == 'repo':
205 repos.append(data_item)
207 repos.append(data_item)
206 elif data_item['type'] == 'group':
208 elif data_item['type'] == 'group':
207 groups.append(data_item)
209 groups.append(data_item)
208 elif data_item['type'] == 'commit':
210 elif data_item['type'] == 'commit':
209 commits.append(data_item)
211 commits.append(data_item)
210 else:
212 else:
211 raise Exception('invalid type %s' % data_item['type'])
213 raise Exception('invalid type %s' % data_item['type'])
212
214
213 return repos, groups, commits
215 return repos, groups, commits
214
216
215
217
216 class TestGotoSwitcherData(TestController):
218 class TestGotoSwitcherData(TestController):
217 required_repos_with_groups = [
219 required_repos_with_groups = [
218 'abc',
220 'abc',
219 'abc-fork',
221 'abc-fork',
220 'forks/abcd',
222 'forks/abcd',
221 'abcd',
223 'abcd',
222 'abcde',
224 'abcde',
223 'a/abc',
225 'a/abc',
224 'aa/abc',
226 'aa/abc',
225 'aaa/abc',
227 'aaa/abc',
226 'aaaa/abc',
228 'aaaa/abc',
227 'repos_abc/aaa/abc',
229 'repos_abc/aaa/abc',
228 'abc_repos/abc',
230 'abc_repos/abc',
229 'abc_repos/abcd',
231 'abc_repos/abcd',
230 'xxx/xyz',
232 'xxx/xyz',
231 'forked-abc/a/abc'
233 'forked-abc/a/abc'
232 ]
234 ]
233
235
234 @pytest.fixture(autouse=True, scope='class')
236 @pytest.fixture(autouse=True, scope='class')
235 def prepare(self, request, pylonsapp):
237 def prepare(self, request, pylonsapp):
236 for repo_and_group in self.required_repos_with_groups:
238 for repo_and_group in self.required_repos_with_groups:
237 # create structure of groups and return the last group
239 # create structure of groups and return the last group
238
240
239 repo_group = map_groups(repo_and_group)
241 repo_group = map_groups(repo_and_group)
240
242
241 RepoModel()._create_repo(
243 RepoModel()._create_repo(
242 repo_and_group, 'hg', 'test-ac', TEST_USER_ADMIN_LOGIN,
244 repo_and_group, 'hg', 'test-ac', TEST_USER_ADMIN_LOGIN,
243 repo_group=getattr(repo_group, 'group_id', None))
245 repo_group=getattr(repo_group, 'group_id', None))
244
246
245 Session().commit()
247 Session().commit()
246
248
247 request.addfinalizer(self.cleanup)
249 request.addfinalizer(self.cleanup)
248
250
249 def cleanup(self):
251 def cleanup(self):
250 # first delete all repos
252 # first delete all repos
251 for repo_and_groups in self.required_repos_with_groups:
253 for repo_and_groups in self.required_repos_with_groups:
252 repo = Repository.get_by_repo_name(repo_and_groups)
254 repo = Repository.get_by_repo_name(repo_and_groups)
253 if repo:
255 if repo:
254 RepoModel().delete(repo)
256 RepoModel().delete(repo)
255 Session().commit()
257 Session().commit()
256
258
257 # then delete all empty groups
259 # then delete all empty groups
258 for repo_and_groups in self.required_repos_with_groups:
260 for repo_and_groups in self.required_repos_with_groups:
259 if '/' in repo_and_groups:
261 if '/' in repo_and_groups:
260 r_group = repo_and_groups.rsplit('/', 1)[0]
262 r_group = repo_and_groups.rsplit('/', 1)[0]
261 repo_group = RepoGroup.get_by_group_name(r_group)
263 repo_group = RepoGroup.get_by_group_name(r_group)
262 if not repo_group:
264 if not repo_group:
263 continue
265 continue
264 parents = repo_group.parents
266 parents = repo_group.parents
265 RepoGroupModel().delete(repo_group, force_delete=True)
267 RepoGroupModel().delete(repo_group, force_delete=True)
266 Session().commit()
268 Session().commit()
267
269
268 for el in reversed(parents):
270 for el in reversed(parents):
269 RepoGroupModel().delete(el, force_delete=True)
271 RepoGroupModel().delete(el, force_delete=True)
270 Session().commit()
272 Session().commit()
271
273
272 def test_returns_list_of_repos_and_groups(self):
274 def test_returns_list_of_repos_and_groups(self):
273 self.log_user()
275 self.log_user()
274
276
275 response = self.app.get(
277 response = self.app.get(
276 url(controller='home', action='goto_switcher_data'),
278 url(controller='home', action='goto_switcher_data'),
277 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
279 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
278 result = json.loads(response.body)['results']
280 result = json.loads(response.body)['results']
279
281
280 repos, groups, commits = assert_and_get_content(result)
282 repos, groups, commits = assert_and_get_content(result)
281
283
282 assert len(repos) == len(Repository.get_all())
284 assert len(repos) == len(Repository.get_all())
283 assert len(groups) == len(RepoGroup.get_all())
285 assert len(groups) == len(RepoGroup.get_all())
284 assert len(commits) == 0
286 assert len(commits) == 0
285
287
286 def test_returns_list_of_repos_and_groups_filtered(self):
288 def test_returns_list_of_repos_and_groups_filtered(self):
287 self.log_user()
289 self.log_user()
288
290
289 response = self.app.get(
291 response = self.app.get(
290 url(controller='home', action='goto_switcher_data'),
292 url(controller='home', action='goto_switcher_data'),
291 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
293 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
292 params={'query': 'abc'}, status=200)
294 params={'query': 'abc'}, status=200)
293 result = json.loads(response.body)['results']
295 result = json.loads(response.body)['results']
294
296
295 repos, groups, commits = assert_and_get_content(result)
297 repos, groups, commits = assert_and_get_content(result)
296
298
297 assert len(repos) == 13
299 assert len(repos) == 13
298 assert len(groups) == 5
300 assert len(groups) == 5
299 assert len(commits) == 0
301 assert len(commits) == 0
300
302
301 def test_returns_list_of_properly_sorted_and_filtered(self):
303 def test_returns_list_of_properly_sorted_and_filtered(self):
302 self.log_user()
304 self.log_user()
303
305
304 response = self.app.get(
306 response = self.app.get(
305 url(controller='home', action='goto_switcher_data'),
307 url(controller='home', action='goto_switcher_data'),
306 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
308 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
307 params={'query': 'abc'}, status=200)
309 params={'query': 'abc'}, status=200)
308 result = json.loads(response.body)['results']
310 result = json.loads(response.body)['results']
309
311
310 repos, groups, commits = assert_and_get_content(result)
312 repos, groups, commits = assert_and_get_content(result)
311
313
312 test_repos = [x['text'] for x in repos[:4]]
314 test_repos = [x['text'] for x in repos[:4]]
313 assert ['abc', 'abcd', 'a/abc', 'abcde'] == test_repos
315 assert ['abc', 'abcd', 'a/abc', 'abcde'] == test_repos
314
316
315 test_groups = [x['text'] for x in groups[:4]]
317 test_groups = [x['text'] for x in groups[:4]]
316 assert ['abc_repos', 'repos_abc',
318 assert ['abc_repos', 'repos_abc',
317 'forked-abc', 'forked-abc/a'] == test_groups
319 'forked-abc', 'forked-abc/a'] == test_groups
318
320
319
321
320 class TestRepoListData(TestController):
322 class TestRepoListData(TestController):
321 def test_returns_list_of_repos_and_groups(self, user_util):
323 def test_returns_list_of_repos_and_groups(self, user_util):
322 self.log_user()
324 self.log_user()
323
325
324 response = self.app.get(
326 response = self.app.get(
325 url(controller='home', action='repo_list_data'),
327 url(controller='home', action='repo_list_data'),
326 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
328 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', }, status=200)
327 result = json.loads(response.body)['results']
329 result = json.loads(response.body)['results']
328
330
329 repos, groups, commits = assert_and_get_content(result)
331 repos, groups, commits = assert_and_get_content(result)
330
332
331 assert len(repos) == len(Repository.get_all())
333 assert len(repos) == len(Repository.get_all())
332 assert len(groups) == 0
334 assert len(groups) == 0
333 assert len(commits) == 0
335 assert len(commits) == 0
334
336
335 def test_returns_list_of_repos_and_groups_filtered(self):
337 def test_returns_list_of_repos_and_groups_filtered(self):
336 self.log_user()
338 self.log_user()
337
339
338 response = self.app.get(
340 response = self.app.get(
339 url(controller='home', action='repo_list_data'),
341 url(controller='home', action='repo_list_data'),
340 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
342 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
341 params={'query': 'vcs_test_git'}, status=200)
343 params={'query': 'vcs_test_git'}, status=200)
342 result = json.loads(response.body)['results']
344 result = json.loads(response.body)['results']
343
345
344 repos, groups, commits = assert_and_get_content(result)
346 repos, groups, commits = assert_and_get_content(result)
345
347
346 assert len(repos) == len(Repository.query().filter(
348 assert len(repos) == len(Repository.query().filter(
347 Repository.repo_name.ilike('%vcs_test_git%')).all())
349 Repository.repo_name.ilike('%vcs_test_git%')).all())
348 assert len(groups) == 0
350 assert len(groups) == 0
349 assert len(commits) == 0
351 assert len(commits) == 0
350
352
351 def test_returns_list_of_repos_and_groups_filtered_with_type(self):
353 def test_returns_list_of_repos_and_groups_filtered_with_type(self):
352 self.log_user()
354 self.log_user()
353
355
354 response = self.app.get(
356 response = self.app.get(
355 url(controller='home', action='repo_list_data'),
357 url(controller='home', action='repo_list_data'),
356 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
358 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
357 params={'query': 'vcs_test_git', 'repo_type': 'git'}, status=200)
359 params={'query': 'vcs_test_git', 'repo_type': 'git'}, status=200)
358 result = json.loads(response.body)['results']
360 result = json.loads(response.body)['results']
359
361
360 repos, groups, commits = assert_and_get_content(result)
362 repos, groups, commits = assert_and_get_content(result)
361
363
362 assert len(repos) == len(Repository.query().filter(
364 assert len(repos) == len(Repository.query().filter(
363 Repository.repo_name.ilike('%vcs_test_git%')).all())
365 Repository.repo_name.ilike('%vcs_test_git%')).all())
364 assert len(groups) == 0
366 assert len(groups) == 0
365 assert len(commits) == 0
367 assert len(commits) == 0
366
368
367 def test_returns_list_of_repos_non_ascii_query(self):
369 def test_returns_list_of_repos_non_ascii_query(self):
368 self.log_user()
370 self.log_user()
369 response = self.app.get(
371 response = self.app.get(
370 url(controller='home', action='repo_list_data'),
372 url(controller='home', action='repo_list_data'),
371 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
373 headers={'X-REQUESTED-WITH': 'XMLHttpRequest', },
372 params={'query': 'ć_vcs_test_ą', 'repo_type': 'git'}, status=200)
374 params={'query': 'ć_vcs_test_ą', 'repo_type': 'git'}, status=200)
373 result = json.loads(response.body)['results']
375 result = json.loads(response.body)['results']
374
376
375 repos, groups, commits = assert_and_get_content(result)
377 repos, groups, commits = assert_and_get_content(result)
376
378
377 assert len(repos) == 0
379 assert len(repos) == 0
378 assert len(groups) == 0
380 assert len(groups) == 0
379 assert len(commits) == 0
381 assert len(commits) == 0
General Comments 0
You need to be logged in to leave comments. Login now