Пример #1
0
    def test_initialize_no_repo(self):
        # Test that panther does not run when there is no current git
        # repository when calling initialize
        repo_directory = self.useFixture(fixtures.TempDir()).path
        os.chdir(repo_directory)

        return_value = baseline.initialize()

        # assert panther did not run due to no git repo
        self.assertEqual((None, None, None, None, None), return_value)
Пример #2
0
    def test_initialize_with_output_argument(self):
        # Test that panther does not run when the '-o' (output) argument is
        # specified
        repo_directory = self.useFixture(fixtures.TempDir()).path
        git_repo = git.Repo.init(repo_directory)
        git_repo.index.commit('Initial Commit')
        os.chdir(repo_directory)

        return_value = baseline.initialize()

        # assert panther did not run due to provided -o (--ouput) argument
        self.assertEqual((None, None, None, None, None), return_value)
Пример #3
0
    def test_initialize_existing_temp_file(self):
        # Test that panther does not run when the temporary output file exists
        # when calling the initialize method
        repo_directory = self.useFixture(fixtures.TempDir()).path
        git_repo = git.Repo.init(repo_directory)
        git_repo.index.commit('Initial Commit')
        os.chdir(repo_directory)

        # create an existing version of temporary output file
        existing_temp_file = baseline.baseline_tmp_file
        with open(existing_temp_file, 'wt') as fd:
            fd.write(self.temp_file_contents)

        return_value = baseline.initialize()

        # assert panther did not run due to existing temporary report file
        self.assertEqual((None, None, None, None, None), return_value)
Пример #4
0
    def test_initialize_dirty_repo(self):
        # Test that panther does not run when the current git repository is
        # 'dirty' when calling the initialize method
        repo_directory = self.useFixture(fixtures.TempDir()).path
        git_repo = git.Repo.init(repo_directory)
        git_repo.index.commit('Initial Commit')
        os.chdir(repo_directory)

        # make the git repo 'dirty'
        with open('dirty_file.py', 'wt') as fd:
            fd.write(self.temp_file_contents)
        git_repo.index.add(['dirty_file.py'])

        return_value = baseline.initialize()

        # assert panther did not run due to dirty repo
        self.assertEqual((None, None, None, None, None), return_value)
Пример #5
0
    def test_initialize_existing_report_file(self):
        # Test that panther does not run when the output file exists (and the
        # provided output format does not match the default format) when
        # calling the initialize method
        repo_directory = self.useFixture(fixtures.TempDir()).path
        git_repo = git.Repo.init(repo_directory)
        git_repo.index.commit('Initial Commit')
        os.chdir(repo_directory)

        # create an existing version of output report file
        existing_report = "{}.{}".format(baseline.report_basename, 'txt')
        with open(existing_report, 'wt') as fd:
            fd.write(self.temp_file_contents)

        return_value = baseline.initialize()

        # assert panther did not run due to existing report file
        self.assertEqual((None, None, None, None, None), return_value)
Пример #6
0
    def test_initialize_git_command_failure(self):
        # Test that panther does not run when the Git command fails
        repo_directory = self.useFixture(fixtures.TempDir()).path
        git_repo = git.Repo.init(repo_directory)
        git_repo.index.commit('Initial Commit')
        os.chdir(repo_directory)

        additional_content = 'additional_file.py'
        with open(additional_content, 'wt') as fd:
            fd.write(self.temp_file_contents)
        git_repo.index.add([additional_content])
        git_repo.index.commit('Additional Content')

        with mock.patch('git.Repo') as mock_git_repo:
            mock_git_repo.side_effect = git.exc.GitCommandNotFound('clone', '')

            return_value = baseline.initialize()

            # assert panther did not run due to git command failure
            self.assertEqual((None, None, None, None, None), return_value)