Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use definite article for single file error case; improve functional test output #5905

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion securedrop/journalist_app/col.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def download_single_file(filesystem_id: str, fn: str) -> werkzeug.Response:
if not Path(file).is_file():
flash(
gettext(
"Your download failed because a file could not be found. An admin can find "
"Your download failed because the file could not be found. An admin can find "
+ "more information in the system and monitoring logs."
),
"error"
Expand Down
7 changes: 5 additions & 2 deletions securedrop/journalist_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ def download(
zf = current_app.storage.get_bulk_archive(submissions, zip_directory=zip_basename)
except FileNotFoundError:
flash(
gettext(
ngettext(
"Your download failed because the file could not be found. An admin can find "
+ "more information in the system and monitoring logs.",
"Your download failed because a file could not be found. An admin can find "
+ "more information in the system and monitoring logs."
+ "more information in the system and monitoring logs.",
len(submissions)
),
"error"
)
Expand Down
5 changes: 5 additions & 0 deletions securedrop/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# -*- coding: utf-8 -*-
from os.path import abspath, dirname, join, realpath
import pytest
import sys

# The tests directory should be adjacent to the securedrop directory. By adding
# the securedrop directory to sys.path here, all test modules are able to
# directly import modules in the securedrop directory.
sys.path.append(abspath(join(dirname(realpath(__file__)), '..', 'securedrop')))

# This ensures we get pytest's more detailed assertion output in helper functions
pytest.register_assert_rewrite('tests.functional.journalist_navigation_steps')
pytest.register_assert_rewrite('tests.functional.source_navigation_steps')
17 changes: 13 additions & 4 deletions securedrop/tests/functional/journalist_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,15 +1181,24 @@ def _journalist_uses_js_buttons_to_download_unread(self):
classes = checkbox.get_attribute("class")
assert "unread-cb" in classes

def _journalist_sees_missing_file_error_message(self):
def _journalist_sees_missing_file_error_message(self, single_file=False):
notification = self.driver.find_element_by_css_selector(".error")

if self.accept_languages is None:
expected_text = (
# We use a definite article ("the" instead of "a") if a single file
# is downloaded directly.
if single_file:
error_msg = (
"Your download failed because the file could not be found. An admin can find "
+ "more information in the system and monitoring logs."
)
else:
error_msg = (
"Your download failed because a file could not be found. An admin can find "
+ "more information in the system and monitoring logs."
)
assert expected_text == notification.text

if self.accept_languages is None:
assert notification.text == error_msg

def _journalist_is_on_collection_page(self):
return self.wait_for(
Expand Down
10 changes: 5 additions & 5 deletions securedrop/tests/functional/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ def test_download_source_unread(self, missing_msg_file):
journalist home page."""
self._journalist_logs_in()
self._journalist_clicks_source_unread()
self._journalist_sees_missing_file_error_message()
self._journalist_sees_missing_file_error_message(single_file=True)
self._is_on_journalist_homepage()

def test_select_source_and_download_all(self, missing_msg_file):
"""Test behavior when the journalist selects the source then clicks the "Download" button
from the journalist home page."""
self._journalist_logs_in()
self._journalist_selects_first_source_then_download_all()
self._journalist_sees_missing_file_error_message()
self._journalist_sees_missing_file_error_message(single_file=True)
self._is_on_journalist_homepage()

def test_select_source_and_download_unread(self, missing_msg_file):
"""Test behavior when the journalist selects the source then clicks the "Download Unread"
button from the journalist home page."""
self._journalist_logs_in()
self._journalist_selects_first_source_then_download_unread()
self._journalist_sees_missing_file_error_message()
self._journalist_sees_missing_file_error_message(single_file=True)
self._is_on_journalist_homepage()

def test_download_message(self, missing_msg_file):
Expand All @@ -158,7 +158,7 @@ def test_download_message(self, missing_msg_file):
self._journalist_logs_in()
self._journalist_checks_messages()
self._journalist_downloads_message_missing_file()
self._journalist_sees_missing_file_error_message()
self._journalist_sees_missing_file_error_message(single_file=True)
self._journalist_is_on_collection_page()

def test_select_message_and_download_selected(self, missing_msg_file):
Expand All @@ -167,5 +167,5 @@ def test_select_message_and_download_selected(self, missing_msg_file):
self._journalist_logs_in()
self._journalist_selects_the_first_source()
self._journalist_selects_message_then_download_selected()
self._journalist_sees_missing_file_error_message()
self._journalist_sees_missing_file_error_message(single_file=True)
self._journalist_is_on_collection_page()