annotate rhodecode/tests/test_hg_operations.py @ 1756:60a00fd76d58 beta

UI !
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 05 Dec 2011 03:31:23 +0200
parents e1e482093077
children 89efedac4e6c
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
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
9 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
10 :license: GPLv3, see COPYING for more details.
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
11 """
1532
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
12 # This program is free software: you can redistribute it and/or modify
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
13 # it under the terms of the GNU General Public License as published by
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
14 # the Free Software Foundation, either version 3 of the License, or
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
15 # (at your option) any later version.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
16 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
17 # This program is distributed in the hope that it will be useful,
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
20 # GNU General Public License for more details.
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
21 #
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
22 # You should have received a copy of the GNU General Public License
2afe9320d5e6 updated docstrings
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
24
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
25 import os
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
26 import time
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
27 import sys
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
28 import shutil
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
29 import logging
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
30
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
31 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
32 from os.path import dirname as dn
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
33
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
34 from tempfile import _RandomNameSequence
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
35 from subprocess import Popen, PIPE
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
36
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
37 from paste.deploy import appconfig
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
38 from pylons import config
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
39 from sqlalchemy import engine_from_config
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
40
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
41 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
42 from rhodecode.model import init_model
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
43 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
44 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
45 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
46
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
47 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
48 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
49
1277
cf2a67b91ffc fixed path for .ini file in test hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
50 rel_path = dn(dn(dn(os.path.abspath(__file__))))
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
51
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
52 conf = appconfig('config:%s' % sys.argv[1], relative_to=rel_path)
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
53 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
54
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
55 add_cache(conf)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
56
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
57 USER = 'test_admin'
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
58 PASS = 'test12'
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
59 HOST = '127.0.0.1:5000'
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
60 DEBUG = False
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
61 print 'DEBUG:', DEBUG
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
62 log = logging.getLogger(__name__)
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
63
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
64 engine = engine_from_config(conf, 'sqlalchemy.db1.')
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
65 init_model(engine)
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
66 sa = meta.Session
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
67
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
68 class Command(object):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
69
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
70 def __init__(self, cwd):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
71 self.cwd = cwd
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
72
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
73 def execute(self, cmd, *args):
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
74 """Runs command on the system with given ``args``.
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
75 """
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
76
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
77 command = cmd + ' ' + ' '.join(args)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
78 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
79 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
80 print command
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
81 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
82 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
83 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
84 print stdout, stderr
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
85 return stdout, stderr
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
86
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
87
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
88 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
89
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
90 def __wrapp(*args, **kwargs):
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1529
diff changeset
91 print '>>>%s' % func.__name__
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
92 try:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
93 res = func(*args, **kwargs)
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
94 except Exception, e:
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
95 print ('###############\n-'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
96 '--%s failed %s--\n'
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
97 '###############\n' % (func.__name__, e))
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
98 sys.exit()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
99 print '++OK++'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
100 return res
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
101 return __wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
102
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
103
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
104 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
105 print '\tcreating test user'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
106
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
107 user = User.get_by_username(USER)
988
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
108
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
109 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
110 print '\tremoving current user'
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
111 for repo in Repository.query().filter(Repository.user == user).all():
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
112 sa.delete(repo)
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
113 sa.delete(user)
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
114 sa.commit()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
115
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
116 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
117 print '\tcreating new one'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
118 new_usr = User()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
119 new_usr.username = USER
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
120 new_usr.password = get_crypt_password(PASS)
988
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
121 new_usr.email = 'mail@mail.com'
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
122 new_usr.name = 'test'
7f4943c90876 fixed test hg operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 930
diff changeset
123 new_usr.lastname = 'lasttestname'
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
124 new_usr.active = True
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
125 new_usr.admin = True
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
126 sa.add(new_usr)
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
127 sa.commit()
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
128
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
129 print '\tdone'
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
130
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
131
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
132 def create_test_repo(force=True):
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
133 from rhodecode.model.repo import RepoModel
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
134
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
135 user = User.get_by_username(USER)
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
136 if user is None:
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
137 raise Exception('user not found')
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
138
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
139
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
140 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
141
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
142 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
143 print '\trepo not found creating'
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
144
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
145 form_data = {'repo_name':HG_REPO,
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
146 'repo_type':'hg',
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
147 'private':False,
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
148 'clone_uri':'' }
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
149 rm = RepoModel(sa)
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
150 rm.base_path = '/home/hg'
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
151 rm.create(form_data, user)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
152
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
153
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
154 def set_anonymous_access(enable=True):
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
155 user = User.get_by_username('default')
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
156 user.active = enable
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
157 sa.add(user)
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
158 sa.commit()
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
159 print '\tanonymous access is now:', enable
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
160 if enable != User.get_by_username('default').active:
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
161 raise Exception('Cannot set anonymous access')
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
162
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
163 def get_anonymous_access():
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
164 user = User.get_by_username('default')
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
165 return user.active
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
166
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
167
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
168 #==============================================================================
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
169 # 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
170 #==============================================================================
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
171 @test_wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
172 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
173 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
174
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
175 try:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
176 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
177 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
178 #print 'made dirs %s' % jn(path)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
179 except OSError:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
180 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
181
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
182 print '\tchecking if anonymous access is enabled'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
183 anonymous_access = get_anonymous_access()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
184 if anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
185 print '\tenabled, disabling it '
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
186 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
187
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
188 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
189 {'user':USER,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
190 'pass':PASS,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
191 'host':HOST,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
192 'cloned_repo':HG_REPO,
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
193 'dest':path}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
194
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
195 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
196
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
197 if no_errors is False:
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
198 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
199 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
200
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
201
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
202 @test_wrapp
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
203 def test_clone_anonymous():
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
204 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
205
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
206 try:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
207 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
208 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
209 #print 'made dirs %s' % jn(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
210 except OSError:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
211 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
212
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
213
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
214 print '\tchecking if anonymous access is enabled'
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
215 anonymous_access = get_anonymous_access()
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
216 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
217 print '\tnot enabled, enabling it '
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
218 set_anonymous_access(enable=True)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
219
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
220 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
221 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
222 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
223 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
224 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
225 'dest':path}
755
99ece4c484e1 Added basic test push/pull script
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
226
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
227 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
228
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
229 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
230 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
231
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
232 #disable if it was enabled
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
233 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
234 print '\tdisabling anonymous access'
1047
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
235 set_anonymous_access(enable=False)
15b60f83420c tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 1008
diff changeset
236
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
237 @test_wrapp
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
238 def test_clone_wrong_credentials():
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
239 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
240
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
241 try:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
242 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
243 os.makedirs(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
244 #print 'made dirs %s' % jn(path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
245 except OSError:
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
246 raise
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
247
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
248 print '\tchecking if anonymous access is enabled'
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
249 anonymous_access = get_anonymous_access()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
250 if anonymous_access:
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
251 print '\tenabled, disabling it '
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
252 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
253
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
254 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
255 {'user':USER + 'error',
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
256 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
257 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
258 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
259 'dest':path}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
260
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
261 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
262
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
263 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
264 raise Exception('Failure')
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
265
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
266 @test_wrapp
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
267 def test_pull():
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
268 pass
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
269
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
270 @test_wrapp
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
271 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
272 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
273 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
274 for i in xrange(5):
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
275 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
276 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
277
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
278 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
279 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
280
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
281 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
282
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
283 @test_wrapp
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
284 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
285
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
286 if with_clone:
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
287 test_clone_with_credentials(no_errors=True)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
288
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
289 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
290 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
291
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
292 Command(cwd).execute('touch %s' % added_file)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
293
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
294 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
295
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
296 for i in xrange(commits):
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
297 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
298 Command(cwd).execute(cmd)
809
7b18e7ca66da extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents: 790
diff changeset
299
1296
1bd6ed0f38b1 small fixes to test_hg_operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 1277
diff changeset
300 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
301 '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
302 added_file)
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
303 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
304
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
305 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
306 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
307 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
308 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
309 'cloned_repo':HG_REPO,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
310 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
311
930
f9016563f987 Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents: 910
diff changeset
312 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
313
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
314 @test_wrapp
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
315 def test_push_wrong_credentials():
1008
a9421a8a874f updated testing script for hg operations
Marcin Kuzminski <marcin@python-works.com>
parents: 988
diff changeset
316 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
317 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
318 {'user':USER + 'xxx',
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
319 'pass':PASS,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
320 'host':HOST,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
321 'cloned_repo':HG_REPO,
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
322 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
809
7b18e7ca66da extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents: 790
diff changeset
323
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
324 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
325 for i in xrange(5):
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
326 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
327 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
328
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
329 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
330 Command(cwd).execute(cmd)
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
331
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
332 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
333
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
334 @test_wrapp
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
335 def test_push_wrong_path():
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
336 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
337 added_file = jn(path, 'somefile.py')
896
af65ca7e5c2b changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 809
diff changeset
338
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
339 try:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
340 shutil.rmtree(path, ignore_errors=True)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
341 os.makedirs(path)
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
342 print '\tmade dirs %s' % jn(path)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
343 except OSError:
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
344 raise
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
345
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
346 Command(cwd).execute("""echo '' > %s""" % added_file)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
347 Command(cwd).execute("""hg init %s""" % path)
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
348 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
349
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
350 for i in xrange(2):
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
351 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
352 Command(cwd).execute(cmd)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
353
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
354 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
355 Command(cwd).execute(cmd)
897
a7efcee0f399 updated mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents: 896
diff changeset
356
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
357 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
358 {'user':USER,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
359 'pass':PASS,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
360 'host':HOST,
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
361 'cloned_repo':HG_REPO + '_error',
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
362 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
363
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
364 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
365 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
366 raise Exception('Failure')
909
1f0e37c0854d fixed hg operations test script
Marcin Kuzminski <marcin@python-works.com>
parents: 897
diff changeset
367
1529
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
368 @test_wrapp
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
369 def get_logs():
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
370 return UserLog.query().all()
1529
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):
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
374 logs = UserLog.query().all()
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
375 operations = 4
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
376 if len(initial) + operations != len(logs):
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
377 raise Exception("missing number of logs initial:%s vs current:%s" % \
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
378 (len(initial), len(logs)))
1529
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()
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
386 print 'initial activity logs: %s' % len(initial_logs)
1715
e1e482093077 tests for changeset comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1596
diff changeset
387 s = time.time()
1596
089ef495e9dd fixed test_hg_push operations
Marcin Kuzminski <marcin@python-works.com>
parents: 1532
diff changeset
388 #test_push_modify_file()
1498
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
389 test_clone_with_credentials()
fcc676c6bf3b updated test_hg_operation script
Marcin Kuzminski <marcin@python-works.com>
parents: 1296
diff changeset
390 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
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 test_push_wrong_credentials()
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
398
0b268dd369ec Fixed test_hg_operations test and added concurency test
Marcin Kuzminski <marcin@python-works.com>
parents: 1498
diff changeset
399 test_logs(initial_logs)
1715
e1e482093077 tests for changeset comments
Marcin Kuzminski <marcin@python-works.com>
parents: 1596
diff changeset
400 print 'finished ok in %.3f' % (time.time() - s)