def test_github_does_not_have_new_version(self): """ If the github query returns a SHA key that is equal to the local master HEAD key, check shall indicate that there is no new version available. """ mock_commit = self.mox.CreateMockAnything() mock_commit.hash = self.__mock_local_head_hash self.mox.StubOutWithMock(git.LocalRepository, "getHead") self.mox.StubOutWithMock(BleedingEdgeUpdater, "is_repo") self.mox.StubOutWithMock(BleedingEdgeUpdater, "has_git") self.mox.StubOutWithMock(BleedingEdgeUpdater, "get_origin_head_sha") BleedingEdgeUpdater.is_repo().AndReturn(True) BleedingEdgeUpdater.has_git().AndReturn(True) git.LocalRepository.getHead().AndReturn(mock_commit) BleedingEdgeUpdater.get_origin_head_sha().AndReturn( self.__mock_local_head_hash) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertTrue(not updater.check())
class UpdateNotifyer(object): """ UpdateNotifyer is responsible for querying the selected updater at the desired interval, and if an update is found, the bot status is updated to reflect this. """ def __init__(self, repo, api_url, bleeding_edge = False, interval = 3600): self.has_update = False self.__timer = None if not bleeding_edge: self.__updater = StableUpdater(repo, api_url) else: self.__updater = BleedingEdgeUpdater(repo, api_url) self.__interval = interval def start(self): """ Start the UpdateNotifyer service. """ self.__timer = threading.Timer(self.__interval, self.timeout) self.__timer.start() def stop(self): """ Stop the UpdateNotifyer service. """ self.__timer.cancel() def timeout(self): """ Called upon by the Timer when self.__interval has elapsed. """ had_update = self.has_update self.has_update = self.__updater.check() if self.has_update and not had_update: cli = Client() new_version = self.__updater.get_update_version() if new_version: cli.change_status(u"update available: %s" % new_version[:7]) self.start()