Show More
@@ -48,7 +48,8 b' from rhodecode.tests import TESTS_TMP_PA' | |||||
48 | from rhodecode.config.environment import load_environment |
|
48 | from rhodecode.config.environment import load_environment | |
49 |
|
49 | |||
50 | rel_path = dn(dn(dn(os.path.abspath(__file__)))) |
|
50 | rel_path = dn(dn(dn(os.path.abspath(__file__)))) | |
51 | conf = appconfig('config:development.ini', relative_to=rel_path) |
|
51 | ||
|
52 | conf = appconfig('config:%s' % sys.argv[1], relative_to=rel_path) | |||
52 | load_environment(conf.global_conf, conf.local_conf) |
|
53 | load_environment(conf.global_conf, conf.local_conf) | |
53 |
|
54 | |||
54 | add_cache(conf) |
|
55 | add_cache(conf) | |
@@ -56,10 +57,13 b' add_cache(conf)' | |||||
56 | USER = 'test_admin' |
|
57 | USER = 'test_admin' | |
57 | PASS = 'test12' |
|
58 | PASS = 'test12' | |
58 | HOST = '127.0.0.1:5000' |
|
59 | HOST = '127.0.0.1:5000' | |
59 | DEBUG = True if sys.argv[1:] else False |
|
60 | DEBUG = False | |
60 | print 'DEBUG:', DEBUG |
|
61 | print 'DEBUG:', DEBUG | |
61 | log = logging.getLogger(__name__) |
|
62 | log = logging.getLogger(__name__) | |
62 |
|
63 | |||
|
64 | engine = engine_from_config(conf, 'sqlalchemy.db1.') | |||
|
65 | init_model(engine) | |||
|
66 | sa = meta.Session | |||
63 |
|
67 | |||
64 | class Command(object): |
|
68 | class Command(object): | |
65 |
|
69 | |||
@@ -96,22 +100,15 b' def test_wrapp(func):' | |||||
96 | return res |
|
100 | return res | |
97 | return __wrapp |
|
101 | return __wrapp | |
98 |
|
102 | |||
99 | def get_session(): |
|
|||
100 | engine = engine_from_config(conf, 'sqlalchemy.db1.') |
|
|||
101 | init_model(engine) |
|
|||
102 | sa = meta.Session |
|
|||
103 | return sa |
|
|||
104 |
|
||||
105 |
|
103 | |||
106 | def create_test_user(force=True): |
|
104 | def create_test_user(force=True): | |
107 | print '\tcreating test user' |
|
105 | print '\tcreating test user' | |
108 | sa = get_session() |
|
|||
109 |
|
106 | |||
110 | user = sa.query(User).filter(User.username == USER).scalar() |
|
107 | user = User.get_by_username(USER) | |
111 |
|
108 | |||
112 | if force and user is not None: |
|
109 | if force and user is not None: | |
113 | print '\tremoving current user' |
|
110 | print '\tremoving current user' | |
114 |
for repo in |
|
111 | for repo in Repository.query().filter(Repository.user == user).all(): | |
115 | sa.delete(repo) |
|
112 | sa.delete(repo) | |
116 | sa.delete(user) |
|
113 | sa.delete(user) | |
117 | sa.commit() |
|
114 | sa.commit() | |
@@ -134,9 +131,8 b' def create_test_user(force=True):' | |||||
134 |
|
131 | |||
135 | def create_test_repo(force=True): |
|
132 | def create_test_repo(force=True): | |
136 | from rhodecode.model.repo import RepoModel |
|
133 | from rhodecode.model.repo import RepoModel | |
137 | sa = get_session() |
|
|||
138 |
|
134 | |||
139 | user = sa.query(User).filter(User.username == USER).scalar() |
|
135 | user = User.get_by_username(USER) | |
140 | if user is None: |
|
136 | if user is None: | |
141 | raise Exception('user not found') |
|
137 | raise Exception('user not found') | |
142 |
|
138 | |||
@@ -156,22 +152,17 b' def create_test_repo(force=True):' | |||||
156 |
|
152 | |||
157 |
|
153 | |||
158 | def set_anonymous_access(enable=True): |
|
154 | def set_anonymous_access(enable=True): | |
159 | sa = get_session() |
|
155 | user = User.get_by_username('default') | |
160 | user = sa.query(User).filter(User.username == 'default').one() |
|
|||
161 | sa.expire(user) |
|
|||
162 | user.active = enable |
|
156 | user.active = enable | |
163 | sa.add(user) |
|
157 | sa.add(user) | |
164 | sa.commit() |
|
158 | sa.commit() | |
165 | sa.remove() |
|
|||
166 | import time;time.sleep(3) |
|
|||
167 | print '\tanonymous access is now:', enable |
|
159 | print '\tanonymous access is now:', enable | |
168 |
|
160 | if enable != User.get_by_username('default').active: | ||
|
161 | raise Exception('Cannot set anonymous access') | |||
169 |
|
162 | |||
170 | def get_anonymous_access(): |
|
163 | def get_anonymous_access(): | |
171 | sa = get_session() |
|
164 | user = User.get_by_username('default') | |
172 | obj1 = sa.query(User).filter(User.username == 'default').one() |
|
165 | return user.active | |
173 | sa.expire(obj1) |
|
|||
174 | return obj1.active |
|
|||
175 |
|
166 | |||
176 |
|
167 | |||
177 | #============================================================================== |
|
168 | #============================================================================== | |
@@ -378,16 +369,15 b' def test_push_wrong_path():' | |||||
378 |
|
369 | |||
379 | @test_wrapp |
|
370 | @test_wrapp | |
380 | def get_logs(): |
|
371 | def get_logs(): | |
381 | sa = get_session() |
|
372 | return UserLog.query().all() | |
382 | return len(sa.query(UserLog).all()) |
|
|||
383 |
|
373 | |||
384 | @test_wrapp |
|
374 | @test_wrapp | |
385 | def test_logs(initial): |
|
375 | def test_logs(initial): | |
386 | sa = get_session() |
|
376 | logs = UserLog.query().all() | |
387 | logs = sa.query(UserLog).all() |
|
377 | operations = 4 | |
388 | operations = 7 |
|
378 | if len(initial) + operations != len(logs): | |
389 | if initial + operations != len(logs): |
|
379 | raise Exception("missing number of logs initial:%s vs current:%s" % \ | |
390 | raise Exception("missing number of logs %s vs %s" % (initial, len(logs))) |
|
380 | (len(initial), len(logs))) | |
391 |
|
381 | |||
392 |
|
382 | |||
393 | if __name__ == '__main__': |
|
383 | if __name__ == '__main__': | |
@@ -395,18 +385,17 b" if __name__ == '__main__':" | |||||
395 | create_test_repo() |
|
385 | create_test_repo() | |
396 |
|
386 | |||
397 | initial_logs = get_logs() |
|
387 | initial_logs = get_logs() | |
|
388 | print 'initial activity logs: %s' % len(initial_logs) | |||
398 |
|
389 | |||
399 |
|
|
390 | #test_push_modify_file() | |
400 | test_clone_with_credentials() |
|
391 | test_clone_with_credentials() | |
401 | test_clone_wrong_credentials() |
|
392 | test_clone_wrong_credentials() | |
402 |
|
393 | |||
403 |
|
||||
404 | test_push_new_file(commits=2, with_clone=True) |
|
394 | test_push_new_file(commits=2, with_clone=True) | |
405 |
|
395 | |||
406 | test_clone_anonymous() |
|
396 | test_clone_anonymous() | |
407 | test_push_wrong_path() |
|
397 | test_push_wrong_path() | |
408 |
|
398 | |||
409 |
|
||||
410 | test_push_wrong_credentials() |
|
399 | test_push_wrong_credentials() | |
411 |
|
400 | |||
412 | test_logs(initial_logs) |
|
401 | test_logs(initial_logs) |
General Comments 0
You need to be logged in to leave comments.
Login now