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())
def test_getting_local_commit_hash_no_git(self): """ If git is not available, local_head_commit_hash attribute should equal None. """ 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") BleedingEdgeUpdater.is_repo().AndReturn(True) BleedingEdgeUpdater.has_git().AndReturn(False) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertEqual(None, updater.local_head_commit_hash)
def test_getting_local_commit_hash(self): """ If project root is a git repo, and git is avaialable, tha local_head_commit_hash attribute should contain the SHA of HEAD after having initialized BleedingEdgeUpdater. """ 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") BleedingEdgeUpdater.is_repo().AndReturn(True) BleedingEdgeUpdater.has_git().AndReturn(True) git.LocalRepository.getHead().AndReturn(mock_commit) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertEquals(self.__mock_local_head_hash, updater.local_head_commit_hash)
def test_has_git_when_has_git(self): """ has_git should return True if the git library indicates git v1 as being available. """ self.mox.StubOutWithMock(git.LocalRepository, "getGitVersion") # This first call is __init__ retrieving HEAD commit hash git.LocalRepository.getGitVersion().AndReturn("1.7.5.4") git.LocalRepository.getGitVersion().AndReturn("1.7.5.4") self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertTrue(updater.has_git())
def test_has_git_when_is_not_repo(self): """ If project root is not a repo, has_git should return False, rather than raising an exception, as it requires a local repository in order to query git for version(?!). """ self.mox.StubOutWithMock(BleedingEdgeUpdater, "is_repo") self.mox.StubOutWithMock(git.LocalRepository, "getGitVersion") BleedingEdgeUpdater.is_repo().AndReturn(False) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertTrue(not updater.has_git())
def test_has_git_when_does_not_have_git(self): """ has_git should return False if the git library is unable to locate git v1. """ self.mox.StubOutWithMock(git.LocalRepository, "getGitVersion") # This first call is __init__ retrieving HEAD commit hash git.LocalRepository.getGitVersion().AndReturn("1.7.5.4") git.LocalRepository.getGitVersion().AndRaise( git.exceptions.GitException("dang nabit")) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertTrue(not updater.has_git())