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_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_getting_local_commit_hash_no_repo(self): """ If project root is not a repo, 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(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_is_repo_when_is_repo(self): """ If project root contains a .git directory, make sure that is_repo indicates that. """ self.mox.StubOutWithMock(os.path, "isdir") # This first call is __init__ checking is_repo in order to create a # LocalRepository attribute. os.path.isdir(os.path.join(self.__project_root, ".git")).AndReturn(True) os.path.isdir(os.path.join(self.__project_root, ".git")).AndReturn(True) self.mox.ReplayAll() updater = BleedingEdgeUpdater(self.__repo, self.__remote_url) self.assertTrue(updater.is_repo())