Show More
@@ -11,8 +11,11 b'' | |||||
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | import os |
|
13 | import os | |
|
14 | import time | |||
|
15 | import sys | |||
14 | import shutil |
|
16 | import shutil | |
15 | import logging |
|
17 | import logging | |
|
18 | ||||
16 | from os.path import join as jn |
|
19 | from os.path import join as jn | |
17 | from os.path import dirname as dn |
|
20 | from os.path import dirname as dn | |
18 |
|
21 | |||
@@ -41,7 +44,8 b' add_cache(conf)' | |||||
41 | USER = 'test_admin' |
|
44 | USER = 'test_admin' | |
42 | PASS = 'test12' |
|
45 | PASS = 'test12' | |
43 | HOST = '127.0.0.1:5000' |
|
46 | HOST = '127.0.0.1:5000' | |
44 | DEBUG = True |
|
47 | DEBUG = bool(int(sys.argv[1])) | |
|
48 | print 'DEBUG:',DEBUG | |||
45 | log = logging.getLogger(__name__) |
|
49 | log = logging.getLogger(__name__) | |
46 |
|
50 | |||
47 |
|
51 | |||
@@ -64,10 +68,24 b' class Command(object):' | |||||
64 | print stdout, stderr |
|
68 | print stdout, stderr | |
65 | return stdout, stderr |
|
69 | return stdout, stderr | |
66 |
|
70 | |||
|
71 | ||||
|
72 | def test_wrapp(func): | |||
|
73 | ||||
|
74 | def __wrapp(*args,**kwargs): | |||
|
75 | print '###%s###' %func.__name__ | |||
|
76 | try: | |||
|
77 | res = func(*args,**kwargs) | |||
|
78 | except: | |||
|
79 | print '--%s failed--' % func.__name__ | |||
|
80 | return | |||
|
81 | print 'ok' | |||
|
82 | return res | |||
|
83 | return __wrapp | |||
|
84 | ||||
67 | def get_session(): |
|
85 | def get_session(): | |
68 | engine = engine_from_config(conf, 'sqlalchemy.db1.') |
|
86 | engine = engine_from_config(conf, 'sqlalchemy.db1.') | |
69 | init_model(engine) |
|
87 | init_model(engine) | |
70 |
sa = meta.Session |
|
88 | sa = meta.Session | |
71 | return sa |
|
89 | return sa | |
72 |
|
90 | |||
73 |
|
91 | |||
@@ -129,16 +147,23 b' def set_anonymous_access(enable=True):' | |||||
129 | user.active = enable |
|
147 | user.active = enable | |
130 | sa.add(user) |
|
148 | sa.add(user) | |
131 | sa.commit() |
|
149 | sa.commit() | |
|
150 | sa.remove() | |||
|
151 | ||||
|
152 | print 'anonymous access is now:',enable | |||
|
153 | ||||
132 |
|
154 | |||
133 | def get_anonymous_access(): |
|
155 | def get_anonymous_access(): | |
134 | sa = get_session() |
|
156 | sa = get_session() | |
135 |
|
|
157 | obj1 = sa.query(User).filter(User.username == 'default').one() | |
|
158 | sa.expire(obj1) | |||
|
159 | return obj1.active | |||
136 |
|
160 | |||
137 |
|
161 | |||
138 | #============================================================================== |
|
162 | #============================================================================== | |
139 | # TESTS |
|
163 | # TESTS | |
140 | #============================================================================== |
|
164 | #============================================================================== | |
141 | def test_clone(no_errors=False): |
|
165 | @test_wrapp | |
|
166 | def test_clone_with_credentials(no_errors=False): | |||
142 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
167 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
143 |
|
168 | |||
144 | try: |
|
169 | try: | |
@@ -148,7 +173,13 b' def test_clone(no_errors=False):' | |||||
148 | except OSError: |
|
173 | except OSError: | |
149 | raise |
|
174 | raise | |
150 |
|
175 | |||
151 |
|
176 | print 'checking if anonymous access is enabled' | ||
|
177 | anonymous_access = get_anonymous_access() | |||
|
178 | if anonymous_access: | |||
|
179 | print 'enabled, disabling it ' | |||
|
180 | set_anonymous_access(enable=False) | |||
|
181 | time.sleep(1) | |||
|
182 | ||||
152 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ |
|
183 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ | |
153 | {'user':USER, |
|
184 | {'user':USER, | |
154 | 'pass':PASS, |
|
185 | 'pass':PASS, | |
@@ -163,8 +194,8 b' def test_clone(no_errors=False):' | |||||
163 | assert """abort""" not in stderr , 'got error from clone' |
|
194 | assert """abort""" not in stderr , 'got error from clone' | |
164 |
|
195 | |||
165 |
|
196 | |||
166 |
|
197 | @test_wrapp | ||
167 |
def test_clone_anonymous |
|
198 | def test_clone_anonymous(): | |
168 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
199 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
169 |
|
200 | |||
170 | try: |
|
201 | try: | |
@@ -180,7 +211,8 b' def test_clone_anonymous_ok():' | |||||
180 | if not anonymous_access: |
|
211 | if not anonymous_access: | |
181 | print 'not enabled, enabling it ' |
|
212 | print 'not enabled, enabling it ' | |
182 | set_anonymous_access(enable=True) |
|
213 | set_anonymous_access(enable=True) | |
183 |
|
214 | time.sleep(1) | ||
|
215 | ||||
184 | clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \ |
|
216 | clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \ | |
185 | {'user':USER, |
|
217 | {'user':USER, | |
186 | 'pass':PASS, |
|
218 | 'pass':PASS, | |
@@ -189,8 +221,6 b' def test_clone_anonymous_ok():' | |||||
189 | 'dest':path} |
|
221 | 'dest':path} | |
190 |
|
222 | |||
191 | stdout, stderr = Command(cwd).execute('hg clone', clone_url) |
|
223 | stdout, stderr = Command(cwd).execute('hg clone', clone_url) | |
192 | print stdout, stderr |
|
|||
193 |
|
||||
194 |
|
224 | |||
195 | assert """adding file changes""" in stdout, 'no messages about cloning' |
|
225 | assert """adding file changes""" in stdout, 'no messages about cloning' | |
196 | assert """abort""" not in stderr , 'got error from clone' |
|
226 | assert """abort""" not in stderr , 'got error from clone' | |
@@ -200,7 +230,7 b' def test_clone_anonymous_ok():' | |||||
200 | print 'disabling anonymous access' |
|
230 | print 'disabling anonymous access' | |
201 | set_anonymous_access(enable=False) |
|
231 | set_anonymous_access(enable=False) | |
202 |
|
232 | |||
203 |
|
233 | @test_wrapp | ||
204 | def test_clone_wrong_credentials(): |
|
234 | def test_clone_wrong_credentials(): | |
205 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
235 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
206 |
|
236 | |||
@@ -211,7 +241,12 b' def test_clone_wrong_credentials():' | |||||
211 | except OSError: |
|
241 | except OSError: | |
212 | raise |
|
242 | raise | |
213 |
|
243 | |||
214 |
|
244 | print 'checking if anonymous access is enabled' | ||
|
245 | anonymous_access = get_anonymous_access() | |||
|
246 | if anonymous_access: | |||
|
247 | print 'enabled, disabling it ' | |||
|
248 | set_anonymous_access(enable=False) | |||
|
249 | ||||
215 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ |
|
250 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ | |
216 | {'user':USER + 'error', |
|
251 | {'user':USER + 'error', | |
217 | 'pass':PASS, |
|
252 | 'pass':PASS, | |
@@ -221,12 +256,14 b' def test_clone_wrong_credentials():' | |||||
221 |
|
256 | |||
222 | stdout, stderr = Command(cwd).execute('hg clone', clone_url) |
|
257 | stdout, stderr = Command(cwd).execute('hg clone', clone_url) | |
223 |
|
258 | |||
224 |
|
|
259 | if not """abort: authorization failed""" in stderr: | |
|
260 | raise Exception('Failure') | |||
225 |
|
261 | |||
226 |
|
262 | @test_wrapp | ||
227 | def test_pull(): |
|
263 | def test_pull(): | |
228 | pass |
|
264 | pass | |
229 |
|
265 | |||
|
266 | @test_wrapp | |||
230 | def test_push_modify_file(f_name='setup.py'): |
|
267 | def test_push_modify_file(f_name='setup.py'): | |
231 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
268 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
232 | modified_file = jn(TESTS_TMP_PATH, HG_REPO, f_name) |
|
269 | modified_file = jn(TESTS_TMP_PATH, HG_REPO, f_name) | |
@@ -239,10 +276,11 b" def test_push_modify_file(f_name='setup." | |||||
239 |
|
276 | |||
240 | Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) |
|
277 | Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) | |
241 |
|
278 | |||
|
279 | @test_wrapp | |||
242 | def test_push_new_file(commits=15, with_clone=True): |
|
280 | def test_push_new_file(commits=15, with_clone=True): | |
243 |
|
281 | |||
244 | if with_clone: |
|
282 | if with_clone: | |
245 | test_clone(no_errors=True) |
|
283 | test_clone_with_credentials(no_errors=True) | |
246 |
|
284 | |||
247 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
285 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
248 | added_file = jn(path, '%ssetupΔ ΕΌΕΊΔ.py' % _RandomNameSequence().next()) |
|
286 | added_file = jn(path, '%ssetupΔ ΕΌΕΊΔ.py' % _RandomNameSequence().next()) | |
@@ -269,6 +307,7 b' def test_push_new_file(commits=15, with_' | |||||
269 |
|
307 | |||
270 | Command(cwd).execute('hg push --verbose --debug %s' % push_url) |
|
308 | Command(cwd).execute('hg push --verbose --debug %s' % push_url) | |
271 |
|
309 | |||
|
310 | @test_wrapp | |||
272 | def test_push_wrong_credentials(): |
|
311 | def test_push_wrong_credentials(): | |
273 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
312 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
274 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \ |
|
313 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \ | |
@@ -288,6 +327,7 b' def test_push_wrong_credentials():' | |||||
288 |
|
327 | |||
289 | Command(cwd).execute('hg push %s' % clone_url) |
|
328 | Command(cwd).execute('hg push %s' % clone_url) | |
290 |
|
329 | |||
|
330 | @test_wrapp | |||
291 | def test_push_wrong_path(): |
|
331 | def test_push_wrong_path(): | |
292 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) |
|
332 | cwd = path = jn(TESTS_TMP_PATH, HG_REPO) | |
293 | added_file = jn(path, 'somefile.py') |
|
333 | added_file = jn(path, 'somefile.py') | |
@@ -318,20 +358,22 b' def test_push_wrong_path():' | |||||
318 | 'dest':jn(TESTS_TMP_PATH, HG_REPO)} |
|
358 | 'dest':jn(TESTS_TMP_PATH, HG_REPO)} | |
319 |
|
359 | |||
320 | stdout, stderr = Command(cwd).execute('hg push %s' % clone_url) |
|
360 | stdout, stderr = Command(cwd).execute('hg push %s' % clone_url) | |
321 |
|
|
361 | if not """abort: HTTP Error 403: Forbidden""" in stderr: | |
|
362 | raise Exception('Failure') | |||
322 |
|
363 | |||
323 |
|
364 | |||
324 | if __name__ == '__main__': |
|
365 | if __name__ == '__main__': | |
325 | create_test_user(force=False) |
|
366 | create_test_user(force=False) | |
326 | create_test_repo() |
|
367 | create_test_repo() | |
327 | #test_push_modify_file() |
|
368 | ||
328 | #test_clone() |
|
369 | # test_push_modify_file() | |
329 |
|
|
370 | test_clone_with_credentials() | |
|
371 | test_clone_wrong_credentials() | |||
330 |
|
372 | |||
331 | #test_clone_wrong_credentials() |
|
|||
332 |
|
373 | |||
333 | test_pull() |
|
|||
334 | test_push_new_file(commits=2, with_clone=True) |
|
374 | test_push_new_file(commits=2, with_clone=True) | |
335 |
|
375 | # | ||
336 |
|
|
376 | test_push_wrong_path() | |
337 | #test_push_wrong_credentials() |
|
377 | ||
|
378 | test_clone_anonymous() | |||
|
379 | test_push_wrong_credentials() No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now