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