def test_getnextchangeset_fromsamecomponent_expectnonefound(self): component1 = "uuid_1" component2 = "uuid_2" # entries for component 1 entry1_1 = testhelper.createchangeentry(revision="1.1", component=component1) entry1_1.setAccepted() entry1_2 = testhelper.createchangeentry(revision="1.2", component=component1) entry1_2.setAccepted() # entries for component 2 (2nd entry being already accepted) entry2_1 = testhelper.createchangeentry(revision="2.1", component=component2) entry2_1.setAccepted() entry2_2 = testhelper.createchangeentry(revision="2.2", component=component2) entry2_2.setAccepted() changeentries = [] changeentries.append(entry1_1) changeentries.append(entry2_1) changeentries.append(entry1_2) changeentries.append(entry2_2) nextentry = ImportHandler.getnextchangeset_fromsamecomponent( currentchangeentry=entry2_1, changeentries=changeentries) self.assertIsNone(nextentry)
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_Accept_AssertThatChangeEntriesGetAccepted(self): with patch.object(shell, 'execute', return_value=0) as shell_mock: revision1 = "anyRevision" revision2 = "anyOtherRevision" anyurl = "anyUrl" config = self.configBuilder.setrepourl(anyurl).setworkspace( self.workspace).build() configuration.config = config changeentry1 = testhelper.createchangeentry(revision1) changeentry2 = testhelper.createchangeentry(revision2) Changes.accept(self.apath, changeentry1, changeentry2) self.assertTrue(changeentry1.isAccepted()) self.assertTrue(changeentry1.isAccepted())
def test_Discard_AssertThatCorrectParamaterGetPassedToShell( self, shell_mock): revision1 = "anyRevision" revision2 = "anyOtherRevision" anyurl = "anyUrl" config = self.configBuilder.setrepourl(anyurl).setworkspace( self.workspace).build() configuration.config = config Changes.discard(testhelper.createchangeentry(revision1), testhelper.createchangeentry(revision2)) expected_discard_command = "lscm discard -w %s -r %s -o %s %s" % ( self.workspace, anyurl, revision1, revision2) shell_mock.execute.assert_called_once_with(expected_discard_command)
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_ChangeEntry_flip_accepted(self): change = testhelper.createchangeentry() self.assertEqual(False, change.accepted) change.setAccepted() self.assertEqual(True, change.accepted) change.setUnaccepted() self.assertEqual(False, change.accepted)
def test_IllegalGitCharsShouldntCreateFile_SpecialCaseAlreadyQuoted(self): with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): Commiter.addandcommit( testhelper.createchangeentry(comment="Check out \"" + ">" + "\"US3333\"")) self.assertEqual(0, len(shell.getoutput("git status -z")), "No file should be created by commit message")
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_Accept_AssertThatCorrectParamaterGetPassedToShell( self, shell_mock): revision1 = "anyRevision" revision2 = "anyOtherRevision" anyurl = "anyUrl" config = self.configBuilder.setrepourl(anyurl).setworkspace( self.workspace).build() configuration.config = config Changes.accept(self.apath, testhelper.createchangeentry(revision1), testhelper.createchangeentry(revision2)) commandtemplate = u"lscm accept --verbose --overwrite-uncommitted --accept-missing-changesets --no-merge --repository-uri {0:s} --target {1:s} --changes {2:s} {3:s}" expected_accept_command = commandtemplate.format( anyurl, self.workspace, revision1, revision2) appendlogfileshortcut = "a" shell_mock.execute.assert_called_once_with(expected_accept_command, self.apath, appendlogfileshortcut) self.assertEqual(expected_accept_command, Changes.latest_accept_command)
def test_useragreeing_answeris_n_expectfalseandexception(self, inputmock): configuration.config = self.configBuilder.build() try: ImportHandler().is_user_agreeing_to_accept_next_change( testhelper.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 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_getnextchangeset_fromsamecomponent_expectsamecomponent(self): component1 = "uuid_1" component2 = "uuid_2" # entries for component 1 (2nd entry being already accepted) entry1_1 = testhelper.createchangeentry(revision="1.1", component=component1) entry1_2 = testhelper.createchangeentry(revision="1.2", component=component1) entry1_2.setAccepted() entry1_3 = testhelper.createchangeentry(revision="1.3", component=component1) # entries for component 2 (2nd entry being already accepted) entry2_1 = testhelper.createchangeentry(revision="2.1", component=component2) entry2_2 = testhelper.createchangeentry(revision="2.2", component=component2) entry2_2.setAccepted() entry2_3 = testhelper.createchangeentry(revision="2.3", component=component2) changeentries = [] changeentries.append(entry1_1) changeentries.append(entry2_1) changeentries.append(entry1_2) changeentries.append(entry2_2) changeentries.append(entry1_3) changeentries.append(entry2_3) nextentry = ImportHandler.getnextchangeset_fromsamecomponent( currentchangeentry=entry2_1, changeentries=changeentries) self.assertIsNotNone(nextentry) self.assertFalse(nextentry.isAccepted()) self.assertEqual(component2, nextentry.component) self.assertEqual("2.3", nextentry.revision)
def test_handleignore_local_jazzignore_expect_delete_gitignore(self): with testhelper.mkchdir("aFolder") as folder: # create a repository with a .jazzignore and .gitignore file configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() Initializer().createrepo() subfolder = "aSubFolder" os.mkdir(subfolder) jazzignore = subfolder + os.sep + ".jazzignore" with open(jazzignore, 'w') as testjazzignore: testjazzignore.write("# my ignores\n") testjazzignore.write("core.ignore = {*.pyc}") Commiter.addandcommit(testhelper.createchangeentry(comment="Initial .jazzignore")) gitignore = subfolder + os.sep + ".gitignore" self.assertTrue(os.path.exists(gitignore)) # now remove .jazzignore os.remove(jazzignore) Commiter.handleignore() self.assertFalse(os.path.exists(gitignore))
def test_IllegalGitCharsShouldntCreateFile_SpecialCaseAlreadyQuoted(self): with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): Commiter.addandcommit(testhelper.createchangeentry(comment="Check out \"" + ">" + "\"US3333\"")) self.assertEqual(0, len(shell.getoutput("git status -z")), "No file should be created by commit message")
def test_IllegalGitCharsShouldntCreateFile_NoCommentCase(self): with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): Commiter.addandcommit(testhelper.createchangeentry(comment="<No Comment>")) self.assertEqual(0, len(shell.getoutput("git status -z")), "No file should be created by commit message")
def test_ChangeEntry_tostring(self): change = testhelper.createchangeentry(revision="anyRev", component="anyCmp") self.assertEqual( "anyComment (Date: 2015-01-22, Author: anyAuthor, Revision: anyRev, Component: anyCmp, Accepted: False)", change.tostring())
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()))