Show More
@@ -1,298 +1,297 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | # This program is free software: you can redistribute it and/or modify |
|
3 | 3 | # it under the terms of the GNU General Public License as published by |
|
4 | 4 | # the Free Software Foundation, either version 3 of the License, or |
|
5 | 5 | # (at your option) any later version. |
|
6 | 6 | # |
|
7 | 7 | # This program is distributed in the hope that it will be useful, |
|
8 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | # GNU General Public License for more details. |
|
11 | 11 | # |
|
12 | 12 | # You should have received a copy of the GNU General Public License |
|
13 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | |
|
15 | 15 | """ |
|
16 | 16 | Helpers for fixture generation |
|
17 | 17 | """ |
|
18 | 18 | import os |
|
19 | 19 | import time |
|
20 | 20 | from kallithea.tests import * |
|
21 | 21 | from kallithea.model.db import Repository, User, RepoGroup, UserGroup |
|
22 | 22 | from kallithea.model.meta import Session |
|
23 | 23 | from kallithea.model.repo import RepoModel |
|
24 | 24 | from kallithea.model.user import UserModel |
|
25 | 25 | from kallithea.model.repo_group import RepoGroupModel |
|
26 | 26 | from kallithea.model.user_group import UserGroupModel |
|
27 | 27 | from kallithea.model.gist import GistModel |
|
28 | 28 | from kallithea.model.scm import ScmModel |
|
29 | 29 | from kallithea.lib.vcs.backends.base import EmptyChangeset |
|
30 | 30 | |
|
31 | 31 | dn = os.path.dirname |
|
32 | 32 | FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'tests', 'fixtures') |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | def error_function(*args, **kwargs): |
|
36 | 36 | raise Exception('Total Crash !') |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class Fixture(object): |
|
40 | 40 | |
|
41 | 41 | def __init__(self): |
|
42 | 42 | pass |
|
43 | 43 | |
|
44 | 44 | def anon_access(self, status): |
|
45 | 45 | """ |
|
46 | 46 | Context manager for controlling anonymous access. |
|
47 | 47 | Anon access will be set and committed, but restored again when exiting the block. |
|
48 | 48 | |
|
49 | 49 | Usage: |
|
50 | 50 | |
|
51 | 51 | fixture = Fixture() |
|
52 | 52 | with fixture.anon_access(False): |
|
53 | 53 | stuff |
|
54 | 54 | """ |
|
55 | 55 | |
|
56 | 56 | class context(object): |
|
57 | 57 | def __enter__(self): |
|
58 | 58 | anon = User.get_default_user() |
|
59 | 59 | self._before = anon.active |
|
60 | 60 | anon.active = status |
|
61 | 61 | Session().add(anon) |
|
62 | 62 | Session().commit() |
|
63 | 63 | time.sleep(1.5) # hack: wait for beaker sql_cache_short to expire |
|
64 | 64 | |
|
65 | 65 | def __exit__(self, exc_type, exc_val, exc_tb): |
|
66 | 66 | anon = User.get_default_user() |
|
67 | 67 | anon.active = self._before |
|
68 | 68 | Session().add(anon) |
|
69 | 69 | Session().commit() |
|
70 | 70 | |
|
71 | 71 | return context() |
|
72 | 72 | |
|
73 | 73 | def _get_repo_create_params(self, **custom): |
|
74 | 74 | defs = dict( |
|
75 | 75 | repo_name=None, |
|
76 | 76 | repo_type='hg', |
|
77 | 77 | clone_uri='', |
|
78 | 78 | repo_group=u'-1', |
|
79 | 79 | repo_description='DESC', |
|
80 | 80 | repo_private=False, |
|
81 | 81 | repo_landing_rev='rev:tip', |
|
82 | 82 | repo_copy_permissions=False, |
|
83 | 83 | repo_state=Repository.STATE_CREATED, |
|
84 | 84 | ) |
|
85 | 85 | defs.update(custom) |
|
86 | 86 | if 'repo_name_full' not in custom: |
|
87 | 87 | defs.update({'repo_name_full': defs['repo_name']}) |
|
88 | 88 | |
|
89 | 89 | # fix the repo name if passed as repo_name_full |
|
90 | 90 | if defs['repo_name']: |
|
91 | 91 | defs['repo_name'] = defs['repo_name'].split('/')[-1] |
|
92 | 92 | |
|
93 | 93 | return defs |
|
94 | 94 | |
|
95 | 95 | def _get_group_create_params(self, **custom): |
|
96 | 96 | defs = dict( |
|
97 | 97 | group_name=None, |
|
98 | 98 | group_description='DESC', |
|
99 | 99 | group_parent_id=None, |
|
100 | 100 | perms_updates=[], |
|
101 | 101 | perms_new=[], |
|
102 | 102 | enable_locking=False, |
|
103 | 103 | recursive=False |
|
104 | 104 | ) |
|
105 | 105 | defs.update(custom) |
|
106 | 106 | |
|
107 | 107 | return defs |
|
108 | 108 | |
|
109 | 109 | def _get_user_create_params(self, name, **custom): |
|
110 | 110 | defs = dict( |
|
111 | 111 | username=name, |
|
112 | 112 | password='qweqwe', |
|
113 | 113 | email='%s+test@example.com' % name, |
|
114 | 114 | firstname='TestUser', |
|
115 | 115 | lastname='Test', |
|
116 | 116 | active=True, |
|
117 | 117 | admin=False, |
|
118 | 118 | extern_type='internal', |
|
119 | 119 | extern_name=None |
|
120 | 120 | ) |
|
121 | 121 | defs.update(custom) |
|
122 | 122 | |
|
123 | 123 | return defs |
|
124 | 124 | |
|
125 | 125 | def _get_user_group_create_params(self, name, **custom): |
|
126 | 126 | defs = dict( |
|
127 | 127 | users_group_name=name, |
|
128 | 128 | user_group_description='DESC', |
|
129 | 129 | users_group_active=True, |
|
130 | 130 | user_group_data={}, |
|
131 | 131 | ) |
|
132 | 132 | defs.update(custom) |
|
133 | 133 | |
|
134 | 134 | return defs |
|
135 | 135 | |
|
136 | 136 | def create_repo(self, name, **kwargs): |
|
137 | 137 | if 'skip_if_exists' in kwargs: |
|
138 | 138 | del kwargs['skip_if_exists'] |
|
139 | 139 | r = Repository.get_by_repo_name(name) |
|
140 | 140 | if r: |
|
141 | 141 | return r |
|
142 | 142 | |
|
143 | 143 | if isinstance(kwargs.get('repo_group'), RepoGroup): |
|
144 | 144 | kwargs['repo_group'] = kwargs['repo_group'].group_id |
|
145 | 145 | |
|
146 | 146 | form_data = self._get_repo_create_params(repo_name=name, **kwargs) |
|
147 | 147 | cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
|
148 | 148 | RepoModel().create(form_data, cur_user) |
|
149 | 149 | Session().commit() |
|
150 | 150 | return Repository.get_by_repo_name(name) |
|
151 | 151 | |
|
152 | 152 | def create_fork(self, repo_to_fork, fork_name, **kwargs): |
|
153 | 153 | repo_to_fork = Repository.get_by_repo_name(repo_to_fork) |
|
154 | 154 | |
|
155 | 155 | form_data = self._get_repo_create_params(repo_name=fork_name, |
|
156 | 156 | fork_parent_id=repo_to_fork, |
|
157 | 157 | repo_type=repo_to_fork.repo_type, |
|
158 | 158 | **kwargs) |
|
159 | 159 | form_data['update_after_clone'] = False |
|
160 | 160 | |
|
161 | 161 | #TODO: fix it !! |
|
162 | 162 | form_data['description'] = form_data['repo_description'] |
|
163 | 163 | form_data['private'] = form_data['repo_private'] |
|
164 | 164 | form_data['landing_rev'] = form_data['repo_landing_rev'] |
|
165 | 165 | |
|
166 | 166 | owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
|
167 | 167 | RepoModel().create_fork(form_data, cur_user=owner) |
|
168 | 168 | Session().commit() |
|
169 | 169 | r = Repository.get_by_repo_name(fork_name) |
|
170 | 170 | assert r |
|
171 | 171 | return r |
|
172 | 172 | |
|
173 | 173 | def destroy_repo(self, repo_name, **kwargs): |
|
174 | 174 | RepoModel().delete(repo_name, **kwargs) |
|
175 | 175 | Session().commit() |
|
176 | 176 | |
|
177 | 177 | def create_repo_group(self, name, **kwargs): |
|
178 | 178 | if 'skip_if_exists' in kwargs: |
|
179 | 179 | del kwargs['skip_if_exists'] |
|
180 | 180 | gr = RepoGroup.get_by_group_name(group_name=name) |
|
181 | 181 | if gr: |
|
182 | 182 | return gr |
|
183 | 183 | form_data = self._get_group_create_params(group_name=name, **kwargs) |
|
184 | 184 | owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
|
185 | 185 | gr = RepoGroupModel().create( |
|
186 | 186 | group_name=form_data['group_name'], |
|
187 | 187 | group_description=form_data['group_name'], |
|
188 | 188 | owner=owner, parent=form_data['group_parent_id']) |
|
189 | 189 | Session().commit() |
|
190 | 190 | gr = RepoGroup.get_by_group_name(gr.group_name) |
|
191 | 191 | return gr |
|
192 | 192 | |
|
193 | 193 | def destroy_repo_group(self, repogroupid): |
|
194 | 194 | RepoGroupModel().delete(repogroupid) |
|
195 | 195 | Session().commit() |
|
196 | 196 | |
|
197 | 197 | def create_user(self, name, **kwargs): |
|
198 | 198 | if 'skip_if_exists' in kwargs: |
|
199 | 199 | del kwargs['skip_if_exists'] |
|
200 | 200 | user = User.get_by_username(name) |
|
201 | 201 | if user: |
|
202 | 202 | return user |
|
203 | 203 | form_data = self._get_user_create_params(name, **kwargs) |
|
204 | 204 | user = UserModel().create(form_data) |
|
205 | 205 | Session().commit() |
|
206 | 206 | user = User.get_by_username(user.username) |
|
207 | 207 | return user |
|
208 | 208 | |
|
209 | 209 | def destroy_user(self, userid): |
|
210 | 210 | UserModel().delete(userid) |
|
211 | 211 | Session().commit() |
|
212 | 212 | |
|
213 | 213 | def create_user_group(self, name, **kwargs): |
|
214 | 214 | if 'skip_if_exists' in kwargs: |
|
215 | 215 | del kwargs['skip_if_exists'] |
|
216 | 216 | gr = UserGroup.get_by_group_name(group_name=name) |
|
217 | 217 | if gr: |
|
218 | 218 | return gr |
|
219 | 219 | form_data = self._get_user_group_create_params(name, **kwargs) |
|
220 | 220 | owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
|
221 | 221 | user_group = UserGroupModel().create( |
|
222 | 222 | name=form_data['users_group_name'], |
|
223 | 223 | description=form_data['user_group_description'], |
|
224 | 224 | owner=owner, active=form_data['users_group_active'], |
|
225 | 225 | group_data=form_data['user_group_data']) |
|
226 | 226 | Session().commit() |
|
227 | 227 | user_group = UserGroup.get_by_group_name(user_group.users_group_name) |
|
228 | 228 | return user_group |
|
229 | 229 | |
|
230 | 230 | def destroy_user_group(self, usergroupid): |
|
231 | 231 | UserGroupModel().delete(user_group=usergroupid, force=True) |
|
232 | 232 | Session().commit() |
|
233 | 233 | |
|
234 | 234 | def create_gist(self, **kwargs): |
|
235 | 235 | form_data = { |
|
236 | 236 | 'description': u'new-gist', |
|
237 | 237 | 'owner': TEST_USER_ADMIN_LOGIN, |
|
238 | 238 | 'gist_type': GistModel.cls.GIST_PUBLIC, |
|
239 | 239 | 'lifetime': -1, |
|
240 | 240 | 'gist_mapping': {'filename1.txt':{'content':'hello world'},} |
|
241 | 241 | } |
|
242 | 242 | form_data.update(kwargs) |
|
243 | 243 | gist = GistModel().create( |
|
244 | 244 | description=form_data['description'],owner=form_data['owner'], |
|
245 | 245 | gist_mapping=form_data['gist_mapping'], gist_type=form_data['gist_type'], |
|
246 | 246 | lifetime=form_data['lifetime'] |
|
247 | 247 | ) |
|
248 | 248 | Session().commit() |
|
249 | 249 | |
|
250 | 250 | return gist |
|
251 | 251 | |
|
252 | 252 | def destroy_gists(self, gistid=None): |
|
253 | 253 | for g in GistModel.cls.get_all(): |
|
254 | 254 | if gistid: |
|
255 | 255 | if gistid == g.gist_access_id: |
|
256 | 256 | GistModel().delete(g) |
|
257 | 257 | else: |
|
258 | 258 | GistModel().delete(g) |
|
259 | 259 | Session().commit() |
|
260 | 260 | |
|
261 | 261 | def load_resource(self, resource_name, strip=True): |
|
262 | 262 | with open(os.path.join(FIXTURES, resource_name)) as f: |
|
263 | 263 | source = f.read() |
|
264 | 264 | if strip: |
|
265 | 265 | source = source.strip() |
|
266 | 266 | |
|
267 | 267 | return source |
|
268 | 268 | |
|
269 | 269 | def commit_change(self, repo, filename, content, message, vcs_type, parent=None, newfile=False): |
|
270 | 270 | repo = Repository.get_by_repo_name(repo) |
|
271 | 271 | _cs = parent |
|
272 | 272 | if not parent: |
|
273 | 273 | _cs = EmptyChangeset(alias=vcs_type) |
|
274 | 274 | |
|
275 | 275 | if newfile: |
|
276 | 276 | nodes = { |
|
277 | 277 | filename: { |
|
278 | 278 | 'content': content |
|
279 | 279 | } |
|
280 | 280 | } |
|
281 | 281 | cs = ScmModel().create_nodes( |
|
282 | 282 | user=TEST_USER_ADMIN_LOGIN, repo=repo, |
|
283 | 283 | message=message, |
|
284 | 284 | nodes=nodes, |
|
285 | 285 | parent_cs=_cs, |
|
286 | 286 | author=TEST_USER_ADMIN_LOGIN, |
|
287 | 287 | ) |
|
288 | 288 | else: |
|
289 | 289 | cs = ScmModel().commit_change( |
|
290 | 290 | repo=repo.scm_instance, repo_name=repo.repo_name, |
|
291 | 291 | cs=parent, user=TEST_USER_ADMIN_LOGIN, |
|
292 | 292 | author=TEST_USER_ADMIN_LOGIN, |
|
293 | 293 | message=message, |
|
294 | 294 | content=content, |
|
295 | 295 | f_path=filename |
|
296 | 296 | ) |
|
297 | 297 | return cs |
|
298 |
@@ -1,20 +1,20 b'' | |||
|
1 | 1 | #!/bin/bash -x |
|
2 | 2 | |
|
3 | 3 | # Enforce some consistency in whitespace - just to avoid spurious whitespaces changes |
|
4 | 4 | |
|
5 | 5 | files=`hg loc '*.py' '*.html' '*.css' '*.rst' '*.txt' '*.js' | egrep -v '/lockfiles.py|LICENSE-MERGELY.html|/codemirror/|/fontello/|(graph|mergely|native.history|select2/select2|yui.flot|yui.2.9)\.js$'` |
|
6 | sed -i "s,`printf '\t'`, ,g" $files | |
|
7 | sed -i "s, *$,,g" $files | |
|
8 | # add trailing newline if missing: | |
|
9 | sed -i '$a\' $files | |
|
6 | sed -i -e "s,`printf '\t'`, ,g" $files | |
|
7 | sed -i -e "s, *$,,g" $files | |
|
8 | # ensure one trailing newline - remove empty last line and make last line include trailing newline: | |
|
9 | sed -i -e '$,${/^$/d}' -e '$a\' $files | |
|
10 | 10 | |
|
11 | sed -i 's,\([^ /]\){,\1 {,g' `hg loc '*.css'` | |
|
12 | sed -i 's|^\([^ /].*,\)\([^ ]\)|\1 \2|g' `hg loc '*.css'` | |
|
11 | sed -i -e 's,\([^ /]\){,\1 {,g' `hg loc '*.css'` | |
|
12 | sed -i -e 's|^\([^ /].*,\)\([^ ]\)|\1 \2|g' `hg loc '*.css'` | |
|
13 | 13 | |
|
14 | sed -i 's/^\( [^: ]*\) *: *\([^/]\)/\1: \2/g' kallithea/public/css/{style,contextbar}.css | |
|
15 | sed -i '1s|, |,|g' kallithea/public/css/{style,contextbar}.css | |
|
16 | sed -i 's/^\([^ ,/]\+ [^,]*[^ ,]\) *, *\(.\)/\1,\n\2/g' kallithea/public/css/{style,contextbar}.css | |
|
17 | sed -i 's/^\([^ ,/].*\) */\1 /g' kallithea/public/css/{style,contextbar}.css | |
|
18 | sed -i 's,^--$,-- ,g' kallithea/templates/email_templates/main.txt | |
|
14 | sed -i -e 's/^\( [^: ]*\) *: *\([^/]\)/\1: \2/g' kallithea/public/css/{style,contextbar}.css | |
|
15 | sed -i -e '1s|, |,|g' kallithea/public/css/{style,contextbar}.css | |
|
16 | sed -i -e 's/^\([^ ,/]\+ [^,]*[^ ,]\) *, *\(.\)/\1,\n\2/g' kallithea/public/css/{style,contextbar}.css | |
|
17 | sed -i -e 's/^\([^ ,/].*\) */\1 /g' kallithea/public/css/{style,contextbar}.css | |
|
18 | sed -i -e 's,^--$,-- ,g' kallithea/templates/email_templates/main.txt | |
|
19 | 19 | |
|
20 | 20 | hg diff |
General Comments 0
You need to be logged in to leave comments.
Login now