def test_upgradeWorker_bad_basedir(self): """ test calling upgradeWorker() with bad base directory """ # override isBuildworkerDir() to always fail self.setupUpIsBuildworkerDir(False) # call upgradeWorker() and check that correct exit code is returned self.assertEqual(upgrade_worker.upgradeWorker(self.config), 1, "unexpected exit code") # check that isBuildworkerDir was called with correct argument self.isBuildworkerDir.assert_called_once_with("dummy")
def test_upgradeWorker_updated(self): """ test calling upgradeWorker() on an older buildbot.tac, that need to be updated """ # patch basedir check to always succeed self.setupUpIsBuildworkerDir(True) # patch open() to return older buildbot.tac file self.setUpOpen(OLD_BUILDBOT_TAC) # call upgradeWorker() and check the success exit code is returned self.assertEqual(upgrade_worker.upgradeWorker(self.config), 0, "unexpected exit code") # check message to the log self.assertLogged("buildbot.tac updated") # check calls to open() self.open.assert_has_calls([mock.call(self.buildbot_tac), mock.call(self.buildbot_tac, "w")]) # check that we wrote correct updated buildbot.tac file self.fileobj.write.assert_called_once_with(MODERN_BUILDBOT_TAC)
def test_upgradeWorker_no_changes(self): """ test calling upgradeWorker() on a buildbot.tac that don't need to be upgraded """ # patch basedir check to always succeed self.setupUpIsBuildworkerDir(True) # patch open() to return a modern buildbot.tac file self.setUpOpen(MODERN_BUILDBOT_TAC) # call upgradeWorker() and check the success exit code is returned self.assertEqual(upgrade_worker.upgradeWorker(self.config), 0, "unexpected exit code") # check message to the log self.assertLogged("No changes made") # check that open() was called with correct path self.open.assert_called_once_with(self.buildbot_tac) # check that no writes where made self.assertFalse(self.fileobj.write.called, "unexpected write to buildbot.tac file")