annotate rhodecode/tests/scripts/test_concurency.py @ 3625:260a7a01b054 beta

follow Python conventions for boolean values True and False might be singletons and the "default" values for "boolean" expressions, but "all" values in Python has a boolean value and should be evaluated as such. Checking with 'is True' and 'is False' is thus confusing, error prone and unnessarily complex. If we anywhere rely and nullable boolean fields from the database layer and don't want the null value to be treated as False then we should check explicitly for null with 'is None'.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 28 Mar 2013 01:10:45 +0100
parents f5dc0417d6b1
children 10b4e34841a4
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
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1813
diff changeset
9 :author: marcink
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1813
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
11 :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
12 """
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
13 # 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
14 # 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
15 # the Free Software Foundation, either version 3 of the License, or
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
16 # (at your option) any later version.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
17 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
18 # 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
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
21 # GNU General Public License for more details.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
22 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
23 # 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
24 # 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
25
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import os
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import sys
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import shutil
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import logging
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 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
31 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
32
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from tempfile import _RandomNameSequence
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from subprocess import Popen, PIPE
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from paste.deploy import appconfig
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from pylons import config
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 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
39
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 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
41 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
42 from rhodecode.model import meta
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 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
44 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
45
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 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
47 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
48
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
49 rel_path = dn(dn(dn(dn(os.path.abspath(__file__)))))
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
50 conf = appconfig('config:rc.ini', relative_to=rel_path)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 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
52
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 add_cache(conf)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 USER = 'test_admin'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 PASS = 'test12'
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
57 HOST = 'rc.local'
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
58 METHOD = 'pull'
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 DEBUG = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 log = logging.getLogger(__name__)
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
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 class Command(object):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 def __init__(self, cwd):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 self.cwd = cwd
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 def execute(self, cmd, *args):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 """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
70 """
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 command = cmd + ' ' + ' '.join(args)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 log.debug('Executing %s' % command)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 if DEBUG:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 print command
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 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
77 stdout, stderr = p.communicate()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 if DEBUG:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 print stdout, stderr
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 return stdout, stderr
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
82
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 def get_session():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 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
85 init_model(engine)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1734
diff changeset
86 sa = meta.Session
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 return sa
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 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
91 print 'creating test user'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 sa = get_session()
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 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
95
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 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
97 print 'removing current user'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 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
99 sa.delete(repo)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 sa.delete(user)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 sa.commit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 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
104 print 'creating new one'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 new_usr = User()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 new_usr.username = USER
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 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
108 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
109 new_usr.name = 'test'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 new_usr.lastname = 'lasttestname'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 new_usr.active = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 new_usr.admin = True
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 sa.add(new_usr)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 sa.commit()
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 print 'done'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 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
120 print 'creating test repo'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 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
122 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 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
125 if user is None:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 raise Exception('user not found')
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 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
129
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 if repo is None:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 print 'repo not found creating'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
133 form_data = {'repo_name': HG_REPO,
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
134 'repo_type': 'hg',
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 'private':False,
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
136 'clone_uri': '' }
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 rm = RepoModel(sa)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 rm.base_path = '/home/hg'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 rm.create(form_data, user)
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
140
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 print 'done'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
143
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 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
145 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 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
147 user.active = enable
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 sa.add(user)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 sa.commit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150
2527
95624ce4465f orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
151
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 def get_anonymous_access():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 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
155
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 #==============================================================================
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 # TESTS
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 #==============================================================================
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
160 def test_clone_with_credentials(no_errors=False, repo=HG_REPO, method=METHOD,
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
161 seq=None, backend='hg'):
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 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
163
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
164 if seq == None:
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
165 seq = _RandomNameSequence().next()
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
166
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 try:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 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
169 os.makedirs(path)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 #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
171 except OSError:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 raise
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
174 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
175 {'user': USER,
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
176 'pass': PASS,
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
177 'host': HOST,
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
178 'cloned_repo': repo, }
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
180 dest = path + seq
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
181 if method == 'pull':
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
182 stdout, stderr = Command(cwd).execute(backend, method, '--cwd', dest, clone_url)
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
183 else:
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
184 stdout, stderr = Command(cwd).execute(backend, method, clone_url, dest)
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
185 print stdout,'sdasdsadsa'
3625
260a7a01b054 follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents: 2895
diff changeset
186 if not no_errors:
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
187 if backend == 'hg':
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
188 assert """adding file changes""" in stdout, 'no messages about cloning'
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
189 assert """abort""" not in stderr , 'got error from clone'
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
190 elif backend == 'git':
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
191 assert """Cloning into""" in stdout, 'no messages about cloning'
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 if __name__ == '__main__':
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 try:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 create_test_user(force=False)
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
196 seq = None
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
197 import time
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198
1813
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
199 try:
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
200 METHOD = sys.argv[3]
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
201 except:
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
202 pass
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
203
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
204 try:
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
205 backend = sys.argv[4]
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
206 except:
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
207 backend = 'hg'
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
208
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
209 if METHOD == 'pull':
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
210 seq = _RandomNameSequence().next()
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
211 test_clone_with_credentials(repo=sys.argv[1], method='clone',
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
212 seq=seq, backend=backend)
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
213 s = time.time()
1813
a8c66e870bd0 implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
214 for i in range(1, int(sys.argv[2]) + 1):
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
215 print 'take', i
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
216 test_clone_with_credentials(repo=sys.argv[1], method=METHOD,
2895
f5dc0417d6b1 made concurrency test also for git
Marcin Kuzminski <marcin@python-works.com>
parents: 2527
diff changeset
217 seq=seq, backend=backend)
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
218 print 'time taken %.3f' % (time.time() - s)
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
219 except Exception, e:
1666
a404060706c0 test concurency script updates
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
220 raise
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
221 sys.exit('stop on %s' % e)