def METHOD_NAME(self):
    root_directory = Path(mkdtemp())
    docroot_path = root_directory
    file_a = root_directory / "test.txt"
    file_a.touch()
    symlink_a = root_directory / "symlink.txt"
    symlink_a.symlink_to(file_a)
    # Symlinks aren't allowed.
    with pytest.raises(UnsupportedSymlinkFileError):
        with override_settings(DOCROOT=docroot_path):
            safe_open(symlink_a, allow_symlinks=False)
    # Symlinks are allowed if they are under the root_directory.
    with override_settings(DOCROOT=docroot_path):
        context_manager = safe_open(
            symlink_a, allow_symlinks=True, base_path=root_directory
        )
        self.assertIsNotNone(context_manager)
    # Symlinks aren't allowed if they aren't under the root_directory.
    with pytest.raises(SymlinkOutsideBasePath):
        with override_settings(DOCROOT=docroot_path):
            new_root_directory = root_directory / "dir"
            new_root_directory.mkdir()
            safe_open(symlink_a, allow_symlinks=True, base_path=new_root_directory)