Show More
@@ -1,143 +1,147 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | """ |
|
21 | """ | |
22 | Base for test suite for making push/pull operations. |
|
22 | Base for test suite for making push/pull operations. | |
23 |
|
23 | |||
24 | .. important:: |
|
24 | .. important:: | |
25 |
|
25 | |||
26 | You must have git >= 1.8.5 for tests to work fine. With 68b939b git started |
|
26 | You must have git >= 1.8.5 for tests to work fine. With 68b939b git started | |
27 | to redirect things to stderr instead of stdout. |
|
27 | to redirect things to stderr instead of stdout. | |
28 | """ |
|
28 | """ | |
29 |
|
29 | |||
30 | from os.path import join as jn |
|
30 | from os.path import join as jn | |
31 | from subprocess import Popen, PIPE |
|
31 | from subprocess import Popen, PIPE | |
32 | import logging |
|
32 | import logging | |
33 | import os |
|
33 | import os | |
34 | import tempfile |
|
34 | import tempfile | |
35 |
|
35 | |||
36 | from rhodecode.tests import GIT_REPO, HG_REPO |
|
36 | from rhodecode.tests import GIT_REPO, HG_REPO | |
37 |
|
37 | |||
38 | DEBUG = True |
|
38 | DEBUG = True | |
39 | RC_LOG = os.path.join(tempfile.gettempdir(), 'rc.log') |
|
39 | RC_LOG = os.path.join(tempfile.gettempdir(), 'rc.log') | |
40 | REPO_GROUP = 'a_repo_group' |
|
40 | REPO_GROUP = 'a_repo_group' | |
41 | HG_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, HG_REPO) |
|
41 | HG_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, HG_REPO) | |
42 | GIT_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, GIT_REPO) |
|
42 | GIT_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, GIT_REPO) | |
43 |
|
43 | |||
44 | log = logging.getLogger(__name__) |
|
44 | log = logging.getLogger(__name__) | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | class Command(object): |
|
47 | class Command(object): | |
48 |
|
48 | |||
49 | def __init__(self, cwd): |
|
49 | def __init__(self, cwd): | |
50 | self.cwd = cwd |
|
50 | self.cwd = cwd | |
51 | self.process = None |
|
51 | self.process = None | |
52 |
|
52 | |||
53 | def execute(self, cmd, *args): |
|
53 | def execute(self, cmd, *args): | |
54 | """ |
|
54 | """ | |
55 | Runs command on the system with given ``args``. |
|
55 | Runs command on the system with given ``args``. | |
56 | """ |
|
56 | """ | |
57 |
|
57 | |||
58 | command = cmd + ' ' + ' '.join(args) |
|
58 | command = cmd + ' ' + ' '.join(args) | |
59 | if DEBUG: |
|
59 | if DEBUG: | |
60 | log.debug('*** CMD %s ***' % (command,)) |
|
60 | log.debug('*** CMD %s ***' % (command,)) | |
61 |
|
61 | |||
62 | env = dict(os.environ) |
|
62 | env = dict(os.environ) | |
63 | # Delete coverage variables, as they make the test fail for Mercurial |
|
63 | # Delete coverage variables, as they make the test fail for Mercurial | |
64 | for key in env.keys(): |
|
64 | for key in env.keys(): | |
65 | if key.startswith('COV_CORE_'): |
|
65 | if key.startswith('COV_CORE_'): | |
66 | del env[key] |
|
66 | del env[key] | |
67 |
|
67 | |||
68 | self.process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, |
|
68 | self.process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, | |
69 | cwd=self.cwd, env=env) |
|
69 | cwd=self.cwd, env=env) | |
70 | stdout, stderr = self.process.communicate() |
|
70 | stdout, stderr = self.process.communicate() | |
71 | if DEBUG: |
|
71 | if DEBUG: | |
72 | log.debug('STDOUT:%s' % (stdout,)) |
|
72 | log.debug('STDOUT:%s' % (stdout,)) | |
73 | log.debug('STDERR:%s' % (stderr,)) |
|
73 | log.debug('STDERR:%s' % (stderr,)) | |
74 | return stdout, stderr |
|
74 | return stdout, stderr | |
75 |
|
75 | |||
76 | def assert_returncode_success(self): |
|
76 | def assert_returncode_success(self): | |
77 | assert self.process.returncode == 0 |
|
77 | assert self.process.returncode == 0 | |
78 |
|
78 | |||
79 |
|
79 | |||
80 | def _add_files_and_push(vcs, dest, clone_url=None, **kwargs): |
|
80 | def _add_files_and_push(vcs, dest, clone_url=None, **kwargs): | |
81 | """ |
|
81 | """ | |
82 | Generate some files, add it to DEST repo and push back |
|
82 | Generate some files, add it to DEST repo and push back | |
83 | vcs is git or hg and defines what VCS we want to make those files for |
|
83 | vcs is git or hg and defines what VCS we want to make those files for | |
84 | """ |
|
84 | """ | |
85 | # commit some stuff into this repo |
|
85 | # commit some stuff into this repo | |
86 | cwd = path = jn(dest) |
|
86 | cwd = path = jn(dest) | |
87 | added_file = jn(path, '%ssetup.py' % tempfile._RandomNameSequence().next()) |
|
87 | added_file = jn(path, '%ssetup.py' % tempfile._RandomNameSequence().next()) | |
88 | Command(cwd).execute('touch %s' % added_file) |
|
88 | Command(cwd).execute('touch %s' % added_file) | |
89 | Command(cwd).execute('%s add %s' % (vcs, added_file)) |
|
89 | Command(cwd).execute('%s add %s' % (vcs, added_file)) | |
|
90 | author_str = 'Marcin KuΕΊminski <me@email.com>' | |||
|
91 | ||||
|
92 | git_ident = "git config user.name {} && git config user.email {}".format( | |||
|
93 | 'Marcin KuΕΊminski', 'me@email.com') | |||
90 |
|
94 | |||
91 | for i in xrange(kwargs.get('files_no', 3)): |
|
95 | for i in xrange(kwargs.get('files_no', 3)): | |
92 | cmd = """echo 'added_line%s' >> %s""" % (i, added_file) |
|
96 | cmd = """echo 'added_line%s' >> %s""" % (i, added_file) | |
93 | Command(cwd).execute(cmd) |
|
97 | Command(cwd).execute(cmd) | |
94 | author_str = 'Marcin KuΕΊminski <me@email.com>' |
|
|||
95 | if vcs == 'hg': |
|
98 | if vcs == 'hg': | |
96 | cmd = """hg commit -m 'commited new %s' -u '%s' %s """ % ( |
|
99 | cmd = """hg commit -m 'commited new %s' -u '%s' %s """ % ( | |
97 | i, author_str, added_file |
|
100 | i, author_str, added_file | |
98 | ) |
|
101 | ) | |
99 | elif vcs == 'git': |
|
102 | elif vcs == 'git': | |
100 |
cmd = """ |
|
103 | cmd = """%s && git commit -m 'commited new %s' %s""" % ( | |
101 | """--author '%s' %s """ % (i, author_str, added_file) |
|
104 | git_ident, i, added_file) | |
102 | Command(cwd).execute(cmd) |
|
105 | Command(cwd).execute(cmd) | |
103 |
|
106 | |||
104 | # PUSH it back |
|
107 | # PUSH it back | |
105 | stdout = stderr = None |
|
108 | stdout = stderr = None | |
106 | if vcs == 'hg': |
|
109 | if vcs == 'hg': | |
107 | stdout, stderr = Command(cwd).execute( |
|
110 | stdout, stderr = Command(cwd).execute( | |
108 | 'hg push --verbose', clone_url) |
|
111 | 'hg push --verbose', clone_url) | |
109 | elif vcs == 'git': |
|
112 | elif vcs == 'git': | |
110 | stdout, stderr = Command(cwd).execute( |
|
113 | stdout, stderr = Command(cwd).execute( | |
111 |
|
|
114 | """%s && git push --verbose %s master""" % ( | |
|
115 | git_ident, clone_url)) | |||
112 |
|
116 | |||
113 | return stdout, stderr |
|
117 | return stdout, stderr | |
114 |
|
118 | |||
115 |
|
119 | |||
116 | def _check_proper_git_push( |
|
120 | def _check_proper_git_push( | |
117 | stdout, stderr, branch='master', should_set_default_branch=False): |
|
121 | stdout, stderr, branch='master', should_set_default_branch=False): | |
118 | # Note: Git is writing most information to stderr intentionally |
|
122 | # Note: Git is writing most information to stderr intentionally | |
119 | assert 'fatal' not in stderr |
|
123 | assert 'fatal' not in stderr | |
120 | assert 'rejected' not in stderr |
|
124 | assert 'rejected' not in stderr | |
121 | assert 'Pushing to' in stderr |
|
125 | assert 'Pushing to' in stderr | |
122 | assert '%s -> %s' % (branch, branch) in stderr |
|
126 | assert '%s -> %s' % (branch, branch) in stderr | |
123 |
|
127 | |||
124 | if should_set_default_branch: |
|
128 | if should_set_default_branch: | |
125 | assert "Setting default branch to %s" % branch in stderr |
|
129 | assert "Setting default branch to %s" % branch in stderr | |
126 | else: |
|
130 | else: | |
127 | assert "Setting default branch" not in stderr |
|
131 | assert "Setting default branch" not in stderr | |
128 |
|
132 | |||
129 |
|
133 | |||
130 | def _check_proper_clone(stdout, stderr, vcs): |
|
134 | def _check_proper_clone(stdout, stderr, vcs): | |
131 | if vcs == 'hg': |
|
135 | if vcs == 'hg': | |
132 | assert 'requesting all changes' in stdout |
|
136 | assert 'requesting all changes' in stdout | |
133 | assert 'adding changesets' in stdout |
|
137 | assert 'adding changesets' in stdout | |
134 | assert 'adding manifests' in stdout |
|
138 | assert 'adding manifests' in stdout | |
135 | assert 'adding file changes' in stdout |
|
139 | assert 'adding file changes' in stdout | |
136 |
|
140 | |||
137 | assert stderr == '' |
|
141 | assert stderr == '' | |
138 |
|
142 | |||
139 | if vcs == 'git': |
|
143 | if vcs == 'git': | |
140 | assert '' == stdout |
|
144 | assert '' == stdout | |
141 | assert 'Cloning into' in stderr |
|
145 | assert 'Cloning into' in stderr | |
142 | assert 'abort:' not in stderr |
|
146 | assert 'abort:' not in stderr | |
143 | assert 'fatal:' not in stderr |
|
147 | assert 'fatal:' not in stderr |
General Comments 0
You need to be logged in to leave comments.
Login now