Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: tests/gcl_unittest.py

Issue 4218006: Add rietveld member to ChangeInfo and use this value to contact rietveld. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gcl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for gcl.py.""" 6 """Unit tests for gcl.py."""
7 7
8 # Fixes include path. 8 # Fixes include path.
9 from super_mox import mox, SuperMoxTestBase 9 from super_mox import mox, SuperMoxTestBase
10 10
11 import gcl 11 import gcl
12 12
13 13
14 class GclTestsBase(SuperMoxTestBase): 14 class GclTestsBase(SuperMoxTestBase):
15 """Setups and tear downs the mocks but doesn't test anything as-is.""" 15 """Setups and tear downs the mocks but doesn't test anything as-is."""
16 def setUp(self): 16 def setUp(self):
17 SuperMoxTestBase.setUp(self) 17 SuperMoxTestBase.setUp(self)
18 self.fake_root_dir = self.RootDir() 18 self.fake_root_dir = self.RootDir()
19 self.mox.StubOutWithMock(gcl, 'RunShell') 19 self.mox.StubOutWithMock(gcl, 'RunShell')
20 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo') 20 self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo')
21 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot') 21 self.mox.StubOutWithMock(gcl.SVN, 'GetCheckoutRoot')
22 self.mox.StubOutWithMock(gcl, 'tempfile') 22 self.mox.StubOutWithMock(gcl, 'tempfile')
23 self.mox.StubOutWithMock(gcl.upload, 'RealMain') 23 self.mox.StubOutWithMock(gcl.upload, 'RealMain')
24 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead') 24 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead')
25 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite') 25 self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite')
26 gcl.REPOSITORY_ROOT = None 26 gcl.REPOSITORY_ROOT = None
27 self.old_review_settings = gcl.CODEREVIEW_SETTINGS
28 self.assertEquals(gcl.CODEREVIEW_SETTINGS, {})
29
30 def tearDown(self):
31 gcl.CODEREVIEW_SETTINGS = self.old_review_settings
27 32
28 33
29 class GclUnittest(GclTestsBase): 34 class GclUnittest(GclTestsBase):
30 """General gcl.py tests.""" 35 """General gcl.py tests."""
31 def tearDown(self): 36 def tearDown(self):
32 gcl.CODEREVIEW_SETTINGS = {} 37 gcl.CODEREVIEW_SETTINGS = {}
33 38
34 def testMembersChanged(self): 39 def testMembersChanged(self):
35 self.mox.ReplayAll() 40 self.mox.ReplayAll()
36 members = [ 41 members = [
37 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 42 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE',
38 'CODEREVIEW_SETTINGS_FILE_NOT_FOUND', 43 'CODEREVIEW_SETTINGS_FILE_NOT_FOUND',
39 'CMDchange', 'CMDchanges', 'CMDcommit', 'CMDdelete', 'CMDdeleteempties', 44 'CMDchange', 'CMDchanges', 'CMDcommit', 'CMDdelete', 'CMDdeleteempties',
40 'CMDdescription', 'CMDdiff', 'CMDhelp', 'CMDlint', 'CMDnothave', 45 'CMDdescription', 'CMDdiff', 'CMDhelp', 'CMDlint', 'CMDnothave',
41 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings', 46 'CMDopened', 'CMDpassthru', 'CMDpresubmit', 'CMDrename', 'CMDsettings',
42 'CMDstatus', 'CMDtry', 'CMDupload', 47 'CMDstatus', 'CMDtry', 'CMDupload',
43 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX', 48 'ChangeInfo', 'Command', 'DEFAULT_LINT_IGNORE_REGEX',
44 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks', 49 'DEFAULT_LINT_REGEX', 'CheckHomeForFile', 'DoPresubmitChecks',
45 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage', 50 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenUsage',
46 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir', 51 'GenerateChangeName', 'GenerateDiff', 'GetCLs', 'GetCacheDir',
47 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir', 52 'GetCachedFile', 'GetChangelistInfoFile', 'GetChangesDir',
48 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir', 53 'GetCodeReviewSetting', 'GetEditor', 'GetFilesNotInCL', 'GetInfoDir',
49 'GetIssueDescription', 'GetModifiedFiles', 'GetRepositoryRoot', 54 'GetModifiedFiles', 'GetRepositoryRoot', 'ListFiles',
50 'ListFiles',
51 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 55 'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG',
52 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT', 56 'OptionallyDoPresubmitChecks', 'REPOSITORY_ROOT',
53 'RunShell', 'RunShellWithReturnCode', 'SVN', 57 'RunShell', 'RunShellWithReturnCode', 'SVN',
54 'SendToRietveld', 'TryChange', 'UnknownFiles', 'Warn', 58 'TryChange', 'UnknownFiles', 'Warn',
55 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass', 59 'attrs', 'breakpad', 'defer_attributes', 'gclient_utils', 'getpass',
56 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'os', 60 'json', 'main', 'need_change', 'need_change_and_args', 'no_args', 'os',
57 'random', 're', 'string', 'subprocess', 'sys', 'tempfile', 61 'random', 're', 'string', 'subprocess', 'sys', 'tempfile',
58 'time', 'upload', 'urllib2', 62 'time', 'upload', 'urllib2',
59 ] 63 ]
60 # If this test fails, you should add the relevant test. 64 # If this test fails, you should add the relevant test.
61 self.compareMembers(gcl, members) 65 self.compareMembers(gcl, members)
62 66
63 def testIsSVNMoved(self): 67 def testIsSVNMoved(self):
64 # TODO(maruel): TEST ME 68 # TODO(maruel): TEST ME
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 134
131 class ChangeInfoUnittest(GclTestsBase): 135 class ChangeInfoUnittest(GclTestsBase):
132 def setUp(self): 136 def setUp(self):
133 GclTestsBase.setUp(self) 137 GclTestsBase.setUp(self)
134 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile') 138 self.mox.StubOutWithMock(gcl, 'GetChangelistInfoFile')
135 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') 139 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot')
136 140
137 def testChangeInfoMembers(self): 141 def testChangeInfoMembers(self):
138 self.mox.ReplayAll() 142 self.mox.ReplayAll()
139 members = [ 143 members = [
140 'CloseIssue', 'Delete', 'GetFiles', 'GetFileNames', 'GetLocalRoot', 144 'CloseIssue', 'Delete', 'Exists', 'GetFiles', 'GetFileNames',
141 'Exists', 'Load', 'MissingTests', 'NeedsUpload', 'Save', 145 'GetLocalRoot', 'GetIssueDescription', 'Load', 'MissingTests',
142 'UpdateRietveldDescription', 'description', 'issue', 'name', 146 'NeedsUpload', 'PrimeLint', 'Save', 'SendToRietveld',
143 'needs_upload', 'patch', 'patchset', 147 'UpdateRietveldDescription',
148 'description', 'issue', 'name',
149 'needs_upload', 'patch', 'patchset', 'rietveld',
144 ] 150 ]
145 # If this test fails, you should add the relevant test. 151 # If this test fails, you should add the relevant test.
146 self.compareMembers(gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir), 152 self.compareMembers(
147 members) 153 gcl.ChangeInfo('', 0, 0, '', None, self.fake_root_dir, 'foo'),
154 members)
148 155
149 def testChangeInfoBase(self): 156 def testChangeInfoBase(self):
150 files = [('M', 'foo'), ('A', 'bar')] 157 files = [('M', 'foo'), ('A', 'bar')]
151 self.mox.ReplayAll() 158 self.mox.ReplayAll()
152 o = gcl.ChangeInfo('name2', '42', '53', 'description2', files, 159 o = gcl.ChangeInfo('name2', '42', '53', 'description2', files,
153 self.fake_root_dir) 160 self.fake_root_dir, 'foo')
154 self.assertEquals(o.name, 'name2') 161 self.assertEquals(o.name, 'name2')
155 self.assertEquals(o.issue, 42) 162 self.assertEquals(o.issue, 42)
156 self.assertEquals(o.patchset, 53) 163 self.assertEquals(o.patchset, 53)
157 self.assertEquals(o.description, 'description2') 164 self.assertEquals(o.description, 'description2')
158 self.assertEquals(o.patch, None) 165 self.assertEquals(o.patch, None)
159 self.assertEquals(o.GetFileNames(), ['foo', 'bar']) 166 self.assertEquals(o.GetFileNames(), ['foo', 'bar'])
160 self.assertEquals(o.GetFiles(), files) 167 self.assertEquals(o.GetFiles(), files)
161 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir) 168 self.assertEquals(o.GetLocalRoot(), self.fake_root_dir)
162 169
163 def testLoadWithIssue(self): 170 def testLoadWithIssue(self):
171 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
164 description = ["This is some description.", "force an extra separator."] 172 description = ["This is some description.", "force an extra separator."]
165 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 173 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
166 gcl.os.path.exists('bleeeh').AndReturn(True) 174 gcl.os.path.exists('bleeeh').AndReturn(True)
167 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( 175 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
168 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description)) 176 gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description))
177 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
169 # Does an upgrade. 178 # Does an upgrade.
170 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 179 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
171 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) 180 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
172 self.mox.ReplayAll() 181 self.mox.ReplayAll()
173 182
174 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 183 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
175 self.assertEquals(change_info.name, 'bleh') 184 self.assertEquals(change_info.name, 'bleh')
176 self.assertEquals(change_info.issue, 42) 185 self.assertEquals(change_info.issue, 42)
177 self.assertEquals(change_info.patchset, 53) 186 self.assertEquals(change_info.patchset, 53)
178 self.assertEquals(change_info.description, 187 self.assertEquals(change_info.description,
179 gcl.ChangeInfo._SEPARATOR.join(description)) 188 gcl.ChangeInfo._SEPARATOR.join(description))
180 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')]) 189 self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')])
181 190
182 def testLoadEmpty(self): 191 def testLoadEmpty(self):
192 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
183 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 193 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
184 gcl.os.path.exists('bleeeh').AndReturn(True) 194 gcl.os.path.exists('bleeeh').AndReturn(True)
185 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn( 195 gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
186 gcl.ChangeInfo._SEPARATOR.join(["", "", ""])) 196 gcl.ChangeInfo._SEPARATOR.join(["", "", ""]))
197 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo')
187 # Does an upgrade. 198 # Does an upgrade.
188 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') 199 gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
189 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) 200 gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg())
190 self.mox.ReplayAll() 201 self.mox.ReplayAll()
191 202
192 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) 203 change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False)
193 self.assertEquals(change_info.name, 'bleh') 204 self.assertEquals(change_info.name, 'bleh')
194 self.assertEquals(change_info.issue, 0) 205 self.assertEquals(change_info.issue, 0)
195 self.assertEquals(change_info.patchset, 0) 206 self.assertEquals(change_info.patchset, 0)
196 self.assertEquals(change_info.description, "") 207 self.assertEquals(change_info.description, "")
197 self.assertEquals(change_info.GetFiles(), []) 208 self.assertEquals(change_info.GetFiles(), [])
198 209
199 def testSaveEmpty(self): 210 def testSaveEmpty(self):
200 gcl.GetChangelistInfoFile('').AndReturn('foo') 211 gcl.GetChangelistInfoFile('').AndReturn('foo')
201 values = { 212 values = {
202 'description': '', 'patchset': 2, 'issue': 1, 213 'description': '', 'patchset': 2, 'issue': 1,
203 'files': [], 'needs_upload': False} 214 'files': [], 'needs_upload': False, 'rietveld': 'foo'}
204 gcl.gclient_utils.FileWrite( 215 gcl.gclient_utils.FileWrite(
205 'foo', gcl.json.dumps(values, sort_keys=True, indent=2)) 216 'foo', gcl.json.dumps(values, sort_keys=True, indent=2))
206 self.mox.ReplayAll() 217 self.mox.ReplayAll()
207 218
208 change_info = gcl.ChangeInfo('', 1, 2, '', None, self.fake_root_dir) 219 change_info = gcl.ChangeInfo('', 1, 2, '', None, self.fake_root_dir, 'foo')
209 change_info.Save() 220 change_info.Save()
210 221
211 def testSaveDirty(self): 222 def testSaveDirty(self):
212 gcl.GetChangelistInfoFile('n').AndReturn('foo') 223 gcl.GetChangelistInfoFile('n').AndReturn('foo')
213 values = { 224 values = {
214 'description': 'des', 'patchset': 0, 'issue': 0, 225 'description': 'des', 'patchset': 0, 'issue': 0,
215 'files': [], 'needs_upload': True} 226 'files': [], 'needs_upload': True, 'rietveld': 'foo'}
216 gcl.gclient_utils.FileWrite( 227 gcl.gclient_utils.FileWrite(
217 'foo', gcl.json.dumps(values, sort_keys=True, indent=2)) 228 'foo', gcl.json.dumps(values, sort_keys=True, indent=2))
218 self.mox.ReplayAll() 229 self.mox.ReplayAll()
219 230
220 change_info = gcl.ChangeInfo('n', 0, 0, 'des', None, self.fake_root_dir, 231 change_info = gcl.ChangeInfo('n', 0, 0, 'des', None, self.fake_root_dir,
221 needs_upload=True) 232 'foo', needs_upload=True)
222 change_info.Save() 233 change_info.Save()
223 234
224 235
225 class CMDuploadUnittest(GclTestsBase): 236 class CMDuploadUnittest(GclTestsBase):
226 def setUp(self): 237 def setUp(self):
227 GclTestsBase.setUp(self) 238 GclTestsBase.setUp(self)
228 self.mox.StubOutWithMock(gcl, 'CheckHomeForFile') 239 self.mox.StubOutWithMock(gcl, 'CheckHomeForFile')
229 self.mox.StubOutWithMock(gcl, 'DoPresubmitChecks') 240 self.mox.StubOutWithMock(gcl, 'DoPresubmitChecks')
230 self.mox.StubOutWithMock(gcl, 'GenerateDiff') 241 self.mox.StubOutWithMock(gcl, 'GenerateDiff')
231 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') 242 self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting')
232 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot') 243 self.mox.StubOutWithMock(gcl, 'GetRepositoryRoot')
233 self.mox.StubOutWithMock(gcl, 'SendToRietveld') 244 self.mox.StubOutWithMock(gcl.ChangeInfo, 'SendToRietveld')
234 self.mox.StubOutWithMock(gcl, 'TryChange') 245 self.mox.StubOutWithMock(gcl, 'TryChange')
235 self.mox.StubOutWithMock(gcl.ChangeInfo, 'Load') 246 self.mox.StubOutWithMock(gcl.ChangeInfo, 'Load')
236 247
237 def testNew(self): 248 def testNew(self):
238 change_info = self.mox.CreateMock(gcl.ChangeInfo) 249 change_info = self.mox.CreateMock(gcl.ChangeInfo)
239 change_info.name = 'naame' 250 change_info.name = 'naame'
240 change_info.issue = 1 251 change_info.issue = 1
241 change_info.patchset = 0 252 change_info.patchset = 0
242 change_info.description = 'deescription', 253 change_info.description = 'deescription',
243 change_info.files = [('A', 'aa'), ('M', 'bb')] 254 change_info.files = [('A', 'aa'), ('M', 'bb')]
244 change_info.patch = None 255 change_info.patch = None
256 change_info.rietveld = 'my_server'
245 files = [item[1] for item in change_info.files] 257 files = [item[1] for item in change_info.files]
246 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) 258 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
247 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server') 259 #gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
248 gcl.os.getcwd().AndReturn('somewhere') 260 gcl.os.getcwd().AndReturn('somewhere')
249 change_info.GetFiles().AndReturn(change_info.files) 261 change_info.GetFiles().AndReturn(change_info.files)
250 change_info.GetLocalRoot().AndReturn('proout') 262 change_info.GetLocalRoot().AndReturn('proout')
251 gcl.os.chdir('proout') 263 gcl.os.chdir('proout')
252 change_info.GetFileNames().AndReturn(files) 264 change_info.GetFileNames().AndReturn(files)
253 gcl.GenerateDiff(files) 265 gcl.GenerateDiff(files)
254 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', 266 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server',
255 '-r', 'georges@example.com', 267 '-r', 'georges@example.com',
256 '--message=\'\'', '--issue=1'], 268 '--message=\'\'', '--issue=1'],
257 change_info.patch).AndReturn(("1", 269 change_info.patch).AndReturn(("1",
258 "2")) 270 "2"))
259 gcl.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=0.5) 271 change_info.Save()
272 change_info.PrimeLint()
260 gcl.os.chdir('somewhere') 273 gcl.os.chdir('somewhere')
261 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" 274 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to"
262 " submit a try. ***") 275 " submit a try. ***")
263 gcl.sys.stdout.write("\n") 276 gcl.sys.stdout.write("\n")
264 change_info.Save()
265 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) 277 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir)
266 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True 278 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True
267 ).AndReturn(change_info) 279 ).AndReturn(change_info)
268 self.mox.ReplayAll() 280 self.mox.ReplayAll()
269 281
270 gcl.CMDupload(['naame', '-r', 'georges@example.com']) 282 gcl.CMDupload(['naame', '-r', 'georges@example.com'])
271 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' 283 self.checkstdout('*** Upload does not submit a try; use gcl try to submit '
272 'a try. ***\n' 284 'a try. ***\n'
273 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') 285 '*** Upload does not submit a try; use gcl try to submit a try. ***\n')
274 286
275 def testServerOverride(self): 287 def testServerOverride(self):
276 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', 288 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
277 [('A', 'aa'), ('M', 'bb')], 289 [('A', 'aa'), ('M', 'bb')],
278 self.fake_root_dir) 290 self.fake_root_dir, 'my_server')
279 self.mox.StubOutWithMock(change_info, 'Save') 291 self.mox.StubOutWithMock(change_info, 'Save')
280 change_info.Save() 292 change_info.Save()
281 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) 293 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
282 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
283 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) 294 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
284 gcl.os.write(42, change_info.description) 295 gcl.os.write(42, change_info.description)
285 gcl.os.close(42) 296 gcl.os.close(42)
286 gcl.GetCodeReviewSetting('CC_LIST') 297 gcl.GetCodeReviewSetting('CC_LIST')
287 gcl.GetCodeReviewSetting('PRIVATE') 298 gcl.GetCodeReviewSetting('PRIVATE')
288 gcl.os.getcwd().AndReturn('somewhere') 299 gcl.os.getcwd().AndReturn('somewhere')
289 gcl.os.chdir(change_info.GetLocalRoot()) 300 gcl.os.chdir(change_info.GetLocalRoot())
290 gcl.GenerateDiff(change_info.GetFileNames()) 301 gcl.GenerateDiff(change_info.GetFileNames())
291 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', '--server=a', 302 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', '--server=a',
292 "--description_file=descfile", 303 "--description_file=descfile",
293 "--message=deescription"], change_info.patch).AndReturn(("1", "2")) 304 "--message=deescription"], change_info.patch).AndReturn(("1", "2"))
294 gcl.os.remove('descfile') 305 gcl.os.remove('descfile')
295 gcl.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=0.5) 306 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1)
296 gcl.os.chdir('somewhere') 307 gcl.os.chdir('somewhere')
297 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" 308 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to"
298 " submit a try. ***") 309 " submit a try. ***")
299 gcl.sys.stdout.write("\n") 310 gcl.sys.stdout.write("\n")
300 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) 311 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir)
301 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True 312 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True
302 ).AndReturn(change_info) 313 ).AndReturn(change_info)
303 self.mox.ReplayAll() 314 self.mox.ReplayAll()
304 315
305 gcl.CMDupload(['naame', '--server=a', '--no_watchlists']) 316 gcl.CMDupload(['naame', '--server=a', '--no_watchlists'])
306 self.checkstdout('*** Upload does not submit a try; use gcl try to submit ' 317 self.checkstdout('*** Upload does not submit a try; use gcl try to submit '
307 'a try. ***\n' 318 'a try. ***\n'
308 '*** Upload does not submit a try; use gcl try to submit a try. ***\n') 319 '*** Upload does not submit a try; use gcl try to submit a try. ***\n')
309 320
310 def testNormal(self): 321 def testNormal(self):
311 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription', 322 change_info = gcl.ChangeInfo('naame', 0, 0, 'deescription',
312 [('A', 'aa'), ('M', 'bb')], 323 [('A', 'aa'), ('M', 'bb')],
313 self.fake_root_dir) 324 self.fake_root_dir, 'my_server')
314 self.mox.StubOutWithMock(change_info, 'Save') 325 self.mox.StubOutWithMock(change_info, 'Save')
315 change_info.Save() 326 change_info.Save()
316 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True) 327 gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
317 gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
318 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) 328 gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
319 gcl.os.write(42, change_info.description) 329 gcl.os.write(42, change_info.description)
320 gcl.os.close(42) 330 gcl.os.close(42)
321 gcl.GetCodeReviewSetting('CC_LIST') 331 gcl.GetCodeReviewSetting('CC_LIST')
322 gcl.GetCodeReviewSetting('PRIVATE') 332 gcl.GetCodeReviewSetting('PRIVATE')
323 gcl.os.getcwd().AndReturn('somewhere') 333 gcl.os.getcwd().AndReturn('somewhere')
324 gcl.os.chdir(change_info.GetLocalRoot()) 334 gcl.os.chdir(change_info.GetLocalRoot())
325 gcl.GenerateDiff(change_info.GetFileNames()) 335 gcl.GenerateDiff(change_info.GetFileNames())
326 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server', 336 gcl.upload.RealMain(['upload.py', '-y', '--server=my_server',
327 "--description_file=descfile", 337 "--description_file=descfile",
328 "--message=deescription"], change_info.patch).AndReturn(("1", "2")) 338 "--message=deescription"], change_info.patch).AndReturn(("1", "2"))
329 gcl.os.remove('descfile') 339 gcl.os.remove('descfile')
330 gcl.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=0.5) 340 change_info.SendToRietveld("/lint/issue%s_%s" % ('1', '2'), timeout=1)
331 gcl.os.chdir('somewhere') 341 gcl.os.chdir('somewhere')
332 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to" 342 gcl.sys.stdout.write("*** Upload does not submit a try; use gcl try to"
333 " submit a try. ***") 343 " submit a try. ***")
334 gcl.sys.stdout.write("\n") 344 gcl.sys.stdout.write("\n")
335 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir) 345 gcl.GetRepositoryRoot().AndReturn(self.fake_root_dir)
336 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True 346 gcl.ChangeInfo.Load('naame', self.fake_root_dir, True, True
337 ).AndReturn(change_info) 347 ).AndReturn(change_info)
338 self.mox.ReplayAll() 348 self.mox.ReplayAll()
339 349
340 gcl.CMDupload(['naame', '--no_watchlists']) 350 gcl.CMDupload(['naame', '--no_watchlists'])
(...skipping 16 matching lines...) Expand all
357 try: 367 try:
358 gcl.CMDupload(['naame', '-s', 'foo']) 368 gcl.CMDupload(['naame', '-s', 'foo'])
359 self.fail() 369 self.fail()
360 except SystemExit: 370 except SystemExit:
361 pass 371 pass
362 372
363 373
364 if __name__ == '__main__': 374 if __name__ == '__main__':
365 import unittest 375 import unittest
366 unittest.main() 376 unittest.main()
OLDNEW
« no previous file with comments | « gcl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698