def test_decrypt_diff(self):

        # Monkey-patch
        _get_old_contents = git_diff.get_old_contents

        def get_old_contents(*args):  # noqa
            return OLD_FILE_1
        git_diff.get_old_contents = get_old_contents
        _get_new_contents = git_diff.get_new_contents

        def get_new_contents(*args):  # noqa
            return NEW_FILE_1
        git_diff.get_new_contents = get_new_contents

        # Test decryption
        try:

            # ... create temporary vault file
            f = tempfile.NamedTemporaryFile()
            f.write(VAULT_PASSWORD)
            f.seek(0)

            # ... decrypt the diff
            parts = git_diff.get_parts(SAMPLE_DIFF)
            old, new = git_diff.decrypt_diff(
                parts[0], password_file=f.name)
            self.assertEqual(old, OLD_FILE_1_DECRYPTED)
            self.assertEqual(new, NEW_FILE_1_DECRYPTED)

        # Restore monkey-patched functions
        finally:
            git_diff.get_old_contents = _get_old_contents
            git_diff.get_new_contents = _get_new_contents
 def test_get_old_filename(self):
     parts = git_diff.get_parts(SAMPLE_DIFF)
     old_filename = git_diff.get_old_filename(parts[0])
     self.assertEqual(old_filename, 'group_vars/foo')
 def test_get_old_sha(self):
     parts = git_diff.get_parts(SAMPLE_DIFF)
     old_sha = git_diff.get_old_sha(parts[0])
     self.assertEqual(old_sha, 'c09080b')
 def test_get_parts(self):
     parts = git_diff.get_parts(SAMPLE_DIFF)
     self.assertEqual(len(parts), 2)
 def test_get_head(self):
     parts = git_diff.get_parts(SAMPLE_DIFF)
     head = git_diff.get_head(parts[0])
     self.assertEqual(head, DIFF_HEAD_1)
 def test_get_new_filename_for_deleted_file(self):
     parts = git_diff.get_parts(DELETED_FILE_DIFF)
     new_filename = git_diff.get_new_filename(parts[0])
     self.assertEqual(new_filename, '/dev/null')
 def test_get_old_filename_for_added_file(self):
     parts = git_diff.get_parts(ADDED_FILE_DIFF)
     old_filename = git_diff.get_old_filename(parts[0])
     self.assertEqual(old_filename, '/dev/null')