Show More
@@ -1,371 +1,371 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | import os |
|
3 | import os | |
4 | import urllib |
|
4 | import urllib | |
5 |
|
5 | |||
6 | from rhodecode.lib import vcs |
|
6 | from rhodecode.lib import vcs | |
7 | from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\ |
|
7 | from rhodecode.model.db import Repository, RepoGroup, UserRepoToPerm, User,\ | |
8 | Permission |
|
8 | Permission | |
9 | from rhodecode.tests import * |
|
9 | from rhodecode.tests import * | |
10 | from rhodecode.model.repos_group import ReposGroupModel |
|
10 | from rhodecode.model.repos_group import ReposGroupModel | |
11 | from rhodecode.model.repo import RepoModel |
|
11 | from rhodecode.model.repo import RepoModel | |
12 | from rhodecode.model.meta import Session |
|
12 | from rhodecode.model.meta import Session | |
13 | from rhodecode.tests.fixture import Fixture |
|
13 | from rhodecode.tests.fixture import Fixture | |
14 |
|
14 | |||
15 | fixture = Fixture() |
|
15 | fixture = Fixture() | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | def _get_permission_for_user(user, repo): |
|
18 | def _get_permission_for_user(user, repo): | |
19 | perm = UserRepoToPerm.query()\ |
|
19 | perm = UserRepoToPerm.query()\ | |
20 | .filter(UserRepoToPerm.repository == |
|
20 | .filter(UserRepoToPerm.repository == | |
21 | Repository.get_by_repo_name(repo))\ |
|
21 | Repository.get_by_repo_name(repo))\ | |
22 | .filter(UserRepoToPerm.user == User.get_by_username(user))\ |
|
22 | .filter(UserRepoToPerm.user == User.get_by_username(user))\ | |
23 | .all() |
|
23 | .all() | |
24 | return perm |
|
24 | return perm | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | class TestAdminReposController(TestController): |
|
27 | class TestAdminReposController(TestController): | |
28 |
|
28 | |||
29 | def test_index(self): |
|
29 | def test_index(self): | |
30 | self.log_user() |
|
30 | self.log_user() | |
31 | response = self.app.get(url('repos')) |
|
31 | response = self.app.get(url('repos')) | |
32 | # Test response... |
|
32 | # Test response... | |
33 |
|
33 | |||
34 | def test_index_as_xml(self): |
|
34 | def test_index_as_xml(self): | |
35 | response = self.app.get(url('formatted_repos', format='xml')) |
|
35 | response = self.app.get(url('formatted_repos', format='xml')) | |
36 |
|
36 | |||
37 | def test_create_hg(self): |
|
37 | def test_create_hg(self): | |
38 | self.log_user() |
|
38 | self.log_user() | |
39 | repo_name = NEW_HG_REPO |
|
39 | repo_name = NEW_HG_REPO | |
40 | description = 'description for newly created repo' |
|
40 | description = 'description for newly created repo' | |
41 | response = self.app.post(url('repos'), |
|
41 | response = self.app.post(url('repos'), | |
42 | fixture._get_repo_create_params(repo_private=False, |
|
42 | fixture._get_repo_create_params(repo_private=False, | |
43 | repo_name=repo_name, |
|
43 | repo_name=repo_name, | |
44 | repo_description=description)) |
|
44 | repo_description=description)) | |
45 | self.checkSessionFlash(response, |
|
45 | self.checkSessionFlash(response, | |
46 | 'Created repository <a href="/%s">%s</a>' |
|
46 | 'Created repository <a href="/%s">%s</a>' | |
47 | % (repo_name, repo_name)) |
|
47 | % (repo_name, repo_name)) | |
48 |
|
48 | |||
49 | #test if the repo was created in the database |
|
49 | #test if the repo was created in the database | |
50 | new_repo = self.Session().query(Repository)\ |
|
50 | new_repo = self.Session().query(Repository)\ | |
51 | .filter(Repository.repo_name == repo_name).one() |
|
51 | .filter(Repository.repo_name == repo_name).one() | |
52 |
|
52 | |||
53 | self.assertEqual(new_repo.repo_name, repo_name) |
|
53 | self.assertEqual(new_repo.repo_name, repo_name) | |
54 | self.assertEqual(new_repo.description, description) |
|
54 | self.assertEqual(new_repo.description, description) | |
55 |
|
55 | |||
56 | #test if repository is visible in the list ? |
|
56 | #test if repository is visible in the list ? | |
57 | response = response.follow() |
|
57 | response = response.follow() | |
58 |
|
58 | |||
59 | response.mustcontain(repo_name) |
|
59 | response.mustcontain(repo_name) | |
60 |
|
60 | |||
61 | #test if repository was created on filesystem |
|
61 | #test if repository was created on filesystem | |
62 | try: |
|
62 | try: | |
63 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
63 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
64 | except Exception: |
|
64 | except Exception: | |
65 | self.fail('no repo %s in filesystem' % repo_name) |
|
65 | self.fail('no repo %s in filesystem' % repo_name) | |
66 |
|
66 | |||
67 | def test_create_hg_non_ascii(self): |
|
67 | def test_create_hg_non_ascii(self): | |
68 | self.log_user() |
|
68 | self.log_user() | |
69 | non_ascii = "Δ ΔΕ" |
|
69 | non_ascii = "Δ ΔΕ" | |
70 | repo_name = "%s%s" % (NEW_HG_REPO, non_ascii) |
|
70 | repo_name = "%s%s" % (NEW_HG_REPO, non_ascii) | |
71 | repo_name_unicode = repo_name.decode('utf8') |
|
71 | repo_name_unicode = repo_name.decode('utf8') | |
72 | description = 'description for newly created repo' + non_ascii |
|
72 | description = 'description for newly created repo' + non_ascii | |
73 | description_unicode = description.decode('utf8') |
|
73 | description_unicode = description.decode('utf8') | |
74 | private = False |
|
74 | private = False | |
75 | response = self.app.post(url('repos'), |
|
75 | response = self.app.post(url('repos'), | |
76 | fixture._get_repo_create_params(repo_private=False, |
|
76 | fixture._get_repo_create_params(repo_private=False, | |
77 | repo_name=repo_name, |
|
77 | repo_name=repo_name, | |
78 | repo_description=description)) |
|
78 | repo_description=description)) | |
79 | self.checkSessionFlash(response, |
|
79 | self.checkSessionFlash(response, | |
80 | u'Created repository <a href="/%s">%s</a>' |
|
80 | u'Created repository <a href="/%s">%s</a>' | |
81 | % (urllib.quote(repo_name), repo_name_unicode)) |
|
81 | % (urllib.quote(repo_name), repo_name_unicode)) | |
82 | #test if the repo was created in the database |
|
82 | #test if the repo was created in the database | |
83 | new_repo = self.Session().query(Repository)\ |
|
83 | new_repo = self.Session().query(Repository)\ | |
84 | .filter(Repository.repo_name == repo_name_unicode).one() |
|
84 | .filter(Repository.repo_name == repo_name_unicode).one() | |
85 |
|
85 | |||
86 | self.assertEqual(new_repo.repo_name, repo_name_unicode) |
|
86 | self.assertEqual(new_repo.repo_name, repo_name_unicode) | |
87 | self.assertEqual(new_repo.description, description_unicode) |
|
87 | self.assertEqual(new_repo.description, description_unicode) | |
88 |
|
88 | |||
89 | #test if repository is visible in the list ? |
|
89 | #test if repository is visible in the list ? | |
90 | response = response.follow() |
|
90 | response = response.follow() | |
91 |
|
91 | |||
92 | response.mustcontain(repo_name) |
|
92 | response.mustcontain(repo_name) | |
93 |
|
93 | |||
94 | #test if repository was created on filesystem |
|
94 | #test if repository was created on filesystem | |
95 | try: |
|
95 | try: | |
96 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
96 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
97 | except Exception: |
|
97 | except Exception: | |
98 | self.fail('no repo %s in filesystem' % repo_name) |
|
98 | self.fail('no repo %s in filesystem' % repo_name) | |
99 |
|
99 | |||
100 | def z(self): |
|
100 | def test_create_hg_in_group(self): | |
101 | self.log_user() |
|
101 | self.log_user() | |
102 |
|
102 | |||
103 | ## create GROUP |
|
103 | ## create GROUP | |
104 | group_name = 'sometest' |
|
104 | group_name = 'sometest' | |
105 | gr = ReposGroupModel().create(group_name=group_name, |
|
105 | gr = ReposGroupModel().create(group_name=group_name, | |
106 | group_description='test', |
|
106 | group_description='test', | |
107 | owner=TEST_USER_ADMIN_LOGIN) |
|
107 | owner=TEST_USER_ADMIN_LOGIN) | |
108 | self.Session().commit() |
|
108 | self.Session().commit() | |
109 |
|
109 | |||
110 | repo_name = 'ingroup' |
|
110 | repo_name = 'ingroup' | |
111 | repo_name_full = RepoGroup.url_sep().join([group_name, repo_name]) |
|
111 | repo_name_full = RepoGroup.url_sep().join([group_name, repo_name]) | |
112 | description = 'description for newly created repo' |
|
112 | description = 'description for newly created repo' | |
113 | response = self.app.post(url('repos'), |
|
113 | response = self.app.post(url('repos'), | |
114 | fixture._get_repo_create_params(repo_private=False, |
|
114 | fixture._get_repo_create_params(repo_private=False, | |
115 | repo_name=repo_name, |
|
115 | repo_name=repo_name, | |
116 | repo_description=description, |
|
116 | repo_description=description, | |
117 | repo_group=gr.group_id,)) |
|
117 | repo_group=gr.group_id,)) | |
118 |
|
118 | |||
119 | self.checkSessionFlash(response, |
|
119 | self.checkSessionFlash(response, | |
120 | 'Created repository <a href="/%s">%s</a>' |
|
120 | 'Created repository <a href="/%s">%s</a>' | |
121 | % (repo_name_full, repo_name)) |
|
121 | % (repo_name_full, repo_name)) | |
122 | #test if the repo was created in the database |
|
122 | #test if the repo was created in the database | |
123 | new_repo = self.Session().query(Repository)\ |
|
123 | new_repo = self.Session().query(Repository)\ | |
124 | .filter(Repository.repo_name == repo_name_full).one() |
|
124 | .filter(Repository.repo_name == repo_name_full).one() | |
125 |
|
125 | |||
126 | self.assertEqual(new_repo.repo_name, repo_name_full) |
|
126 | self.assertEqual(new_repo.repo_name, repo_name_full) | |
127 | self.assertEqual(new_repo.description, description) |
|
127 | self.assertEqual(new_repo.description, description) | |
128 |
|
128 | |||
129 | #test if repository is visible in the list ? |
|
129 | #test if repository is visible in the list ? | |
130 | response = response.follow() |
|
130 | response = response.follow() | |
131 |
|
131 | |||
132 | response.mustcontain(repo_name_full) |
|
132 | response.mustcontain(repo_name_full) | |
133 |
|
133 | |||
134 | #test if repository was created on filesystem |
|
134 | #test if repository was created on filesystem | |
135 | try: |
|
135 | try: | |
136 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full)) |
|
136 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name_full)) | |
137 | except Exception: |
|
137 | except Exception: | |
138 | ReposGroupModel().delete(group_name) |
|
138 | ReposGroupModel().delete(group_name) | |
139 | self.Session().commit() |
|
139 | self.Session().commit() | |
140 | self.fail('no repo %s in filesystem' % repo_name) |
|
140 | self.fail('no repo %s in filesystem' % repo_name) | |
141 |
|
141 | |||
142 | RepoModel().delete(repo_name_full) |
|
142 | RepoModel().delete(repo_name_full) | |
143 | ReposGroupModel().delete(group_name) |
|
143 | ReposGroupModel().delete(group_name) | |
144 | self.Session().commit() |
|
144 | self.Session().commit() | |
145 |
|
145 | |||
146 | def test_create_git(self): |
|
146 | def test_create_git(self): | |
147 | self.log_user() |
|
147 | self.log_user() | |
148 | repo_name = NEW_GIT_REPO |
|
148 | repo_name = NEW_GIT_REPO | |
149 | description = 'description for newly created repo' |
|
149 | description = 'description for newly created repo' | |
150 |
|
150 | |||
151 | response = self.app.post(url('repos'), |
|
151 | response = self.app.post(url('repos'), | |
152 | fixture._get_repo_create_params(repo_private=False, |
|
152 | fixture._get_repo_create_params(repo_private=False, | |
153 | repo_type='git', |
|
153 | repo_type='git', | |
154 | repo_name=repo_name, |
|
154 | repo_name=repo_name, | |
155 | repo_description=description)) |
|
155 | repo_description=description)) | |
156 | self.checkSessionFlash(response, |
|
156 | self.checkSessionFlash(response, | |
157 | 'Created repository <a href="/%s">%s</a>' |
|
157 | 'Created repository <a href="/%s">%s</a>' | |
158 | % (repo_name, repo_name)) |
|
158 | % (repo_name, repo_name)) | |
159 |
|
159 | |||
160 | #test if the repo was created in the database |
|
160 | #test if the repo was created in the database | |
161 | new_repo = self.Session().query(Repository)\ |
|
161 | new_repo = self.Session().query(Repository)\ | |
162 | .filter(Repository.repo_name == repo_name).one() |
|
162 | .filter(Repository.repo_name == repo_name).one() | |
163 |
|
163 | |||
164 | self.assertEqual(new_repo.repo_name, repo_name) |
|
164 | self.assertEqual(new_repo.repo_name, repo_name) | |
165 | self.assertEqual(new_repo.description, description) |
|
165 | self.assertEqual(new_repo.description, description) | |
166 |
|
166 | |||
167 | #test if repository is visible in the list ? |
|
167 | #test if repository is visible in the list ? | |
168 | response = response.follow() |
|
168 | response = response.follow() | |
169 |
|
169 | |||
170 | response.mustcontain(repo_name) |
|
170 | response.mustcontain(repo_name) | |
171 |
|
171 | |||
172 | #test if repository was created on filesystem |
|
172 | #test if repository was created on filesystem | |
173 | try: |
|
173 | try: | |
174 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
174 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
175 | except Exception: |
|
175 | except Exception: | |
176 | self.fail('no repo %s in filesystem' % repo_name) |
|
176 | self.fail('no repo %s in filesystem' % repo_name) | |
177 |
|
177 | |||
178 | def test_create_git_non_ascii(self): |
|
178 | def test_create_git_non_ascii(self): | |
179 | self.log_user() |
|
179 | self.log_user() | |
180 | non_ascii = "Δ ΔΕ" |
|
180 | non_ascii = "Δ ΔΕ" | |
181 | repo_name = "%s%s" % (NEW_GIT_REPO, non_ascii) |
|
181 | repo_name = "%s%s" % (NEW_GIT_REPO, non_ascii) | |
182 | repo_name_unicode = repo_name.decode('utf8') |
|
182 | repo_name_unicode = repo_name.decode('utf8') | |
183 | description = 'description for newly created repo' + non_ascii |
|
183 | description = 'description for newly created repo' + non_ascii | |
184 | description_unicode = description.decode('utf8') |
|
184 | description_unicode = description.decode('utf8') | |
185 | private = False |
|
185 | private = False | |
186 | response = self.app.post(url('repos'), |
|
186 | response = self.app.post(url('repos'), | |
187 | fixture._get_repo_create_params(repo_private=False, |
|
187 | fixture._get_repo_create_params(repo_private=False, | |
188 | repo_type='git', |
|
188 | repo_type='git', | |
189 | repo_name=repo_name, |
|
189 | repo_name=repo_name, | |
190 | repo_description=description)) |
|
190 | repo_description=description)) | |
191 |
|
191 | |||
192 | self.checkSessionFlash(response, |
|
192 | self.checkSessionFlash(response, | |
193 | u'Created repository <a href="/%s">%s</a>' |
|
193 | u'Created repository <a href="/%s">%s</a>' | |
194 | % (urllib.quote(repo_name), repo_name_unicode)) |
|
194 | % (urllib.quote(repo_name), repo_name_unicode)) | |
195 |
|
195 | |||
196 | #test if the repo was created in the database |
|
196 | #test if the repo was created in the database | |
197 | new_repo = self.Session().query(Repository)\ |
|
197 | new_repo = self.Session().query(Repository)\ | |
198 | .filter(Repository.repo_name == repo_name_unicode).one() |
|
198 | .filter(Repository.repo_name == repo_name_unicode).one() | |
199 |
|
199 | |||
200 | self.assertEqual(new_repo.repo_name, repo_name_unicode) |
|
200 | self.assertEqual(new_repo.repo_name, repo_name_unicode) | |
201 | self.assertEqual(new_repo.description, description_unicode) |
|
201 | self.assertEqual(new_repo.description, description_unicode) | |
202 |
|
202 | |||
203 | #test if repository is visible in the list ? |
|
203 | #test if repository is visible in the list ? | |
204 | response = response.follow() |
|
204 | response = response.follow() | |
205 |
|
205 | |||
206 | response.mustcontain(repo_name) |
|
206 | response.mustcontain(repo_name) | |
207 |
|
207 | |||
208 | #test if repository was created on filesystem |
|
208 | #test if repository was created on filesystem | |
209 | try: |
|
209 | try: | |
210 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
210 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
211 | except Exception: |
|
211 | except Exception: | |
212 | self.fail('no repo %s in filesystem' % repo_name) |
|
212 | self.fail('no repo %s in filesystem' % repo_name) | |
213 |
|
213 | |||
214 | def test_update(self): |
|
214 | def test_update(self): | |
215 | response = self.app.put(url('repo', repo_name=HG_REPO)) |
|
215 | response = self.app.put(url('repo', repo_name=HG_REPO)) | |
216 |
|
216 | |||
217 | def test_update_browser_fakeout(self): |
|
217 | def test_update_browser_fakeout(self): | |
218 | response = self.app.post(url('repo', repo_name=HG_REPO), |
|
218 | response = self.app.post(url('repo', repo_name=HG_REPO), | |
219 | params=dict(_method='put')) |
|
219 | params=dict(_method='put')) | |
220 |
|
220 | |||
221 | def test_delete_hg(self): |
|
221 | def test_delete_hg(self): | |
222 | self.log_user() |
|
222 | self.log_user() | |
223 | repo_name = 'vcs_test_new_to_delete' |
|
223 | repo_name = 'vcs_test_new_to_delete' | |
224 | description = 'description for newly created repo' |
|
224 | description = 'description for newly created repo' | |
225 | response = self.app.post(url('repos'), |
|
225 | response = self.app.post(url('repos'), | |
226 | fixture._get_repo_create_params(repo_private=False, |
|
226 | fixture._get_repo_create_params(repo_private=False, | |
227 | repo_type='hg', |
|
227 | repo_type='hg', | |
228 | repo_name=repo_name, |
|
228 | repo_name=repo_name, | |
229 | repo_description=description)) |
|
229 | repo_description=description)) | |
230 |
|
230 | |||
231 | self.checkSessionFlash(response, |
|
231 | self.checkSessionFlash(response, | |
232 | 'Created repository <a href="/%s">%s</a>' |
|
232 | 'Created repository <a href="/%s">%s</a>' | |
233 | % (repo_name, repo_name)) |
|
233 | % (repo_name, repo_name)) | |
234 | #test if the repo was created in the database |
|
234 | #test if the repo was created in the database | |
235 | new_repo = self.Session().query(Repository)\ |
|
235 | new_repo = self.Session().query(Repository)\ | |
236 | .filter(Repository.repo_name == repo_name).one() |
|
236 | .filter(Repository.repo_name == repo_name).one() | |
237 |
|
237 | |||
238 | self.assertEqual(new_repo.repo_name, repo_name) |
|
238 | self.assertEqual(new_repo.repo_name, repo_name) | |
239 | self.assertEqual(new_repo.description, description) |
|
239 | self.assertEqual(new_repo.description, description) | |
240 |
|
240 | |||
241 | #test if repository is visible in the list ? |
|
241 | #test if repository is visible in the list ? | |
242 | response = response.follow() |
|
242 | response = response.follow() | |
243 |
|
243 | |||
244 | response.mustcontain(repo_name) |
|
244 | response.mustcontain(repo_name) | |
245 |
|
245 | |||
246 | #test if repository was created on filesystem |
|
246 | #test if repository was created on filesystem | |
247 | try: |
|
247 | try: | |
248 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
248 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
249 | except Exception: |
|
249 | except Exception: | |
250 | self.fail('no repo %s in filesystem' % repo_name) |
|
250 | self.fail('no repo %s in filesystem' % repo_name) | |
251 |
|
251 | |||
252 | response = self.app.delete(url('repo', repo_name=repo_name)) |
|
252 | response = self.app.delete(url('repo', repo_name=repo_name)) | |
253 |
|
253 | |||
254 | self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name)) |
|
254 | self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name)) | |
255 |
|
255 | |||
256 | response.follow() |
|
256 | response.follow() | |
257 |
|
257 | |||
258 | #check if repo was deleted from db |
|
258 | #check if repo was deleted from db | |
259 | deleted_repo = self.Session().query(Repository)\ |
|
259 | deleted_repo = self.Session().query(Repository)\ | |
260 | .filter(Repository.repo_name == repo_name).scalar() |
|
260 | .filter(Repository.repo_name == repo_name).scalar() | |
261 |
|
261 | |||
262 | self.assertEqual(deleted_repo, None) |
|
262 | self.assertEqual(deleted_repo, None) | |
263 |
|
263 | |||
264 | self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)), |
|
264 | self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)), | |
265 | False) |
|
265 | False) | |
266 |
|
266 | |||
267 | def test_delete_git(self): |
|
267 | def test_delete_git(self): | |
268 | self.log_user() |
|
268 | self.log_user() | |
269 | repo_name = 'vcs_test_new_to_delete' |
|
269 | repo_name = 'vcs_test_new_to_delete' | |
270 | description = 'description for newly created repo' |
|
270 | description = 'description for newly created repo' | |
271 | private = False |
|
271 | private = False | |
272 | response = self.app.post(url('repos'), |
|
272 | response = self.app.post(url('repos'), | |
273 | fixture._get_repo_create_params(repo_private=False, |
|
273 | fixture._get_repo_create_params(repo_private=False, | |
274 | repo_type='git', |
|
274 | repo_type='git', | |
275 | repo_name=repo_name, |
|
275 | repo_name=repo_name, | |
276 | repo_description=description)) |
|
276 | repo_description=description)) | |
277 |
|
277 | |||
278 | self.checkSessionFlash(response, |
|
278 | self.checkSessionFlash(response, | |
279 | 'Created repository <a href="/%s">%s</a>' |
|
279 | 'Created repository <a href="/%s">%s</a>' | |
280 | % (repo_name, repo_name)) |
|
280 | % (repo_name, repo_name)) | |
281 | #test if the repo was created in the database |
|
281 | #test if the repo was created in the database | |
282 | new_repo = self.Session().query(Repository)\ |
|
282 | new_repo = self.Session().query(Repository)\ | |
283 | .filter(Repository.repo_name == repo_name).one() |
|
283 | .filter(Repository.repo_name == repo_name).one() | |
284 |
|
284 | |||
285 | self.assertEqual(new_repo.repo_name, repo_name) |
|
285 | self.assertEqual(new_repo.repo_name, repo_name) | |
286 | self.assertEqual(new_repo.description, description) |
|
286 | self.assertEqual(new_repo.description, description) | |
287 |
|
287 | |||
288 | #test if repository is visible in the list ? |
|
288 | #test if repository is visible in the list ? | |
289 | response = response.follow() |
|
289 | response = response.follow() | |
290 |
|
290 | |||
291 | response.mustcontain(repo_name) |
|
291 | response.mustcontain(repo_name) | |
292 |
|
292 | |||
293 | #test if repository was created on filesystem |
|
293 | #test if repository was created on filesystem | |
294 | try: |
|
294 | try: | |
295 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) |
|
295 | vcs.get_repo(os.path.join(TESTS_TMP_PATH, repo_name)) | |
296 | except Exception: |
|
296 | except Exception: | |
297 | self.fail('no repo %s in filesystem' % repo_name) |
|
297 | self.fail('no repo %s in filesystem' % repo_name) | |
298 |
|
298 | |||
299 | response = self.app.delete(url('repo', repo_name=repo_name)) |
|
299 | response = self.app.delete(url('repo', repo_name=repo_name)) | |
300 |
|
300 | |||
301 | self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name)) |
|
301 | self.checkSessionFlash(response, 'Deleted repository %s' % (repo_name)) | |
302 |
|
302 | |||
303 | response.follow() |
|
303 | response.follow() | |
304 |
|
304 | |||
305 | #check if repo was deleted from db |
|
305 | #check if repo was deleted from db | |
306 | deleted_repo = self.Session().query(Repository)\ |
|
306 | deleted_repo = self.Session().query(Repository)\ | |
307 | .filter(Repository.repo_name == repo_name).scalar() |
|
307 | .filter(Repository.repo_name == repo_name).scalar() | |
308 |
|
308 | |||
309 | self.assertEqual(deleted_repo, None) |
|
309 | self.assertEqual(deleted_repo, None) | |
310 |
|
310 | |||
311 | self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)), |
|
311 | self.assertEqual(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name)), | |
312 | False) |
|
312 | False) | |
313 |
|
313 | |||
314 | def test_delete_repo_with_group(self): |
|
314 | def test_delete_repo_with_group(self): | |
315 | #TODO: |
|
315 | #TODO: | |
316 | pass |
|
316 | pass | |
317 |
|
317 | |||
318 | def test_delete_browser_fakeout(self): |
|
318 | def test_delete_browser_fakeout(self): | |
319 | response = self.app.post(url('repo', repo_name=HG_REPO), |
|
319 | response = self.app.post(url('repo', repo_name=HG_REPO), | |
320 | params=dict(_method='delete')) |
|
320 | params=dict(_method='delete')) | |
321 |
|
321 | |||
322 | def test_show_hg(self): |
|
322 | def test_show_hg(self): | |
323 | self.log_user() |
|
323 | self.log_user() | |
324 | response = self.app.get(url('repo', repo_name=HG_REPO)) |
|
324 | response = self.app.get(url('repo', repo_name=HG_REPO)) | |
325 |
|
325 | |||
326 | def test_show_git(self): |
|
326 | def test_show_git(self): | |
327 | self.log_user() |
|
327 | self.log_user() | |
328 | response = self.app.get(url('repo', repo_name=GIT_REPO)) |
|
328 | response = self.app.get(url('repo', repo_name=GIT_REPO)) | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | def test_edit(self): |
|
331 | def test_edit(self): | |
332 | response = self.app.get(url('edit_repo', repo_name=HG_REPO)) |
|
332 | response = self.app.get(url('edit_repo', repo_name=HG_REPO)) | |
333 |
|
333 | |||
334 | def test_set_private_flag_sets_default_to_none(self): |
|
334 | def test_set_private_flag_sets_default_to_none(self): | |
335 | self.log_user() |
|
335 | self.log_user() | |
336 | #initially repository perm should be read |
|
336 | #initially repository perm should be read | |
337 | perm = _get_permission_for_user(user='default', repo=HG_REPO) |
|
337 | perm = _get_permission_for_user(user='default', repo=HG_REPO) | |
338 | self.assertTrue(len(perm), 1) |
|
338 | self.assertTrue(len(perm), 1) | |
339 | self.assertEqual(perm[0].permission.permission_name, 'repository.read') |
|
339 | self.assertEqual(perm[0].permission.permission_name, 'repository.read') | |
340 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False) |
|
340 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False) | |
341 |
|
341 | |||
342 | response = self.app.put(url('repo', repo_name=HG_REPO), |
|
342 | response = self.app.put(url('repo', repo_name=HG_REPO), | |
343 | fixture._get_repo_create_params(repo_private=1, |
|
343 | fixture._get_repo_create_params(repo_private=1, | |
344 | repo_name=HG_REPO, |
|
344 | repo_name=HG_REPO, | |
345 | user=TEST_USER_ADMIN_LOGIN)) |
|
345 | user=TEST_USER_ADMIN_LOGIN)) | |
346 | self.checkSessionFlash(response, |
|
346 | self.checkSessionFlash(response, | |
347 | msg='Repository %s updated successfully' % (HG_REPO)) |
|
347 | msg='Repository %s updated successfully' % (HG_REPO)) | |
348 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, True) |
|
348 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, True) | |
349 |
|
349 | |||
350 | #now the repo default permission should be None |
|
350 | #now the repo default permission should be None | |
351 | perm = _get_permission_for_user(user='default', repo=HG_REPO) |
|
351 | perm = _get_permission_for_user(user='default', repo=HG_REPO) | |
352 | self.assertTrue(len(perm), 1) |
|
352 | self.assertTrue(len(perm), 1) | |
353 | self.assertEqual(perm[0].permission.permission_name, 'repository.none') |
|
353 | self.assertEqual(perm[0].permission.permission_name, 'repository.none') | |
354 |
|
354 | |||
355 | response = self.app.put(url('repo', repo_name=HG_REPO), |
|
355 | response = self.app.put(url('repo', repo_name=HG_REPO), | |
356 | fixture._get_repo_create_params(repo_private=False, |
|
356 | fixture._get_repo_create_params(repo_private=False, | |
357 | repo_name=HG_REPO, |
|
357 | repo_name=HG_REPO, | |
358 | user=TEST_USER_ADMIN_LOGIN)) |
|
358 | user=TEST_USER_ADMIN_LOGIN)) | |
359 | self.checkSessionFlash(response, |
|
359 | self.checkSessionFlash(response, | |
360 | msg='Repository %s updated successfully' % (HG_REPO)) |
|
360 | msg='Repository %s updated successfully' % (HG_REPO)) | |
361 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False) |
|
361 | self.assertEqual(Repository.get_by_repo_name(HG_REPO).private, False) | |
362 |
|
362 | |||
363 | #we turn off private now the repo default permission should stay None |
|
363 | #we turn off private now the repo default permission should stay None | |
364 | perm = _get_permission_for_user(user='default', repo=HG_REPO) |
|
364 | perm = _get_permission_for_user(user='default', repo=HG_REPO) | |
365 | self.assertTrue(len(perm), 1) |
|
365 | self.assertTrue(len(perm), 1) | |
366 | self.assertEqual(perm[0].permission.permission_name, 'repository.none') |
|
366 | self.assertEqual(perm[0].permission.permission_name, 'repository.none') | |
367 |
|
367 | |||
368 | #update this permission back |
|
368 | #update this permission back | |
369 | perm[0].permission = Permission.get_by_key('repository.read') |
|
369 | perm[0].permission = Permission.get_by_key('repository.read') | |
370 | Session().add(perm[0]) |
|
370 | Session().add(perm[0]) | |
371 | Session().commit() |
|
371 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now