annotate rhodecode/tests/_test_concurency.py @ 1749:8ecc6b8229a5 beta

commit less models - models don't do any commits(with few exceptions) - all db transactions should be handled by higher level modules like controllers, celery tasks
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 02 Dec 2011 22:31:13 +0200
parents 48d4fcf04a29
children a8c66e870bd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.tests.test_hg_operations
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 Test suite for making push/pull operations
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: Dec 30, 2010
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
9 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
10 :license: GPLv3, see COPYING for more details.
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 """
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
12 # This program is free software: you can redistribute it and/or modify
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
13 # it under the terms of the GNU General Public License as published by
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
14 # the Free Software Foundation, either version 3 of the License, or
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
15 # (at your option) any later version.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
16 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
17 # This program is distributed in the hope that it will be useful,
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
20 # GNU General Public License for more details.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
21 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
22 # You should have received a copy of the GNU General Public License
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 import os
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import sys
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import shutil
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import logging
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from os.path import join as jn
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from os.path import dirname as dn
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from tempfile import _RandomNameSequence
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from subprocess import Popen, PIPE
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from paste.deploy import appconfig
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from pylons import config
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from sqlalchemy import engine_from_config
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 from rhodecode.lib.utils import add_cache
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 from rhodecode.model import init_model
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 from rhodecode.model import meta
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 from rhodecode.model.db import User, Repository
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 from rhodecode.lib.auth import get_crypt_password
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 from rhodecode.config.environment import load_environment
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 rel_path = dn(dn(dn(os.path.abspath(__file__))))
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 conf = appconfig('config:development.ini', relative_to=rel_path)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 load_environment(conf.global_conf, conf.local_conf)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 add_cache(conf)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 USER = 'test_admin'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 PASS = 'test12'
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1666
diff changeset
56 HOST = 'hg.local'
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
57 METHOD = 'pull'
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 DEBUG = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 log = logging.getLogger(__name__)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 class Command(object):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 def __init__(self, cwd):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 self.cwd = cwd
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 def execute(self, cmd, *args):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 """Runs command on the system with given ``args``.
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 """
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 command = cmd + ' ' + ' '.join(args)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 log.debug('Executing %s' % command)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 if DEBUG:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 print command
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, cwd=self.cwd)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 stdout, stderr = p.communicate()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 if DEBUG:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 print stdout, stderr
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 return stdout, stderr
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 def get_session():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 engine = engine_from_config(conf, 'sqlalchemy.db1.')
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 init_model(engine)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
84 sa = meta.Session
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 return sa
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 def create_test_user(force=True):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 print 'creating test user'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 user = sa.query(User).filter(User.username == USER).scalar()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 if force and user is not None:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 print 'removing current user'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 for repo in sa.query(Repository).filter(Repository.user == user).all():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 sa.delete(repo)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 sa.delete(user)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 sa.commit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 if user is None or force:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 print 'creating new one'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 new_usr = User()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 new_usr.username = USER
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 new_usr.password = get_crypt_password(PASS)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 new_usr.email = 'mail@mail.com'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 new_usr.name = 'test'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 new_usr.lastname = 'lasttestname'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 new_usr.active = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 new_usr.admin = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 sa.add(new_usr)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 sa.commit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 print 'done'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 def create_test_repo(force=True):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 print 'creating test repo'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 from rhodecode.model.repo import RepoModel
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 user = sa.query(User).filter(User.username == USER).scalar()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 if user is None:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 raise Exception('user not found')
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 repo = sa.query(Repository).filter(Repository.repo_name == HG_REPO).scalar()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 if repo is None:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 print 'repo not found creating'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 form_data = {'repo_name':HG_REPO,
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 'repo_type':'hg',
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 'private':False,
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 'clone_uri':'' }
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 rm = RepoModel(sa)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 rm.base_path = '/home/hg'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 rm.create(form_data, user)
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
139
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 print 'done'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 def set_anonymous_access(enable=True):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 user = sa.query(User).filter(User.username == 'default').one()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 user.active = enable
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 sa.add(user)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 sa.commit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 def get_anonymous_access():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 return sa.query(User).filter(User.username == 'default').one().active
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 #==============================================================================
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 # TESTS
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 #==============================================================================
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
157 def test_clone_with_credentials(no_errors=False, repo=HG_REPO, method=METHOD,
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
158 seq=None):
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 cwd = path = jn(TESTS_TMP_PATH, repo)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
161 if seq == None:
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
162 seq = _RandomNameSequence().next()
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
163
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 try:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 shutil.rmtree(path, ignore_errors=True)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 os.makedirs(path)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 #print 'made dirs %s' % jn(path)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 except OSError:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 raise
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
172 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 {'user':USER,
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 'pass':PASS,
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 'host':HOST,
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
176 'cloned_repo':repo, }
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
178 dest = path + seq
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
179 if method == 'pull':
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
180 stdout, stderr = Command(cwd).execute('hg', method, '--cwd', dest, clone_url)
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
181 else:
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
182 stdout, stderr = Command(cwd).execute('hg', method, clone_url, dest)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
184 if no_errors is False:
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
185 assert """adding file changes""" in stdout, 'no messages about cloning'
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
186 assert """abort""" not in stderr , 'got error from clone'
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 if __name__ == '__main__':
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 try:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 create_test_user(force=False)
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
191 seq = None
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
192 import time
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
194 if METHOD == 'pull':
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
195 seq = _RandomNameSequence().next()
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
196 test_clone_with_credentials(repo=sys.argv[1], method='clone',
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
197 seq=seq)
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
198 s = time.time()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 for i in range(int(sys.argv[2])):
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
200 print 'take', i
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
201 test_clone_with_credentials(repo=sys.argv[1], method=METHOD,
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
202 seq=seq)
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
203 print 'time taken %.3f' % (time.time() - s)
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
204 except Exception, e:
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
205 raise
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
206 sys.exit('stop on %s' % e)