Exemplo n.º 1
0
    def test_log_from_date(self):
        """Test if commits are returned from the given date"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log(from_date=datetime.datetime(2014, 2, 11, 22, 7, 49))
        gitlog = [line for line in gitlog]

        self.assertEqual(len(gitlog), 36)
        self.assertEqual(gitlog[0][:14], "commit ce8e0b8")

        # Use a timezone, it will return an empty line
        from_date = datetime.datetime(2014,
                                      2,
                                      11,
                                      22,
                                      7,
                                      49,
                                      tzinfo=dateutil.tz.tzoffset(
                                          None, -36000))
        gitlog = repo.log(from_date=from_date)
        gitlog = [line for line in gitlog]

        self.assertEqual(gitlog, [])

        shutil.rmtree(new_path)
Exemplo n.º 2
0
    def test_clone_existing_directory(self):
        """Test if it raises an exception when tries to clone an existing directory"""

        expected = "git command - fatal: destination path '%s' already exists" % (self.tmp_path)

        with self.assertRaisesRegex(RepositoryError, expected):
            _ = GitRepository.clone(self.git_path, self.tmp_path)
Exemplo n.º 3
0
    def test_clone_existing_directory(self):
        """Test if it raises an exception when tries to clone an existing directory"""

        expected = "git command - fatal: destination path '%s' already exists" \
            % (self.tmp_path)

        with self.assertRaisesRegex(RepositoryError, expected):
            _ = GitRepository.clone(self.git_path, self.tmp_path)
Exemplo n.º 4
0
    def test_pull(self):
        """Test if the repository is updated to 'origin' status"""
        def count_commits():
            """Get the number of commits counting the entries on the log"""

            cmd = ['git', 'log', '--oneline']
            gitlog = subprocess.check_output(cmd,
                                             stderr=subprocess.STDOUT,
                                             cwd=new_path,
                                             env={
                                                 'LANG': 'C',
                                                 'PAGER': ''
                                             })
            commits = gitlog.strip(b'\n').split(b'\n')
            return len(commits)

        new_path = os.path.join(self.tmp_path, 'newgit')
        new_file = os.path.join(new_path, 'newfile')

        repo = GitRepository.clone(self.git_path, new_path)

        # Count the number of commits before adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        # Create a new file and commit it to the repository
        with open(new_file, 'w') as f:
            f.write("Testing pull method")

        cmd = ['git', 'add', new_file]
        subprocess.check_output(cmd,
                                stderr=subprocess.STDOUT,
                                cwd=new_path,
                                env={'LANG': 'C'})

        cmd = [
            'git', '-c', 'user.name="mock"', '-c',
            'user.email="*****@*****.**"', 'commit', '-m', 'Testing pull'
        ]
        subprocess.check_output(cmd,
                                stderr=subprocess.STDOUT,
                                cwd=new_path,
                                env={'LANG': 'C'})

        # Count the number of commits after the adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 10)

        # Update the repository to its original status
        repo.pull()

        # The number of commits should be updated to its original value
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        shutil.rmtree(new_path)
Exemplo n.º 5
0
    def test_clone_error(self):
        """Test if it raises an exception when an error occurs cloning a repository"""

        # Clone a non-git repository
        new_path = os.path.join(self.tmp_path, "newgit")

        expected = "git command - fatal: repository '%s' does not exist" % self.tmp_path

        with self.assertRaisesRegex(RepositoryError, expected):
            _ = GitRepository.clone(self.tmp_path, new_path)
Exemplo n.º 6
0
    def test_clone_error(self):
        """Test if it raises an exception when an error occurs cloning a repository"""

        # Clone a non-git repository
        new_path = os.path.join(self.tmp_path, 'newgit')

        expected = "git command - fatal: repository '%s' does not exist" \
            % self.tmp_path

        with self.assertRaisesRegex(RepositoryError, expected):
            _ = GitRepository.clone(self.tmp_path, new_path)
Exemplo n.º 7
0
    def test_log_empty(self):
        """Test if no line is returned when the log is empty"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log(from_date=datetime.datetime(2020, 1, 1, 1, 1, 1))
        gitlog = [line for line in gitlog]

        self.assertListEqual(gitlog, [])

        shutil.rmtree(new_path)
Exemplo n.º 8
0
    def test_log(self):
        """Test log command"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log()
        gitlog = [line for line in gitlog]
        self.assertEqual(len(gitlog), 108)
        self.assertEqual(gitlog[0][:14], "commit bc57a92")

        shutil.rmtree(new_path)
Exemplo n.º 9
0
    def test_log_empty(self):
        """Test if no line is returned when the log is empty"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log(from_date=datetime.datetime(2020, 1, 1, 1, 1, 1))
        gitlog = [line for line in gitlog]

        self.assertListEqual(gitlog, [])

        shutil.rmtree(new_path)
Exemplo n.º 10
0
    def test_log(self):
        """Test log command"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log()
        gitlog = [line for line in gitlog]
        self.assertEqual(len(gitlog), 108)
        self.assertEqual(gitlog[0][:14], "commit bc57a92")

        shutil.rmtree(new_path)
Exemplo n.º 11
0
    def test_clone(self):
        """Test if a git repository is cloned"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)

        self.assertIsInstance(repo, GitRepository)
        self.assertEqual(repo.uri, self.git_path)
        self.assertEqual(repo.dirpath, new_path)
        self.assertTrue(os.path.exists(new_path))
        self.assertTrue(os.path.exists(os.path.join(new_path, '.git')))

        shutil.rmtree(new_path)
Exemplo n.º 12
0
    def test_clone(self):
        """Test if a git repository is cloned"""

        new_path = os.path.join(self.tmp_path, 'newgit')

        repo = GitRepository.clone(self.git_path, new_path)

        self.assertIsInstance(repo, GitRepository)
        self.assertEqual(repo.uri, self.git_path)
        self.assertEqual(repo.dirpath, new_path)
        self.assertTrue(os.path.exists(new_path))
        self.assertTrue(os.path.exists(os.path.join(new_path, '.git')))

        shutil.rmtree(new_path)
Exemplo n.º 13
0
    def test_pull(self):
        """Test if the repository is updated to 'origin' status"""

        def count_commits():
            """Get the number of commits counting the entries on the log"""

            cmd = ['git', 'log', '--oneline']
            gitlog = subprocess.check_output(cmd, stderr=subprocess.STDOUT,
                                             cwd=new_path,
                                             env={'LANG' : 'C', 'PAGER' : ''})
            commits = gitlog.strip(b'\n').split(b'\n')
            return len(commits)

        new_path = os.path.join(self.tmp_path, 'newgit')
        new_file = os.path.join(new_path, 'newfile')

        repo = GitRepository.clone(self.git_path, new_path)

        # Count the number of commits before adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        # Create a new file and commit it to the repository
        with open(new_file, 'w') as f:
            f.write("Testing pull method")

        cmd = ['git', 'add', new_file]
        subprocess.check_output(cmd, stderr=subprocess.STDOUT,
                                cwd=new_path, env={'LANG' : 'C'})

        cmd = ['git', '-c', 'user.name="mock"',
               '-c', 'user.email="*****@*****.**"',
               'commit', '-m', 'Testing pull']
        subprocess.check_output(cmd, stderr=subprocess.STDOUT,
                                cwd=new_path, env={'LANG' : 'C'})

        # Count the number of commits after the adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 10)

        # Update the repository to its original status
        repo.pull()

        # The number of commits should be updated to its original value
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        shutil.rmtree(new_path)
Exemplo n.º 14
0
    def test_pull(self):
        """Test if the repository is updated to 'origin' status"""

        def count_commits():
            """Get the number of commits counting the entries on the log"""

            cmd = ["git", "log", "--oneline"]
            gitlog = subprocess.check_output(
                cmd, stderr=subprocess.STDOUT, cwd=new_path, env={"LANG": "C", "PAGER": ""}
            )
            commits = gitlog.strip(b"\n").split(b"\n")
            return len(commits)

        new_path = os.path.join(self.tmp_path, "newgit")
        new_file = os.path.join(new_path, "newfile")

        repo = GitRepository.clone(self.git_path, new_path)

        # Count the number of commits before adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        # Create a new file and commit it to the repository
        with open(new_file, "w") as f:
            f.write("Testing pull method")

        cmd = ["git", "add", new_file]
        subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=new_path, env={"LANG": "C"})

        cmd = ["git", "-c", 'user.name="mock"', "-c", 'user.email="*****@*****.**"', "commit", "-m", "Testing pull"]
        subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=new_path, env={"LANG": "C"})

        # Count the number of commits after the adding a new one
        ncommits = count_commits()
        self.assertEqual(ncommits, 10)

        # Update the repository to its original status
        repo.pull()

        # The number of commits should be updated to its original value
        ncommits = count_commits()
        self.assertEqual(ncommits, 9)

        shutil.rmtree(new_path)
Exemplo n.º 15
0
    def test_log_from_date(self):
        """Test if commits are returned from the given date"""

        new_path = os.path.join(self.tmp_path, "newgit")

        repo = GitRepository.clone(self.git_path, new_path)
        gitlog = repo.log(from_date=datetime.datetime(2014, 2, 11, 22, 7, 49))
        gitlog = [line for line in gitlog]

        self.assertEqual(len(gitlog), 36)
        self.assertEqual(gitlog[0][:14], "commit ce8e0b8")

        # Use a timezone, it will return an empty line
        from_date = datetime.datetime(2014, 2, 11, 22, 7, 49, tzinfo=dateutil.tz.tzoffset(None, -36000))
        gitlog = repo.log(from_date=from_date)
        gitlog = [line for line in gitlog]

        self.assertEqual(gitlog, [])

        shutil.rmtree(new_path)