Exemplo n.º 1
0
class TestRepository(unittest.TestCase):
    """Repository object test suite."""

    def setUp(self):
        """Setup sandbox."""
        self.sandbox = Sandbox()

    def tearDown(self):
        """Destroy sandbox."""
        self.sandbox.destroy()

    def test_path_not_exists(self):
        """Test repository path when doesn't exists."""
        self.assertRaises(
            RepositoryPathInvalid, Repository, "/dir/doesnt/exists")

    def test_repository_not_valid_path_isfile(self):
        """Test repository is not valid because path is file."""
        self.sandbox.touch("invalid_repo")

        self.assertRaises(
            RepositoryPathInvalid, Repository,
            os.path.join(self.sandbox.path, "invalid_repo"))

    def test_repository_not_valid_path_isdir(self):
        """
        Test repository is not valid when path is directory,
        but adapter not found.
        """
        self.sandbox.mkdir("invalid_repo")
        self.assertRaises(
            RepositoryAdapterNotFound, Repository,
            os.path.join(self.sandbox.path, "invalid_repo"))

    def test_repository_valid_scm_git(self):
        """Test repository is valid and is a git repository."""
        self.sandbox.mkdir("git_repo")
        self.sandbox.mkdir("git_repo/.git")

        repo = Repository("%s/git_repo" % self.sandbox.path)
        self.assertIsInstance(repo.adapter, GitAdapter)

    def test_get_scm(self):
        """Test get scm for a repository."""
        self.sandbox.mkdir("git_repo")
        self.sandbox.mkdir("git_repo/.git")

        repo = Repository("%s/git_repo" % self.sandbox.path)
        self.assertEqual("Git", repo.get_scm())

    def test_get_scm_none(self):
        """Test get scm for a repository when adapter is None."""
        self.sandbox.mkdir("git_repo")
        self.sandbox.mkdir("git_repo/.git")

        repo = Repository("%s/git_repo" % self.sandbox.path)
        repo.adapter = None
        self.assertEqual(None, repo.get_scm())