Mercurial > kallithea
annotate rhodecode/tests/test_hg_operations.py @ 896:af65ca7e5c2b beta
changed mercurial test operations script
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 30 Dec 2010 18:14:37 +0100 |
parents | rhodecode/tests/test_hg_operations.sh@7b18e7ca66da |
children | a7efcee0f399 |
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 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
7 |
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 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
14 import shutil |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
15 import logging |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
16 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
17 from subprocess import Popen, PIPE |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
18 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
19 from os.path import join as jn |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
20 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
21 from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
22 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
23 USER = 'test_admin' |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
24 PASS = 'test12' |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
25 HOST = '127.0.0.1:5000' |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
26 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
27 log = logging.getLogger(__name__) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
28 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
29 def __execute_cmd(cmd, *args): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
30 """Runs command on the system with given ``args``. |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
31 """ |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
32 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
33 command = cmd + ' ' + ' '.join(args) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
34 log.debug('Executing %s' % command) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
35 print command |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
36 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
37 stdout, stderr = p.communicate() |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
38 print stdout, stderr |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
39 return stdout, stderr |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
40 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
41 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
42 #=============================================================================== |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
43 # TESTS |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
44 #=============================================================================== |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
45 def test_clone(): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
46 #rm leftovers |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
47 try: |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
48 log.debug('removing old directory') |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
49 shutil.rmtree(jn(TESTS_TMP_PATH, HG_REPO)) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
50 except OSError: |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
51 pass |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
52 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
53 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
|
54 {'user':USER, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
55 'pass':PASS, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
56 'host':HOST, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
57 'cloned_repo':HG_REPO, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
58 'dest':jn(TESTS_TMP_PATH, HG_REPO)} |
755
99ece4c484e1
Added basic test push/pull script
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 |
896
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
60 stdout, stderr = __execute_cmd('hg clone', clone_url) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
61 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
62 def test_pull(): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
63 pass |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
64 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
65 def test_push(): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
66 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
67 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
|
68 for i in xrange(5): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
69 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
70 __execute_cmd(cmd) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
71 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
72 cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
73 __execute_cmd(cmd) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
74 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
75 __execute_cmd('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
76 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
77 def test_push_new_file(): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
78 added_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
|
79 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
80 __execute_cmd('touch %s' % added_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
81 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
82 __execute_cmd('hg addremove %s' % added_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
83 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
84 for i in xrange(15): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
85 cmd = """echo 'added_line%s' >> %s""" % (i, added_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
86 __execute_cmd(cmd) |
809
7b18e7ca66da
extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents:
790
diff
changeset
|
87 |
896
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
88 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
89 __execute_cmd(cmd) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
90 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
91 __execute_cmd('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
92 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
93 def test_push_wrong_credentials(): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
94 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
95 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
|
96 {'user':USER + 'xxx', |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
97 'pass':PASS, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
98 'host':HOST, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
99 'cloned_repo':HG_REPO, |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
100 'dest':jn(TESTS_TMP_PATH, HG_REPO)} |
809
7b18e7ca66da
extended hg push test script
Marcin Kuzminski <marcin@python-works.com>
parents:
790
diff
changeset
|
101 |
896
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
102 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
|
103 for i in xrange(5): |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
104 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
105 __execute_cmd(cmd) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
106 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
107 cmd = """hg ci -m 'commited %s' %s """ % (i, modified_file) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
108 __execute_cmd(cmd) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
109 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
110 __execute_cmd('hg push %s' % clone_url) |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
111 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
112 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
113 |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
114 if __name__ == '__main__': |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
115 test_push_wrong_credentials() |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
116 #test_clone() |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
117 #test_push_new_file() |
af65ca7e5c2b
changed mercurial test operations script
Marcin Kuzminski <marcin@python-works.com>
parents:
809
diff
changeset
|
118 |