mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
parent
250a481f31
commit
9ca27fd6fe
3 changed files with 86 additions and 2 deletions
|
@ -562,7 +562,9 @@ class DocSelectionWidget(QtWidgets.QWidget):
|
||||||
self.file_dialog.setDirectory(first_doc_dir)
|
self.file_dialog.setDirectory(first_doc_dir)
|
||||||
|
|
||||||
if self.file_dialog.exec():
|
if self.file_dialog.exec():
|
||||||
documents = [Document(filename) for filename in self.file_dialog.selectedFiles()]
|
documents = [
|
||||||
|
Document(filename) for filename in self.file_dialog.selectedFiles()
|
||||||
|
]
|
||||||
self.documents_selected.emit(documents)
|
self.documents_selected.emit(documents)
|
||||||
else:
|
else:
|
||||||
# No files selected
|
# No files selected
|
||||||
|
|
|
@ -9,6 +9,7 @@ from dangerzone.document import SAFE_EXTENSION
|
||||||
|
|
||||||
SAMPLE_DIRECTORY = "test_docs"
|
SAMPLE_DIRECTORY = "test_docs"
|
||||||
BASIC_SAMPLE = "sample-pdf.pdf"
|
BASIC_SAMPLE = "sample-pdf.pdf"
|
||||||
|
BASIC_SAMPLE2 = "sample-doc.doc"
|
||||||
test_docs_dir = Path(__file__).parent.joinpath(SAMPLE_DIRECTORY)
|
test_docs_dir = Path(__file__).parent.joinpath(SAMPLE_DIRECTORY)
|
||||||
test_docs = [
|
test_docs = [
|
||||||
p
|
p
|
||||||
|
@ -30,6 +31,11 @@ def sample_doc() -> str:
|
||||||
return str(test_docs_dir.joinpath(BASIC_SAMPLE))
|
return str(test_docs_dir.joinpath(BASIC_SAMPLE))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_doc2() -> str:
|
||||||
|
return str(test_docs_dir.joinpath(BASIC_SAMPLE2))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def unreadable_pdf(tmp_path: Path) -> str:
|
def unreadable_pdf(tmp_path: Path) -> str:
|
||||||
file_path = tmp_path / "document.pdf"
|
file_path = tmp_path / "document.pdf"
|
||||||
|
|
|
@ -1,15 +1,42 @@
|
||||||
from pytest import MonkeyPatch
|
from pytest import MonkeyPatch, fixture
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from pytestqt.qtbot import QtBot
|
from pytestqt.qtbot import QtBot
|
||||||
|
|
||||||
from dangerzone.gui import MainWindow
|
from dangerzone.gui import MainWindow
|
||||||
from dangerzone.gui import updater as updater_mod
|
from dangerzone.gui import updater as updater_mod
|
||||||
|
from dangerzone.gui.main_window import *
|
||||||
from dangerzone.gui.updater import UpdateReport, UpdaterThread
|
from dangerzone.gui.updater import UpdateReport, UpdaterThread
|
||||||
from dangerzone.util import get_version
|
from dangerzone.util import get_version
|
||||||
|
|
||||||
|
from .. import sample_doc, sample_doc2
|
||||||
from . import qt_updater, updater
|
from . import qt_updater, updater
|
||||||
from .test_updater import default_updater_settings
|
from .test_updater import default_updater_settings
|
||||||
|
|
||||||
|
# FIXME: See https://github.com/freedomofpress/dangerzone/issues/320 for more details.
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from PySide2 import QtCore
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
from PySide6 import QtCore, QtGui, QtWidgets
|
||||||
|
except ImportError:
|
||||||
|
from PySide2 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## Widget Fixtures
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
@fixture
|
||||||
|
def content_widget(qtbot: QtBot, mocker: MockerFixture) -> QtWidgets.QWidget:
|
||||||
|
# Setup
|
||||||
|
mock_app = mocker.MagicMock()
|
||||||
|
dummy = mocker.MagicMock()
|
||||||
|
dz = DangerzoneGui(mock_app, dummy)
|
||||||
|
w = ContentWidget(dz)
|
||||||
|
qtbot.addWidget(w)
|
||||||
|
return w
|
||||||
|
|
||||||
|
|
||||||
def test_qt(
|
def test_qt(
|
||||||
qtbot: QtBot,
|
qtbot: QtBot,
|
||||||
|
@ -68,3 +95,52 @@ def test_qt(
|
||||||
# update check.
|
# update check.
|
||||||
# 5. Check that latest version/changelog, as well as update errors, are cached in
|
# 5. Check that latest version/changelog, as well as update errors, are cached in
|
||||||
# the settings
|
# the settings
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## Document Selection tests
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
def test_change_document_button(
|
||||||
|
content_widget: ContentWidget,
|
||||||
|
qtbot: QtBot,
|
||||||
|
mocker: MockerFixture,
|
||||||
|
sample_doc: str,
|
||||||
|
sample_doc2: str,
|
||||||
|
) -> None:
|
||||||
|
# Setup first doc selection
|
||||||
|
file_dialog_mock = mocker.MagicMock()
|
||||||
|
file_dialog_mock.selectedFiles.return_value = (sample_doc,)
|
||||||
|
content_widget.doc_selection_widget.file_dialog = file_dialog_mock
|
||||||
|
|
||||||
|
# Select first file
|
||||||
|
with qtbot.waitSignal(content_widget.documents_added):
|
||||||
|
qtbot.mouseClick(
|
||||||
|
content_widget.doc_selection_widget.dangerous_doc_button,
|
||||||
|
QtCore.Qt.MouseButton.LeftButton,
|
||||||
|
)
|
||||||
|
file_dialog_mock.accept()
|
||||||
|
|
||||||
|
# Setup doc change
|
||||||
|
file_dialog_mock.selectedFiles.return_value = (sample_doc2,)
|
||||||
|
|
||||||
|
# When clicking on "select docs" button
|
||||||
|
with qtbot.waitSignal(content_widget.documents_added):
|
||||||
|
qtbot.mouseClick(
|
||||||
|
content_widget.settings_widget.change_selection_button,
|
||||||
|
QtCore.Qt.MouseButton.LeftButton,
|
||||||
|
)
|
||||||
|
file_dialog_mock.accept()
|
||||||
|
|
||||||
|
# Then two dialogs should have been open
|
||||||
|
assert file_dialog_mock.exec.call_count is 2
|
||||||
|
assert file_dialog_mock.selectedFiles.call_count is 2
|
||||||
|
|
||||||
|
# Then the final document should be only the second one
|
||||||
|
docs = [
|
||||||
|
doc.input_filename
|
||||||
|
for doc in content_widget.dangerzone.get_unconverted_documents()
|
||||||
|
]
|
||||||
|
assert len(docs) is 1
|
||||||
|
assert docs[0] == sample_doc2
|
||||||
|
|
Loading…
Reference in a new issue