Exemple #1
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)
Exemple #2
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)
Exemple #3
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)