1 | #!/usr/bin/python |
---|
2 | """Automated tests for MergeBot |
---|
3 | |
---|
4 | Run from a Trac source tree with mergebot installed system-wide. (This needs |
---|
5 | to be reworked to be less cumbersome.) |
---|
6 | """ |
---|
7 | |
---|
8 | import os |
---|
9 | import unittest |
---|
10 | import time |
---|
11 | import shutil |
---|
12 | |
---|
13 | from subprocess import call, Popen #, PIPE, STDOUT |
---|
14 | from twill.errors import TwillAssertionError |
---|
15 | |
---|
16 | |
---|
17 | from trac.tests.functional import FunctionalTestSuite, FunctionalTester, FunctionalTwillTestCaseSetup, tc, b, logfile |
---|
18 | from trac.tests.functional.svntestenv import SvnFunctionalTestEnvironment |
---|
19 | from trac.tests.contentgen import random_page, random_sentence #, random_word |
---|
20 | |
---|
21 | |
---|
22 | #class MergeBotTestEnvironment(FunctionalTestEnvironment): |
---|
23 | # """Slight change to FunctionalTestEnvironment to keep the PYTHONPATH from |
---|
24 | # our environment. |
---|
25 | # """ |
---|
26 | # def start(self): |
---|
27 | # """Starts the webserver""" |
---|
28 | # server = Popen(["python", "./trac/web/standalone.py", |
---|
29 | # "--port=%s" % self.port, "-s", |
---|
30 | # "--basic-auth=trac,%s," % self.htpasswd, |
---|
31 | # self.tracdir], |
---|
32 | # #env={'PYTHONPATH':'.'}, |
---|
33 | # stdout=logfile, stderr=logfile, |
---|
34 | # ) |
---|
35 | # self.pid = server.pid |
---|
36 | # time.sleep(1) # Give the server time to come up |
---|
37 | # |
---|
38 | # def _tracadmin(self, *args): |
---|
39 | # """Internal utility method for calling trac-admin""" |
---|
40 | # if call(["python", "./trac/admin/console.py", self.tracdir] + |
---|
41 | # list(args), |
---|
42 | # #env={'PYTHONPATH':'.'}, |
---|
43 | # stdout=logfile, stderr=logfile): |
---|
44 | # raise Exception('Failed running trac-admin with %r' % (args, )) |
---|
45 | # |
---|
46 | # |
---|
47 | #FunctionalTestEnvironment = MergeBotTestEnvironment |
---|
48 | |
---|
49 | |
---|
50 | class MergeBotFunctionalTester(FunctionalTester): |
---|
51 | """Adds some MergeBot functionality to the functional tester.""" |
---|
52 | # FIXME: the tc.find( <various actions> ) checks are bogus: any ticket can |
---|
53 | # satisfy them, not just the one we're working on. |
---|
54 | def __init__(self, trac_url, repo_url): |
---|
55 | FunctionalTester.__init__(self, trac_url) |
---|
56 | self.repo_url = repo_url |
---|
57 | self.mergeboturl = self.url + '/mergebot' |
---|
58 | |
---|
59 | def wait_until_find(self, search, timeout=5): |
---|
60 | start = time.time() |
---|
61 | while time.time() - start < timeout: |
---|
62 | try: |
---|
63 | #tc.reload() # This appears to re-POST |
---|
64 | tc.go(b.get_url()) |
---|
65 | tc.find(search) |
---|
66 | return |
---|
67 | except TwillAssertionError: |
---|
68 | pass |
---|
69 | raise TwillAssertionError("Unable to find %r within %s seconds" % (search, timeout)) |
---|
70 | |
---|
71 | def wait_until_notfind(self, search, timeout=5): |
---|
72 | start = time.time() |
---|
73 | while time.time() - start < timeout: |
---|
74 | try: |
---|
75 | #tc.reload() # This appears to re-POST |
---|
76 | tc.go(b.get_url()) |
---|
77 | tc.notfind(search) |
---|
78 | return |
---|
79 | except TwillAssertionError: |
---|
80 | pass |
---|
81 | raise TwillAssertionError("Unable to notfind %r within %s seconds" % (search, timeout)) |
---|
82 | |
---|
83 | def go_to_mergebot(self): |
---|
84 | tc.go(self.mergeboturl) |
---|
85 | tc.url(self.mergeboturl) |
---|
86 | tc.notfind('No handler matched request to /mergebot') |
---|
87 | |
---|
88 | def branch(self, ticket_id, component, timeout=1): |
---|
89 | """timeout is in seconds.""" |
---|
90 | self.go_to_mergebot() |
---|
91 | tc.formvalue('ops-%s' % ticket_id, 'ticket', ticket_id) # Essentially a noop to select the right form |
---|
92 | tc.submit('Branch') |
---|
93 | self.wait_until_find('Nothing in the queue', timeout) |
---|
94 | tc.find('Rebranch') |
---|
95 | tc.find('Merge') |
---|
96 | tc.find('CheckMerge') |
---|
97 | self.go_to_ticket(ticket_id) |
---|
98 | tc.find('Created branch from .* for .*') |
---|
99 | retval = call(['svn', 'ls', self.repo_url + '/' + component + '/branches/ticket-%s' % ticket_id], |
---|
100 | stdout=logfile, stderr=logfile) |
---|
101 | if retval: |
---|
102 | raise Exception('svn ls failed with exit code %s' % retval) |
---|
103 | |
---|
104 | def _rebranch(self, ticket_id, component, search, timeout=15): |
---|
105 | """timeout is in seconds.""" |
---|
106 | self.go_to_mergebot() |
---|
107 | tc.formvalue('ops-%s' % ticket_id, 'ticket', ticket_id) # Essentially a noop to select the right form |
---|
108 | tc.submit('Rebranch') |
---|
109 | self.wait_until_find('Nothing in the queue', timeout) |
---|
110 | tc.find('Rebranch') |
---|
111 | tc.find('Merge') |
---|
112 | tc.find('CheckMerge') |
---|
113 | self.go_to_ticket(ticket_id) |
---|
114 | tc.find(search) |
---|
115 | retval = call(['svn', 'ls', self.repo_url + '/' + component + '/branches/ticket-%s' % ticket_id], |
---|
116 | stdout=logfile, stderr=logfile) |
---|
117 | if retval: |
---|
118 | raise Exception('svn ls failed with exit code %s' % retval) |
---|
119 | |
---|
120 | def rebranch(self, ticket_id, component, timeout=15): |
---|
121 | self._rebranch(ticket_id, component, 'Rebranched from .* for .*', timeout) |
---|
122 | |
---|
123 | def rebranch_conflict(self, ticket_id, component, timeout=15): |
---|
124 | self._rebranch(ticket_id, component, 'There were conflicts on rebranching', timeout) |
---|
125 | |
---|
126 | def merge(self, ticket_id, component, timeout=5): |
---|
127 | self._merge(ticket_id, component, 'Merged .* to .* for', timeout) |
---|
128 | |
---|
129 | def merge_conflict(self, ticket_id, component, timeout=5): |
---|
130 | self._merge(ticket_id, component, 'Found [0-9]+ conflicts? in attempt to merge ', timeout) |
---|
131 | |
---|
132 | def _merge(self, ticket_id, component, search, timeout=5): |
---|
133 | """timeout is in seconds.""" |
---|
134 | self.go_to_mergebot() |
---|
135 | tc.formvalue('ops-%s' % ticket_id, 'ticket', ticket_id) # Essentially a noop to select the right form |
---|
136 | tc.submit('Merge') |
---|
137 | self.wait_until_find('Nothing in the queue', timeout) |
---|
138 | tc.find('Branch') |
---|
139 | self.go_to_ticket(ticket_id) |
---|
140 | tc.find(search) |
---|
141 | # TODO: We may want to change this to remove the "dead" branch |
---|
142 | retval = call(['svn', 'ls', self.repo_url + '/' + component + '/branches/ticket-%s' % ticket_id], |
---|
143 | stdout=logfile, stderr=logfile) |
---|
144 | if retval: |
---|
145 | raise Exception('svn ls failed with exit code %s' % retval) |
---|
146 | |
---|
147 | def checkmerge(self, ticket_id, component, timeout=5): |
---|
148 | """timeout is in seconds.""" |
---|
149 | self.go_to_mergebot() |
---|
150 | tc.formvalue('ops-%s' % ticket_id, 'ticket', ticket_id) # Essentially a noop to select the right form |
---|
151 | tc.submit('CheckMerge') |
---|
152 | self.wait_until_find('Nothing in the queue', timeout) |
---|
153 | tc.find('Rebranch') |
---|
154 | tc.find('Merge') |
---|
155 | tc.find('CheckMerge') |
---|
156 | self.go_to_ticket(ticket_id) |
---|
157 | tc.find('while checking merge of') |
---|
158 | retval = call(['svn', 'ls', self.repo_url + '/' + component + '/branches/ticket-%s' % ticket_id], |
---|
159 | stdout=logfile, stderr=logfile) |
---|
160 | if retval: |
---|
161 | raise Exception('svn ls failed with exit code %s' % retval) |
---|
162 | |
---|
163 | |
---|
164 | class MergeBotTestSuite(FunctionalTestSuite): |
---|
165 | def setUp(self): |
---|
166 | port = 8889 |
---|
167 | baseurl = "http://localhost:%s" % port |
---|
168 | self._testenv = SvnFunctionalTestEnvironment("testenv%s" % port, port, baseurl) |
---|
169 | |
---|
170 | # Configure mergebot |
---|
171 | env = self._testenv.get_trac_environment() |
---|
172 | env.config.set('components', 'mergebot.web_ui.mergebotmodule', 'enabled') |
---|
173 | env.config.save() |
---|
174 | os.mkdir(os.path.join("testenv%s" % port, 'trac', 'mergebot')) |
---|
175 | self._testenv._tracadmin('upgrade') # sets up the bulk of the mergebot config |
---|
176 | env.config.parse_if_needed() |
---|
177 | env.config.set('mergebot', 'repository_url', self._testenv.repo_url()) |
---|
178 | env.config.set('logging', 'log_type', 'file') |
---|
179 | env.config.save() |
---|
180 | env.config.parse_if_needed() |
---|
181 | |
---|
182 | self._testenv.start() |
---|
183 | self._tester = MergeBotFunctionalTester(baseurl, self._testenv.repo_url()) |
---|
184 | os.system('mergebotdaemon -f "%s" > %s/mergebotdaemon.log 2>&1 &' % (self._testenv.tracdir, self._testenv.tracdir)) |
---|
185 | self.fixture = (self._testenv, self._tester) |
---|
186 | |
---|
187 | # Setup some common component stuff for MergeBot's use: |
---|
188 | svnurl = self._testenv.repo_url() |
---|
189 | for component in ['stuff', 'flagship', 'submarine']: |
---|
190 | self._tester.create_component(component) |
---|
191 | if call(['svn', '-m', 'Create tree for "%s".' % component, 'mkdir', |
---|
192 | svnurl + '/' + component, |
---|
193 | svnurl + '/' + component + '/trunk', |
---|
194 | svnurl + '/' + component + '/tags', |
---|
195 | svnurl + '/' + component + '/branches'], |
---|
196 | stdout=logfile, stderr=logfile): |
---|
197 | raise Exception("svn mkdir failed") |
---|
198 | |
---|
199 | self._tester.create_version('trunk') |
---|
200 | |
---|
201 | |
---|
202 | class FunctionalSvnTestCaseSetup(FunctionalTwillTestCaseSetup): |
---|
203 | def get_workdir(self): |
---|
204 | return os.path.join(self._testenv.dirname, self.__class__.__name__) |
---|
205 | |
---|
206 | def checkout(self, ticket_id=None): |
---|
207 | """checkout a working copy of the branch for the given ticket, or trunk if none given""" |
---|
208 | if ticket_id is None: |
---|
209 | svnurl = self._testenv.repo_url() + '/stuff/trunk' |
---|
210 | else: |
---|
211 | svnurl = self._testenv.repo_url() + '/stuff/branches/ticket-%s' % ticket_id |
---|
212 | retval = call(['svn', 'checkout', svnurl, self.get_workdir()], |
---|
213 | stdout=logfile, stderr=logfile) |
---|
214 | self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval)) |
---|
215 | |
---|
216 | def switch(self, ticket_id=None): |
---|
217 | if ticket_id is None: |
---|
218 | svnurl = self._testenv.repo_url() + '/stuff/trunk' |
---|
219 | else: |
---|
220 | svnurl = self._testenv.repo_url() + '/stuff/branches/ticket-%s' % ticket_id |
---|
221 | retval = call(['svn', 'switch', svnurl, self.get_workdir()], |
---|
222 | stdout=logfile, stderr=logfile) |
---|
223 | self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval)) |
---|
224 | |
---|
225 | def add_new_file(self, filename=None): |
---|
226 | workdir = self.get_workdir() |
---|
227 | if filename is None: |
---|
228 | newfile = os.path.join(workdir, self.__class__.__name__) |
---|
229 | else: |
---|
230 | newfile = os.path.join(workdir, filename) |
---|
231 | open(newfile, 'w').write(random_page()) |
---|
232 | retval = call(['svn', 'add', newfile], |
---|
233 | cwd=workdir, |
---|
234 | stdout=logfile, stderr=logfile) |
---|
235 | self.assertEqual(retval, 0, "svn add failed with error %s" % (retval)) |
---|
236 | |
---|
237 | def commit(self, message, files=None): |
---|
238 | if files is None: |
---|
239 | files = ['.'] |
---|
240 | commit_message = self.__class__.__name__ + ": " + message |
---|
241 | retval = call(['svn', 'commit', '-m', commit_message] + list(files), |
---|
242 | cwd=self.get_workdir(), |
---|
243 | stdout=logfile, stderr=logfile) |
---|
244 | self.assertEqual(retval, 0, "svn commit failed with error %s" % (retval)) |
---|
245 | |
---|
246 | def mv(self, oldname, newname): |
---|
247 | retval = call(['svn', 'mv', oldname, newname], |
---|
248 | cwd=self.get_workdir(), |
---|
249 | stdout=logfile, stderr=logfile) |
---|
250 | self.assertEqual(retval, 0, "svn mv failed with error %s" % (retval)) |
---|
251 | |
---|
252 | |
---|
253 | class MergeBotTestEnabled(FunctionalTwillTestCaseSetup): |
---|
254 | def runTest(self): |
---|
255 | self._tester.logout() |
---|
256 | tc.go(self._tester.url) |
---|
257 | self._tester.login('admin') |
---|
258 | tc.follow('MergeBot') |
---|
259 | mergeboturl = self._tester.url + '/mergebot' |
---|
260 | tc.url(mergeboturl) |
---|
261 | tc.notfind('No handler matched request to /mergebot') |
---|
262 | |
---|
263 | |
---|
264 | class MergeBotTestNoVersion(FunctionalTwillTestCaseSetup): |
---|
265 | """Verify that if a ticket does not have the version field set, it will not |
---|
266 | appear in the MergeBot list. |
---|
267 | """ |
---|
268 | def runTest(self): |
---|
269 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
270 | info={'component':'stuff', 'version':''}) |
---|
271 | tc.follow('MergeBot') |
---|
272 | tc.notfind(self.__class__.__name__) |
---|
273 | |
---|
274 | |
---|
275 | class MergeBotTestBranch(FunctionalTwillTestCaseSetup): |
---|
276 | def runTest(self): |
---|
277 | """Verify that the 'branch' button works""" |
---|
278 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
279 | info={'component':'stuff', 'version':'trunk'}) |
---|
280 | self._tester.branch(ticket_id, 'stuff') |
---|
281 | |
---|
282 | |
---|
283 | class MergeBotTestRebranch(FunctionalTwillTestCaseSetup): |
---|
284 | def runTest(self): |
---|
285 | """Verify that the 'rebranch' button works""" |
---|
286 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
287 | info={'component':'stuff', 'version':'trunk'}) |
---|
288 | self._tester.branch(ticket_id, 'stuff') |
---|
289 | self._tester.rebranch(ticket_id, 'stuff') |
---|
290 | |
---|
291 | |
---|
292 | class MergeBotTestMerge(FunctionalTwillTestCaseSetup): |
---|
293 | def runTest(self): |
---|
294 | """Verify that the 'merge' button works""" |
---|
295 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
296 | info={'component':'stuff', 'version':'trunk'}) |
---|
297 | self._tester.branch(ticket_id, 'stuff') |
---|
298 | self._tester.merge(ticket_id, 'stuff') |
---|
299 | |
---|
300 | |
---|
301 | class MergeBotTestMergeWithChange(FunctionalSvnTestCaseSetup): |
---|
302 | def runTest(self): |
---|
303 | """Verify that the 'merge' button works with changes on the branch""" |
---|
304 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
305 | info={'component':'stuff', 'version':'trunk'}) |
---|
306 | self._tester.branch(ticket_id, 'stuff') |
---|
307 | |
---|
308 | # checkout a working copy & make a change |
---|
309 | self.checkout(ticket_id) |
---|
310 | # Create & add a new file |
---|
311 | self.add_new_file() |
---|
312 | self.commit('Add a new file') |
---|
313 | |
---|
314 | self._tester.merge(ticket_id, 'stuff') |
---|
315 | |
---|
316 | |
---|
317 | class MergeBotTestMergeWithChangeAndTrunkChange(FunctionalSvnTestCaseSetup): |
---|
318 | def runTest(self): |
---|
319 | """Verify that the 'merge' button works with changes on the branch and trunk""" |
---|
320 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
321 | info={'component':'stuff', 'version':'trunk'}) |
---|
322 | self._tester.branch(ticket_id, 'stuff') |
---|
323 | |
---|
324 | # checkout a working copy & make a change |
---|
325 | self.checkout(ticket_id) |
---|
326 | # Create & add a new file |
---|
327 | basename = self.__class__.__name__ |
---|
328 | self.add_new_file(basename + '-ticket') |
---|
329 | self.commit('Add a new file on ticket') |
---|
330 | self.switch() |
---|
331 | self.add_new_file(basename + '-trunk') |
---|
332 | self.commit('Add a new file on trunk') |
---|
333 | |
---|
334 | self._tester.merge(ticket_id, 'stuff') |
---|
335 | |
---|
336 | |
---|
337 | class MergeBotTestMergeWithConflict(FunctionalSvnTestCaseSetup): |
---|
338 | def runTest(self): |
---|
339 | """Verify that the 'merge' button detects conflicts between the branch and trunk""" |
---|
340 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
341 | info={'component':'stuff', 'version':'trunk'}) |
---|
342 | basename = self.__class__.__name__ |
---|
343 | |
---|
344 | # create a file in which to have conflicts |
---|
345 | self.checkout() |
---|
346 | self.add_new_file(basename) |
---|
347 | self.commit('Add a new file on trunk') |
---|
348 | |
---|
349 | # create the branch |
---|
350 | self._tester.branch(ticket_id, 'stuff') |
---|
351 | |
---|
352 | # modify the file on trunk |
---|
353 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
354 | self.commit('Modify the file on trunk') |
---|
355 | |
---|
356 | # modify the file on the branch |
---|
357 | self.switch(ticket_id) |
---|
358 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
359 | self.commit('Modify the file on branch') |
---|
360 | |
---|
361 | # merge, make sure it shows a conflict |
---|
362 | self._tester.merge_conflict(ticket_id, 'stuff') |
---|
363 | |
---|
364 | |
---|
365 | class MergeBotTestMergeWithBranchRenameConflict(FunctionalSvnTestCaseSetup): |
---|
366 | def runTest(self): |
---|
367 | """Verify that the 'merge' button detects a conflict when a file renamed on the branch was modified on trunk""" |
---|
368 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
369 | info={'component':'stuff', 'version':'trunk'}) |
---|
370 | basename = self.__class__.__name__ |
---|
371 | |
---|
372 | # create a file in which to have conflicts |
---|
373 | self.checkout() |
---|
374 | self.add_new_file(basename) |
---|
375 | self.commit('Add a new file on trunk') |
---|
376 | |
---|
377 | # create the branch |
---|
378 | self._tester.branch(ticket_id, 'stuff') |
---|
379 | |
---|
380 | # modify the file on trunk |
---|
381 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
382 | self.commit('Modify the file on trunk') |
---|
383 | |
---|
384 | # rename the file on the branch |
---|
385 | self.switch(ticket_id) |
---|
386 | self.mv(basename, basename + '-renamed') |
---|
387 | self.commit('Rename the file on the branch') |
---|
388 | |
---|
389 | self._tester.merge_conflict(ticket_id, 'stuff') |
---|
390 | |
---|
391 | |
---|
392 | class MergeBotTestMergeWithTrunkRenameConflict(FunctionalSvnTestCaseSetup): |
---|
393 | def runTest(self): |
---|
394 | """Verify that the 'merge' button detects conflicts when a file renamed on trunk was modified on the branch""" |
---|
395 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
396 | info={'component':'stuff', 'version':'trunk'}) |
---|
397 | basename = self.__class__.__name__ |
---|
398 | |
---|
399 | # create a file in which to have conflicts |
---|
400 | self.checkout() |
---|
401 | self.add_new_file(basename) |
---|
402 | self.commit('Add a new file on trunk') |
---|
403 | |
---|
404 | # create the branch |
---|
405 | self._tester.branch(ticket_id, 'stuff') |
---|
406 | |
---|
407 | # rename the file on trunk |
---|
408 | self.mv(basename, basename + '-renamed') |
---|
409 | self.commit('Rename the file on trunk') |
---|
410 | |
---|
411 | # rename the file on the branch |
---|
412 | self.switch(ticket_id) |
---|
413 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
414 | self.commit('Modify the file on the branch') |
---|
415 | |
---|
416 | # make sure it finds the conflict |
---|
417 | self._tester.merge_conflict(ticket_id, 'stuff') |
---|
418 | |
---|
419 | |
---|
420 | class MergeBotTestCheckMerge(FunctionalTwillTestCaseSetup): |
---|
421 | def runTest(self): |
---|
422 | """Verify that the 'checkmerge' button works""" |
---|
423 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
424 | info={'component':'stuff', 'version':'trunk'}) |
---|
425 | self._tester.branch(ticket_id, 'stuff') |
---|
426 | self._tester.checkmerge(ticket_id, 'stuff') |
---|
427 | |
---|
428 | |
---|
429 | class MergeBotTestRebranchWithChange(FunctionalSvnTestCaseSetup): |
---|
430 | def runTest(self): |
---|
431 | """Verify that the 'rebranch' button works with changes on the branch""" |
---|
432 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
433 | info={'component':'stuff', 'version':'trunk'}) |
---|
434 | self._tester.branch(ticket_id, 'stuff') |
---|
435 | |
---|
436 | # checkout a working copy & make a change |
---|
437 | self.checkout(ticket_id) |
---|
438 | # Create & add a new file |
---|
439 | self.add_new_file() |
---|
440 | self.commit('Add a new file') |
---|
441 | |
---|
442 | self._tester.rebranch(ticket_id, 'stuff') |
---|
443 | |
---|
444 | |
---|
445 | class MergeBotTestRebranchWithChangeAndTrunkChange(FunctionalSvnTestCaseSetup): |
---|
446 | def runTest(self): |
---|
447 | """Verify that the 'rebranch' button works with changes on the branch and trunk""" |
---|
448 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
449 | info={'component':'stuff', 'version':'trunk'}) |
---|
450 | self._tester.branch(ticket_id, 'stuff') |
---|
451 | |
---|
452 | # checkout a working copy & make a change |
---|
453 | self.checkout(ticket_id) |
---|
454 | # Create & add a new file |
---|
455 | basename = self.__class__.__name__ |
---|
456 | self.add_new_file(basename + '-ticket') |
---|
457 | self.commit('Add a new file on ticket') |
---|
458 | self.switch() |
---|
459 | self.add_new_file(basename + '-trunk') |
---|
460 | self.commit('Add a new file on trunk') |
---|
461 | |
---|
462 | self._tester.rebranch(ticket_id, 'stuff') |
---|
463 | |
---|
464 | |
---|
465 | class MergeBotTestRebranchWithConflict(FunctionalSvnTestCaseSetup): |
---|
466 | def runTest(self): |
---|
467 | """Verify that the 'rebranch' button detects conflicts between the branch and trunk""" |
---|
468 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
469 | info={'component':'stuff', 'version':'trunk'}) |
---|
470 | basename = self.__class__.__name__ |
---|
471 | |
---|
472 | # create a file in which to have conflicts |
---|
473 | self.checkout() |
---|
474 | self.add_new_file(basename) |
---|
475 | self.commit('Add a new file on trunk') |
---|
476 | |
---|
477 | # create the branch |
---|
478 | self._tester.branch(ticket_id, 'stuff') |
---|
479 | |
---|
480 | # modify the file on trunk |
---|
481 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
482 | self.commit('Modify the file on trunk') |
---|
483 | |
---|
484 | # modify the file on the branch |
---|
485 | self.switch(ticket_id) |
---|
486 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
487 | self.commit('Modify the file on branch') |
---|
488 | |
---|
489 | # rebranch, make sure it shows a conflict |
---|
490 | self._tester.rebranch_conflict(ticket_id, 'stuff') |
---|
491 | |
---|
492 | |
---|
493 | class MergeBotTestRebranchWithBranchRenameConflict(FunctionalSvnTestCaseSetup): |
---|
494 | def runTest(self): |
---|
495 | """Verify that the 'rebranch' button detects a conflict when a file renamed on the branch was modified on trunk""" |
---|
496 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
497 | info={'component':'stuff', 'version':'trunk'}) |
---|
498 | basename = self.__class__.__name__ |
---|
499 | |
---|
500 | # create a file in which to have conflicts |
---|
501 | self.checkout() |
---|
502 | self.add_new_file(basename) |
---|
503 | self.commit('Add a new file on trunk') |
---|
504 | |
---|
505 | # create the branch |
---|
506 | self._tester.branch(ticket_id, 'stuff') |
---|
507 | |
---|
508 | # modify the file on trunk |
---|
509 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
510 | self.commit('Modify the file on trunk') |
---|
511 | |
---|
512 | # rename the file on the branch |
---|
513 | self.switch(ticket_id) |
---|
514 | self.mv(basename, basename + '-renamed') |
---|
515 | self.commit('Rename the file on the branch') |
---|
516 | |
---|
517 | self._tester.rebranch_conflict(ticket_id, 'stuff') |
---|
518 | |
---|
519 | |
---|
520 | class MergeBotTestRebranchWithTrunkRenameConflict(FunctionalSvnTestCaseSetup): |
---|
521 | def runTest(self): |
---|
522 | """Verify that the 'rebranch' button detects conflicts when a file renamed on trunk was modified on the branch""" |
---|
523 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
524 | info={'component':'stuff', 'version':'trunk'}) |
---|
525 | basename = self.__class__.__name__ |
---|
526 | |
---|
527 | # create a file in which to have conflicts |
---|
528 | self.checkout() |
---|
529 | self.add_new_file(basename) |
---|
530 | self.commit('Add a new file on trunk') |
---|
531 | |
---|
532 | # create the branch |
---|
533 | self._tester.branch(ticket_id, 'stuff') |
---|
534 | |
---|
535 | # rename the file on trunk |
---|
536 | self.mv(basename, basename + '-renamed') |
---|
537 | self.commit('Rename the file on trunk') |
---|
538 | |
---|
539 | # rename the file on the branch |
---|
540 | self.switch(ticket_id) |
---|
541 | open(os.path.join(self.get_workdir(), basename), 'a').write(random_sentence()) |
---|
542 | self.commit('Modify the file on the branch') |
---|
543 | |
---|
544 | # make sure it finds the conflict |
---|
545 | self._tester.rebranch_conflict(ticket_id, 'stuff') |
---|
546 | |
---|
547 | |
---|
548 | class MergeBotTestSingleUseCase(FunctionalTwillTestCaseSetup): |
---|
549 | def runTest(self): |
---|
550 | """Create a branch, make a change, checkmerge, and merge it.""" |
---|
551 | ticket_id = self._tester.create_ticket(summary=self.__class__.__name__, |
---|
552 | info={'component':'stuff', 'version':'trunk'}) |
---|
553 | self._tester.branch(ticket_id, 'stuff') |
---|
554 | # checkout a working copy & make a change |
---|
555 | svnurl = self._testenv.repo_url() |
---|
556 | workdir = os.path.join(self._testenv.dirname, self.__class__.__name__) |
---|
557 | retval = call(['svn', 'checkout', svnurl + '/stuff/branches/ticket-%s' % ticket_id, workdir], |
---|
558 | stdout=logfile, stderr=logfile) |
---|
559 | self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval)) |
---|
560 | # Create & add a new file |
---|
561 | newfile = os.path.join(workdir, self.__class__.__name__) |
---|
562 | open(newfile, 'w').write(random_page()) |
---|
563 | retval = call(['svn', 'add', self.__class__.__name__], |
---|
564 | cwd=workdir, |
---|
565 | stdout=logfile, stderr=logfile) |
---|
566 | self.assertEqual(retval, 0, "svn add failed with error %s" % (retval)) |
---|
567 | retval = call(['svn', 'commit', '-m', 'Add a new file', self.__class__.__name__], |
---|
568 | cwd=workdir, |
---|
569 | stdout=logfile, stderr=logfile) |
---|
570 | self.assertEqual(retval, 0, "svn commit failed with error %s" % (retval)) |
---|
571 | |
---|
572 | self._tester.checkmerge(ticket_id, 'stuff') |
---|
573 | self._tester.merge(ticket_id, 'stuff') |
---|
574 | |
---|
575 | shutil.rmtree(workdir) # cleanup working copy |
---|
576 | |
---|
577 | |
---|
578 | def suite(): |
---|
579 | suite = MergeBotTestSuite() |
---|
580 | suite.addTest(MergeBotTestEnabled()) |
---|
581 | suite.addTest(MergeBotTestNoVersion()) |
---|
582 | suite.addTest(MergeBotTestBranch()) |
---|
583 | suite.addTest(MergeBotTestRebranch()) |
---|
584 | suite.addTest(MergeBotTestCheckMerge()) |
---|
585 | suite.addTest(MergeBotTestMerge()) |
---|
586 | suite.addTest(MergeBotTestRebranchWithChange()) |
---|
587 | suite.addTest(MergeBotTestRebranchWithChangeAndTrunkChange()) |
---|
588 | suite.addTest(MergeBotTestRebranchWithConflict()) |
---|
589 | suite.addTest(MergeBotTestRebranchWithBranchRenameConflict()) |
---|
590 | suite.addTest(MergeBotTestRebranchWithTrunkRenameConflict()) |
---|
591 | suite.addTest(MergeBotTestMergeWithChange()) |
---|
592 | suite.addTest(MergeBotTestMergeWithChangeAndTrunkChange()) |
---|
593 | suite.addTest(MergeBotTestMergeWithConflict()) |
---|
594 | suite.addTest(MergeBotTestMergeWithBranchRenameConflict()) |
---|
595 | suite.addTest(MergeBotTestMergeWithTrunkRenameConflict()) |
---|
596 | suite.addTest(MergeBotTestSingleUseCase()) |
---|
597 | return suite |
---|
598 | |
---|
599 | if __name__ == '__main__': |
---|
600 | unittest.main(defaultTest='suite') |
---|