Show More
@@ -1,24 +1,118 | |||||
1 | #!/bin/bash |
|
1 | # -*- coding: utf-8 -*- | |
2 | repo=/tmp/vcs_test_hg_clone |
|
2 | """ | |
3 | repo_name=vcs_test_hg |
|
3 | rhodecode.tests.test_hg_operations | |
4 | user=test_admin |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | password=test12 |
|
5 | ||
6 | echo 'removing repo '$repo |
|
6 | Test suite for making push/pull operations | |
7 | rm -rf '$repo' |
|
7 | ||
8 | hg clone http://$user:$password@127.0.0.1:5000/$repo_name $repo |
|
8 | :created_on: Dec 30, 2010 | |
9 | cd $repo |
|
9 | :copyright: (c) 2010 by marcink. | |
10 | echo 'some' >> $repo/setup.py && hg ci -m 'ci1' && \ |
|
10 | :license: LICENSE_NAME, see LICENSE_FILE for more details. | |
11 | echo 'some' >> $repo/setup.py && hg ci -m 'ci2' && \ |
|
11 | """ | |
12 | echo 'some' >> $repo/setup.py && hg ci -m 'ci3' && \ |
|
12 | ||
13 | echo 'some' >> $repo/setup.py && hg ci -m 'ci4' && \ |
|
13 | import os | |
14 | hg push |
|
14 | import shutil | |
|
15 | import logging | |||
|
16 | ||||
|
17 | from subprocess import Popen, PIPE | |||
|
18 | ||||
|
19 | from os.path import join as jn | |||
|
20 | ||||
|
21 | from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO | |||
|
22 | ||||
|
23 | USER = 'test_admin' | |||
|
24 | PASS = 'test12' | |||
|
25 | HOST = '127.0.0.1:5000' | |||
|
26 | ||||
|
27 | log = logging.getLogger(__name__) | |||
|
28 | ||||
|
29 | def __execute_cmd(cmd, *args): | |||
|
30 | """Runs command on the system with given ``args``. | |||
|
31 | """ | |||
|
32 | ||||
|
33 | command = cmd + ' ' + ' '.join(args) | |||
|
34 | log.debug('Executing %s' % command) | |||
|
35 | print command | |||
|
36 | p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) | |||
|
37 | stdout, stderr = p.communicate() | |||
|
38 | print stdout, stderr | |||
|
39 | return stdout, stderr | |||
|
40 | ||||
|
41 | ||||
|
42 | #=============================================================================== | |||
|
43 | # TESTS | |||
|
44 | #=============================================================================== | |||
|
45 | def test_clone(): | |||
|
46 | #rm leftovers | |||
|
47 | try: | |||
|
48 | log.debug('removing old directory') | |||
|
49 | shutil.rmtree(jn(TESTS_TMP_PATH, HG_REPO)) | |||
|
50 | except OSError: | |||
|
51 | pass | |||
|
52 | ||||
|
53 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \ | |||
|
54 | {'user':USER, | |||
|
55 | 'pass':PASS, | |||
|
56 | 'host':HOST, | |||
|
57 | 'cloned_repo':HG_REPO, | |||
|
58 | 'dest':jn(TESTS_TMP_PATH, HG_REPO)} | |||
15 |
|
59 | |||
16 | echo 'new file' >> $repo/new_file.py |
|
60 | stdout, stderr = __execute_cmd('hg clone', clone_url) | |
17 | hg add $repo/new_file.py |
|
61 | ||
|
62 | def test_pull(): | |||
|
63 | pass | |||
|
64 | ||||
|
65 | def test_push(): | |||
|
66 | ||||
|
67 | modified_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py') | |||
|
68 | for i in xrange(5): | |||
|
69 | cmd = """echo 'added_line%s' >> %s""" % (i, modified_file) | |||
|
70 | __execute_cmd(cmd) | |||
|
71 | ||||
|
72 | cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file) | |||
|
73 | __execute_cmd(cmd) | |||
|
74 | ||||
|
75 | __execute_cmd('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) | |||
|
76 | ||||
|
77 | def test_push_new_file(): | |||
|
78 | added_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py') | |||
|
79 | ||||
|
80 | __execute_cmd('touch %s' % added_file) | |||
|
81 | ||||
|
82 | __execute_cmd('hg addremove %s' % added_file) | |||
|
83 | ||||
|
84 | for i in xrange(15): | |||
|
85 | cmd = """echo 'added_line%s' >> %s""" % (i, added_file) | |||
|
86 | __execute_cmd(cmd) | |||
18 |
|
87 | |||
19 | for i in {1..15} |
|
88 | cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file) | |
20 | do |
|
89 | __execute_cmd(cmd) | |
21 | echo "line $i" >> $repo/new_file.py && hg ci -m "autocommit $i" |
|
90 | ||
22 | done |
|
91 | __execute_cmd('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO)) | |
|
92 | ||||
|
93 | def test_push_wrong_credentials(): | |||
|
94 | ||||
|
95 | clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \ | |||
|
96 | {'user':USER + 'xxx', | |||
|
97 | 'pass':PASS, | |||
|
98 | 'host':HOST, | |||
|
99 | 'cloned_repo':HG_REPO, | |||
|
100 | 'dest':jn(TESTS_TMP_PATH, HG_REPO)} | |||
23 |
|
101 | |||
24 | hg push No newline at end of file |
|
102 | modified_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py') | |
|
103 | for i in xrange(5): | |||
|
104 | cmd = """echo 'added_line%s' >> %s""" % (i, modified_file) | |||
|
105 | __execute_cmd(cmd) | |||
|
106 | ||||
|
107 | cmd = """hg ci -m 'commited %s' %s """ % (i, modified_file) | |||
|
108 | __execute_cmd(cmd) | |||
|
109 | ||||
|
110 | __execute_cmd('hg push %s' % clone_url) | |||
|
111 | ||||
|
112 | ||||
|
113 | ||||
|
114 | if __name__ == '__main__': | |||
|
115 | test_push_wrong_credentials() | |||
|
116 | #test_clone() | |||
|
117 | #test_push_new_file() | |||
|
118 |
General Comments 0
You need to be logged in to leave comments.
Login now