annotate rhodecode/tests/test_hg_operations.py @ 1529:0b268dd369ec beta

Fixed test_hg_operations test and added concurency test
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 07 Oct 2011 23:17:45 +0200
parents fcc676c6bf3b
children 04027bdb876c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
1 # -*- coding: utf-8 -*-
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
2 """
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
3 rhodecode.tests.test_hg_operations
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
5
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
6 Test suite for making push/pull operations
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1087
diff changeset
7
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
8 :created_on: Dec 30, 2010
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
9 :copyright: (c) 2010 by marcink.
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
10 :license: LICENSE_NAME, see LICENSE_FILE for more details.
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
11 """
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
12
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
13 import os
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
14 import time
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
15 import sys
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
16 import shutil
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
17 import logging
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
18
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
19 from os.path import join as jn
1277
cf2a67b91ffc fixed path for .ini file in test hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
20 from os.path import dirname as dn
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
21
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
22 from tempfile import _RandomNameSequence
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
23 from subprocess import Popen, PIPE
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
24
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
25 from paste.deploy import appconfig
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
26 from pylons import config
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
27 from sqlalchemy import engine_from_config
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
28
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
29 from rhodecode.lib.utils import add_cache
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
30 from rhodecode.model import init_model
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
31 from rhodecode.model import meta
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
32 from rhodecode.model.db import User, Repository, UserLog
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
33 from rhodecode.lib.auth import get_crypt_password
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
34
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
35 from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
36 from rhodecode.config.environment import load_environment
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
37
1277
cf2a67b91ffc fixed path for .ini file in test hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
38 rel_path = dn(dn(dn(os.path.abspath(__file__))))
cf2a67b91ffc fixed path for .ini file in test hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
39 conf = appconfig('config:development.ini', relative_to=rel_path)
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
40 load_environment(conf.global_conf, conf.local_conf)
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
41
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
42 add_cache(conf)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
43
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
44 USER = 'test_admin'
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
45 PASS = 'test12'
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
46 HOST = '127.0.0.1:5000'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
47 DEBUG = bool(int(sys.argv[1]))
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
48 print 'DEBUG:', DEBUG
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
49 log = logging.getLogger(__name__)
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
50
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
51
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
52 class Command(object):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
53
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
54 def __init__(self, cwd):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
55 self.cwd = cwd
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
56
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
57 def execute(self, cmd, *args):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
58 """Runs command on the system with given ``args``.
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
59 """
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
60
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
61 command = cmd + ' ' + ' '.join(args)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
62 log.debug('Executing %s' % command)
910
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
63 if DEBUG:
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
64 print command
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
65 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, cwd=self.cwd)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
66 stdout, stderr = p.communicate()
910
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
67 if DEBUG:
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
68 print stdout, stderr
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
69 return stdout, stderr
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
70
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
71
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
72 def test_wrapp(func):
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
73
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
74 def __wrapp(*args, **kwargs):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
75 print '###%s###' % func.__name__
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
76 try:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
77 res = func(*args, **kwargs)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
78 except Exception, e:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
79 print ('###############\n-'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
80 '--%s failed %s--\n'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
81 '###############\n' % (func.__name__, e))
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
82 sys.exit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
83 print '++OK++'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
84 return res
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
85 return __wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
86
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
87 def get_session():
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
88 engine = engine_from_config(conf, 'sqlalchemy.db1.')
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
89 init_model(engine)
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
90 sa = meta.Session
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
91 return sa
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
92
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
93
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
94 def create_test_user(force=True):
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
95 print '\tcreating test user'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
96 sa = get_session()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
97
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
98 user = sa.query(User).filter(User.username == USER).scalar()
988
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
99
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
100 if force and user is not None:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
101 print '\tremoving current user'
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
102 for repo in sa.query(Repository).filter(Repository.user == user).all():
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
103 sa.delete(repo)
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
104 sa.delete(user)
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
105 sa.commit()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
106
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
107 if user is None or force:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
108 print '\tcreating new one'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
109 new_usr = User()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
110 new_usr.username = USER
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
111 new_usr.password = get_crypt_password(PASS)
988
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
112 new_usr.email = 'mail@mail.com'
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
113 new_usr.name = 'test'
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
114 new_usr.lastname = 'lasttestname'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
115 new_usr.active = True
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
116 new_usr.admin = True
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
117 sa.add(new_usr)
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
118 sa.commit()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
119
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
120 print '\tdone'
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
121
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
122
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
123 def create_test_repo(force=True):
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
124 from rhodecode.model.repo import RepoModel
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
125 sa = get_session()
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
126
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
127 user = sa.query(User).filter(User.username == USER).scalar()
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
128 if user is None:
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
129 raise Exception('user not found')
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
130
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
131
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
132 repo = sa.query(Repository).filter(Repository.repo_name == HG_REPO).scalar()
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
133
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
134 if repo is None:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
135 print '\trepo not found creating'
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
136
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
137 form_data = {'repo_name':HG_REPO,
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
138 'repo_type':'hg',
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
139 'private':False,
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
140 'clone_uri':'' }
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
141 rm = RepoModel(sa)
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
142 rm.base_path = '/home/hg'
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
143 rm.create(form_data, user)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
144
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
145
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
146 def set_anonymous_access(enable=True):
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
147 sa = get_session()
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
148 user = sa.query(User).filter(User.username == 'default').one()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
149 sa.expire(user)
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
150 user.active = enable
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
151 sa.add(user)
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
152 sa.commit()
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
153 sa.remove()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
154 import time;time.sleep(3)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
155 print '\tanonymous access is now:', enable
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
156
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
157
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
158 def get_anonymous_access():
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
159 sa = get_session()
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
160 obj1 = sa.query(User).filter(User.username == 'default').one()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
161 sa.expire(obj1)
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
162 return obj1.active
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
163
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
164
910
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
165 #==============================================================================
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
166 # TESTS
910
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
167 #==============================================================================
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
168 @test_wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
169 def test_clone_with_credentials(no_errors=False):
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
170 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
171
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
172 try:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
173 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
174 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
175 #print 'made dirs %s' % jn(path)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
176 except OSError:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
177 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
178
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
179 print '\tchecking if anonymous access is enabled'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
180 anonymous_access = get_anonymous_access()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
181 if anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
182 print '\tenabled, disabling it '
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
183 set_anonymous_access(enable=False)
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
184 time.sleep(1)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
185
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
186 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
187 {'user':USER,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
188 'pass':PASS,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
189 'host':HOST,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
190 'cloned_repo':HG_REPO,
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
191 'dest':path}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
192
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
193 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
194
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
195 if no_errors is False:
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
196 assert """adding file changes""" in stdout, 'no messages about cloning'
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
197 assert """abort""" not in stderr , 'got error from clone'
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
198
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
199
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
200 @test_wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
201 def test_clone_anonymous():
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
202 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
203
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
204 try:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
205 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
206 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
207 #print 'made dirs %s' % jn(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
208 except OSError:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
209 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
210
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
211
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
212 print '\tchecking if anonymous access is enabled'
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
213 anonymous_access = get_anonymous_access()
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
214 if not anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
215 print '\tnot enabled, enabling it '
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
216 set_anonymous_access(enable=True)
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
217 time.sleep(1)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
218
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
219 clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
220 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
221 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
222 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
223 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
224 'dest':path}
755
99ece4c484e1 Added basic test push/pull script
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
225
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
226 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
227
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
228 assert """adding file changes""" in stdout, 'no messages about cloning'
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
229 assert """abort""" not in stderr , 'got error from clone'
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
230
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
231 #disable if it was enabled
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
232 if not anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
233 print '\tdisabling anonymous access'
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
234 set_anonymous_access(enable=False)
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
235
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
236 @test_wrapp
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
237 def test_clone_wrong_credentials():
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
238 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
239
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
240 try:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
241 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
242 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
243 #print 'made dirs %s' % jn(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
244 except OSError:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
245 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
246
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
247 print '\tchecking if anonymous access is enabled'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
248 anonymous_access = get_anonymous_access()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
249 if anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
250 print '\tenabled, disabling it '
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
251 set_anonymous_access(enable=False)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
252
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
253 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
254 {'user':USER + 'error',
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
255 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
256 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
257 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
258 'dest':path}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
259
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
260 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
261
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
262 if not """abort: authorization failed""" in stderr:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
263 raise Exception('Failure')
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
264
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
265 @test_wrapp
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
266 def test_pull():
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
267 pass
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
268
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
269 @test_wrapp
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
270 def test_push_modify_file(f_name='setup.py'):
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
271 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
272 modified_file = jn(TESTS_TMP_PATH, HG_REPO, f_name)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
273 for i in xrange(5):
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
274 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
275 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
276
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
277 cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
278 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
279
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
280 Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO))
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
281
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
282 @test_wrapp
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
283 def test_push_new_file(commits=15, with_clone=True):
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
284
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
285 if with_clone:
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
286 test_clone_with_credentials(no_errors=True)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
287
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
288 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1087
51076a2a2b64 fixed unicode problems with file paths.
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
289 added_file = jn(path, '%ssetupążźć.py' % _RandomNameSequence().next())
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
290
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
291 Command(cwd).execute('touch %s' % added_file)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
292
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
293 Command(cwd).execute('hg add %s' % added_file)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
294
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
295 for i in xrange(commits):
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
296 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
297 Command(cwd).execute(cmd)
809
7b18e7ca66da extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents: 790
diff changeset
298
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
299 cmd = """hg ci -m 'commited new %s' -u '%s' %s """ % (i,
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
300 'Marcin Kuźminski <marcin@python-blog.com>',
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
301 added_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
302 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
303
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
304 push_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
305 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
306 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
307 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
308 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
309 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
310
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
311 Command(cwd).execute('hg push --verbose --debug %s' % push_url)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
312
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
313 @test_wrapp
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
314 def test_push_wrong_credentials():
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
315 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
316 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
317 {'user':USER + 'xxx',
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
318 'pass':PASS,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
319 'host':HOST,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
320 'cloned_repo':HG_REPO,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
321 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
809
7b18e7ca66da extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents: 790
diff changeset
322
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
323 modified_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py')
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
324 for i in xrange(5):
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
325 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
326 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
327
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
328 cmd = """hg ci -m 'commited %s' %s """ % (i, modified_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
329 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
330
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
331 Command(cwd).execute('hg push %s' % clone_url)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
332
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
333 @test_wrapp
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
334 def test_push_wrong_path():
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
335 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
336 added_file = jn(path, 'somefile.py')
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
337
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
338 try:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
339 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
340 os.makedirs(path)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
341 print '\tmade dirs %s' % jn(path)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
342 except OSError:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
343 raise
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
344
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
345 Command(cwd).execute("""echo '' > %s""" % added_file)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
346 Command(cwd).execute("""hg init %s""" % path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
347 Command(cwd).execute("""hg add %s""" % added_file)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
348
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
349 for i in xrange(2):
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
350 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
351 Command(cwd).execute(cmd)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
352
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
353 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
354 Command(cwd).execute(cmd)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
355
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
356 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
357 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
358 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
359 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
360 'cloned_repo':HG_REPO + '_error',
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
361 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
362
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
363 stdout, stderr = Command(cwd).execute('hg push %s' % clone_url)
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
364 if not """abort: HTTP Error 403: Forbidden""" in stderr:
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
365 raise Exception('Failure')
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
366
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
367 @test_wrapp
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
368 def get_logs():
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
369 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
370 return len(sa.query(UserLog).all())
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
371
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
372 @test_wrapp
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
373 def test_logs(initial):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
374 sa = get_session()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
375 logs = sa.query(UserLog).all()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
376 operations = 7
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
377 if initial + operations != len(logs):
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
378 raise Exception("missing number of logs %s vs %s" % (initial, len(logs)))
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
379
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
380
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
381 if __name__ == '__main__':
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
382 create_test_user(force=False)
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
383 create_test_repo()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
384
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
385 initial_logs = get_logs()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
386
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
387 # test_push_modify_file()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
388 test_clone_with_credentials()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
389 test_clone_wrong_credentials()
910
811fa5d45de8 Rewrite simehg for enabling cloning with raw url for anonymous access + some optimizations for making less queries when authenticating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 909
diff changeset
390
988
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
391
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
392 test_push_new_file(commits=2, with_clone=True)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
393
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
394 test_clone_anonymous()
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
395 test_push_wrong_path()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
396
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
397
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
398 test_push_wrong_credentials()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
399
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
400 test_logs(initial_logs)