-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test to document change button
Fixes #428
- Loading branch information
Showing
6 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
from pytest_mock import MockerFixture | ||
from pytestqt.qtbot import QtBot | ||
|
||
from dangerzone.gui.main_window import * | ||
|
||
from .. import sample_doc, sample_doc2 | ||
|
||
# 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 | ||
## | ||
|
||
|
||
@pytest.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 | ||
|
||
|
||
## | ||
## 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 |