-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2188 from freedomofpress/delete-source-dialog-all…
…ow-multi Refactor DeleteSourceDialog so it accepts Set[Source]
- Loading branch information
Showing
5 changed files
with
142 additions
and
32 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
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
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 |
---|---|---|
@@ -1,22 +1,90 @@ | ||
import unittest | ||
import pytest | ||
|
||
from securedrop_client.gui.source.delete import DeleteSourceDialog as Dialog | ||
from securedrop_client.gui.source.delete import DeleteSourceDialog | ||
from tests import factory | ||
|
||
|
||
class DeleteSourceDialogTest(unittest.TestCase): | ||
def setUp(self): | ||
self._source = factory.Source() | ||
factory.File(source=self._source) | ||
self.dialog = Dialog(self._source) | ||
@pytest.fixture( | ||
params=[set(), set([factory.Source()]), set([factory.Source(), factory.Source()])], | ||
) | ||
def dialog(request): | ||
""" | ||
Set up the dialog under various conditions: 0 sources, 1 source, >1 source. | ||
Tests that target a specific configuration can use decorators to skip unwanted | ||
conditions. | ||
""" | ||
# Give the source(s) a submission | ||
for source in request.param: | ||
factory.File(source=source) | ||
return DeleteSourceDialog(request.param) | ||
|
||
def test_default_button_is_safer_choice(self): | ||
|
||
class TestDeleteSourceDialog: | ||
def test_dialog_setup(self, dialog): | ||
assert type(dialog) is DeleteSourceDialog | ||
assert type(dialog.sources) is set | ||
assert dialog.dangerous | ||
|
||
def test_default_button_is_safer_choice(self, dialog): | ||
# This test does rely on an implementation detail (the buttons) | ||
# but I couldn't find a way to test this properly using key events. | ||
assert not self.dialog.continue_button.isDefault() | ||
assert self.dialog.cancel_button.isDefault() | ||
assert not dialog.continue_button.isDefault() | ||
assert dialog.cancel_button.isDefault() | ||
|
||
def test_displays_important_information_when_shown(self, dialog): | ||
if len(dialog.sources) < 1: | ||
pytest.skip("Skip if no sources") | ||
assert "not be able to send them replies" in dialog.text() | ||
assert "source will not be able to log in" in dialog.text() | ||
assert "files and messages from that source will also be destroyed" in dialog.text() | ||
|
||
def test_dialog_continue_button_adapts_to_source_count(self, dialog): | ||
count = len(dialog.sources) | ||
|
||
if count < 1: | ||
pytest.skip("Skip if no sources") | ||
|
||
if count == 1: | ||
assert dialog.continue_button.text() == "YES, DELETE ENTIRE SOURCE ACCOUNT" | ||
elif count > 1: | ||
assert dialog.continue_button.text() == f"YES, DELETE {count} SOURCE ACCOUNTS" | ||
else: | ||
# should be unreachable due to decorator | ||
pytest.fail("Unreachable, or so we thought") | ||
|
||
def test_no_sources_shows_error_text(self, dialog): | ||
if len(dialog.sources) > 0: | ||
pytest.skip("Skip if sources") | ||
|
||
assert dialog.text() == "No sources have been selected." | ||
|
||
def test_no_sources_continue_button_disabled(self, dialog): | ||
if len(dialog.sources) > 0: | ||
pytest.skip("Skip if sources") | ||
|
||
assert not dialog.continue_button.isEnabled() | ||
|
||
def test_correct_format_body_text(self): | ||
""" | ||
For n > 1 sources, ensure the warning text includes | ||
all the journalist desginators. | ||
""" | ||
sources = set() | ||
names = [ | ||
"source one", | ||
"source two", | ||
"source three", | ||
"source four", | ||
"source five", | ||
"source six", | ||
"source seven", | ||
] | ||
|
||
for item in names: | ||
source = factory.Source(journalist_designation=item) | ||
sources.update([source]) | ||
|
||
dialog = DeleteSourceDialog(sources) | ||
|
||
def test_displays_important_information_when_shown(self): | ||
assert "not be able to send them replies" in self.dialog.text() | ||
assert "source will not be able to log in" in self.dialog.text() | ||
assert "files and messages from that source will also be destroyed" in self.dialog.text() | ||
for n in names: | ||
assert n in dialog.make_body_text(sources) |
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