def test_RetryAccept_NotSuccessful_AndExit(self, exitmock, inputmock, shellmock): component1 = "uuid1" component2 = "uuid2" changeentry1 = testhelper.createchangeentry(revision="anyRevId", component=component1) changeentry2 = testhelper.createchangeentry(revision="component2RevId", component=component2) changeentry3 = testhelper.createchangeentry(revision="anyOtherRevId", component=component1) changeentry3.setAccepted() changeentries = [changeentry1, changeentry2, changeentry3] self.configBuilder.setrepourl( "anyurl").setuseautomaticconflictresolution( "True").setmaxchangesetstoaccepttogether(10).setworkspace( "anyWs") config = self.configBuilder.build() configuration.config = config handler = ImportHandler() handler.retryacceptincludingnextchangesets(changeentry1, changeentries) inputmock.assert_called_once_with( 'Do you want to continue? Y for continue, any key for abort') exitmock.assert_called_once_with( "Please check the output/log and rerun program with resume")
def test_RetryAccept_AssertThatOnlyChangesFromSameComponentGetAcceptedTogether( self, inputmock, shellmock): component1 = "uuid1" component2 = "uuid2" changeentry1 = testhelper.createchangeentry(revision="anyRevId", component=component1) changeentry2 = testhelper.createchangeentry(revision="component2RevId", component=component2) changeentry3 = testhelper.createchangeentry(revision="anyOtherRevId", component=component1) changeentries = [changeentry1, changeentry2, changeentry3] shellmock.execute.return_value = 0 self.configBuilder.setrepourl( "anyurl").setuseautomaticconflictresolution( "True").setmaxchangesetstoaccepttogether(10).setworkspace( "anyWs") config = self.configBuilder.build() configuration.config = config handler = ImportHandler() handler.retryacceptincludingnextchangesets(changeentry1, changeentries) expectedshellcommand = 'lscm accept --verbose --overwrite-uncommitted --accept-missing-changesets --no-merge --repository-uri anyurl --target anyWs --changes anyRevId anyOtherRevId' shellmock.execute.assert_called_once_with( expectedshellcommand, handler.config.getlogpath("accept.txt"), "a")
def test_useragreeing_answeris_n_expectfalseandexception(self, inputmock): handler = ImportHandler(self.configBuilder.build()) try: handler.is_user_agreeing_to_accept_next_change( self.createChangeEntry()) self.fail("Should have exit the program") except SystemExit as e: self.assertEqual( "Please check the output/log and rerun program with resume", e.code)
def prepare(): config = configuration.get() rtc = ImportHandler() rtcworkspace = WorkspaceHandler() # git checkout branchpoint Commiter.checkout(config.previousstreamname + "_branchpoint") # list baselines of current workspace componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(config.previousstreamuuid) # set components to that baselines rtcworkspace.setcomponentstobaseline(componentbaselineentries, config.previousstreamuuid) rtcworkspace.load()
def test_collectChangeSetsToAcceptToAvoidMergeConflict_ShouldAcceptLargeAmountOfChangeSets( self): changeentries = [ testhelper.createchangeentry(str(i)) for i in range(1, 500) ] change1 = changeentries[0] configuration.config = self.configBuilder.build() collectedchanges = ImportHandler( ).collect_changes_to_accept_to_avoid_conflicts(change1, changeentries, 500) self.assertEqual(499, len(collectedchanges))
def test_collectChangeSetsToAcceptToAvoidMergeConflict_ShouldAdhereToMaxChangeSetCount( self): change1 = testhelper.createchangeentry("1") change2 = testhelper.createchangeentry("2") change3 = testhelper.createchangeentry("3") changeentries = [change1, change2, change3] configuration.config = self.configBuilder.build() collectedchanges = ImportHandler( ).collect_changes_to_accept_to_avoid_conflicts(change1, changeentries, 2) self.assertTrue(change1 in collectedchanges) self.assertTrue(change2 in collectedchanges) self.assertFalse(change3 in collectedchanges) self.assertEqual(2, len(collectedchanges))
def test_collectChangeSetsToAcceptToAvoidMergeConflict_ShouldCollectOnlyUnacceptedChangesets( self): change1 = testhelper.createchangeentry(revision="1") change2 = testhelper.createchangeentry(revision="2") change2.setAccepted() change3 = testhelper.createchangeentry(revision="3") changeentries = [change1, change2, change3] configuration.config = self.configBuilder.build() collectedchanges = ImportHandler( ).collect_changes_to_accept_to_avoid_conflicts(change1, changeentries, 10) self.assertTrue(change1 in collectedchanges) self.assertFalse(change2 in collectedchanges) self.assertTrue(change3 in collectedchanges) self.assertEqual(2, len(collectedchanges))
def test_RetryAccept_AssertThatTwoChangesGetAcceptedTogether( self, inputmock, shellmock): changeentry1 = self.createChangeEntry("anyRevId") changeentry2 = self.createChangeEntry("anyOtherRevId") changeentries = [changeentry1, changeentry2] shellmock.execute.return_value = 0 self.configBuilder.setrepourl( "anyurl").setuseautomaticconflictresolution("True").setworkspace( "anyWs") config = self.configBuilder.build() handler = ImportHandler(config) handler.retryacceptincludingnextchangesets(changeentry1, changeentries) expectedshellcommand = 'lscm accept -v -o -r anyurl -t anyWs --changes anyRevId anyOtherRevId' shellmock.execute.assert_called_once_with( expectedshellcommand, handler.config.getlogpath("accept.txt"), "a")
def test_getchangeentriesbytypeandvalue_type_stream(self, shellmock): anyurl = "anyUrl" config = self.configBuilder.setrepourl(anyurl).setworkspace( self.workspace).build() configuration.config = config stream = "myStreamUUID" comparetype = CompareType.stream comparetypename = comparetype.name filename = "Compare_%s_%s.txt" % (comparetypename, stream) outputfilename = config.getlogpath(filename) try: shellmock.encoding = 'UTF-8' ImportHandler().getchangeentriesbytypeandvalue(comparetype, stream) except FileNotFoundError: pass # do not bother creating the output file here expected_compare_command = "lscm --show-alias n --show-uuid y compare ws %s %s %s -r %s -I swc -C @@{name}@@{email}@@ --flow-directions i -D @@\"yyyy-MM-dd HH:mm:ss\"@@" \ % (self.workspace, comparetypename, stream, anyurl) shellmock.execute.assert_called_once_with(expected_compare_command, outputfilename)
def migrate(): config = configuration.read() rtc = ImportHandler(config) rtcworkspace = WorkspaceHandler(config) git = Commiter initialize(config) streamuuids = config.streamuuids for streamuuid in streamuuids: componentbaselineentries = rtc.getcomponentbaselineentriesfromstream( streamuuid) streamname = config.streamnames[streamuuids.index(streamuuid)] rtcworkspace.setnewflowtargets(streamuuid) git.branch(streamname) history = rtc.readhistory(componentbaselineentries, streamname) changeentries = rtc.getchangeentriesofstreamcomponents( componentbaselineentries) rtc.acceptchangesintoworkspace( rtc.getchangeentriestoaccept(changeentries, history)) shouter.shout("All changes of components of stream '%s' accepted" % streamname) git.pushbranch(streamname) rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid) rtcworkspace.load() changeentries = rtc.getchangeentriesofstream(streamuuid) rtc.acceptchangesintoworkspace( rtc.getchangeentriestoaccept(changeentries, history)) git.pushbranch(streamname) shouter.shout( "All changes of stream '%s' accepted - Migration of stream completed" % streamname) morestreamstomigrate = streamuuids.index(streamuuid) + 1 is not len( streamuuids) if morestreamstomigrate: git.checkout("master") rtcworkspace.recreateoldestworkspace()
def migrate(): rtc = ImportHandler() rtcworkspace = WorkspaceHandler() git = Commiter if existsrepo(): resume() else: initialize() config = configuration.get() streamuuid = config.streamuuid streamname = config.streamname branchname = streamname + "_branchpoint" componentbaselineentries = rtc.getcomponentbaselineentriesfromstream(streamuuid) rtcworkspace.setnewflowtargets(streamuuid) history = rtc.readhistory(componentbaselineentries, streamname) changeentries = rtc.getchangeentriesofstreamcomponents(componentbaselineentries) if len(changeentries) > 0: git.branch(branchname) rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history)) shouter.shout("All changes until creation of stream '%s' accepted" % streamname) git.pushbranch(branchname) rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid) rtcworkspace.load() git.branch(streamname) changeentries = rtc.getchangeentriesofstream(streamuuid) amountofacceptedchanges = rtc.acceptchangesintoworkspace(rtc.getchangeentriestoaccept(changeentries, history)) if amountofacceptedchanges > 0: git.pushbranch(streamname) git.promotebranchtomaster(streamname) RTCLogin.logout() summary(streamname)
def test_collectChangeSetsToAcceptToAvoidMergeConflict_ShouldCollectThreeChangesets( self): mychange1 = self.createChangeEntry("doSomethingOnOldRev") mychange2 = self.createChangeEntry("doSomethingElseOnOldRev") mymergechange = self.createChangeEntry("anyRev", comment="merge change") changefromsomeoneelse = self.createChangeEntry(author="anyOtherAuthor", revision="2", comment="anotherCommit") changeentries = [ mychange1, mychange2, mymergechange, changefromsomeoneelse ] handler = ImportHandler(self.configBuilder.build()) collectedchanges = handler.collect_changes_to_accept_to_avoid_conflicts( mychange1, changeentries) self.assertTrue(mychange1 in collectedchanges) self.assertTrue(mychange2 in collectedchanges) self.assertTrue(mymergechange in collectedchanges) self.assertFalse(changefromsomeoneelse in collectedchanges) self.assertEqual(3, len(collectedchanges))
def migrate(): config = configuration.read() rtc = ImportHandler(config) rtcworkspace = WorkspaceHandler(config) git = Commiter initialize(config) streamuuid = config.streamuuid streamname = config.streamname branchname = streamname + "_branchpoint" componentbaselineentries = rtc.getcomponentbaselineentriesfromstream( streamuuid) rtcworkspace.setnewflowtargets(streamuuid) git.branch(branchname) history = rtc.readhistory(componentbaselineentries, streamname) changeentries = rtc.getchangeentriesofstreamcomponents( componentbaselineentries) rtc.acceptchangesintoworkspace( rtc.getchangeentriestoaccept(changeentries, history)) shouter.shout("All changes until creation of stream '%s' accepted" % streamname) git.pushbranch(branchname) git.branch(streamname) rtcworkspace.setcomponentstobaseline(componentbaselineentries, streamuuid) rtcworkspace.load() changeentries = rtc.getchangeentriesofstream(streamuuid) rtc.acceptchangesintoworkspace( rtc.getchangeentriestoaccept(changeentries, history)) git.pushbranch(streamname) shouter.shout( "All changes of stream '%s' accepted - Migration of stream completed" % streamname)
def test_useragreeing_answeris_y_expecttrue(self, inputmock): handler = ImportHandler(self.configBuilder.build()) self.assertTrue( handler.is_user_agreeing_to_accept_next_change( self.createChangeEntry()))
def test_useragreeing_answeris_y_expecttrue(self, inputmock): configuration.config = self.configBuilder.build() self.assertTrue(ImportHandler().is_user_agreeing_to_accept_next_change( testhelper.createchangeentry()))