Skip to content

Commit

Permalink
Ensure functional test assertions are evalated
Browse files Browse the repository at this point in the history
Replace guard clause to ensure assertions are evaluated when running
functional tests (ref. freedomofpress#5607).
  • Loading branch information
DrGFreeman committed Nov 10, 2020
1 parent ce22827 commit f7899e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
32 changes: 16 additions & 16 deletions securedrop/tests/functional/journalist_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _journalist_clicks_delete_collections_on_modal(self):
self._journalist_clicks_on_modal("delete-collections")

def collection_deleted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "1 collection deleted" in flash_msg.text

Expand All @@ -163,7 +163,7 @@ def _journalist_clicks_delete_selected_on_modal(self):
self._journalist_clicks_on_modal("delete-selected")

def submission_deleted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Submission deleted." in flash_msg.text

Expand Down Expand Up @@ -275,7 +275,7 @@ def _admin_updates_logo_image(self):
self.safe_click_by_id("submit-logo-update")

def updated_image():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Image updated." in flash_msg.text

Expand Down Expand Up @@ -327,7 +327,7 @@ def _admin_adds_a_user_with_invalid_username(self):

self.wait_for(lambda: self.driver.find_element_by_id("username"))

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
# The add user page has a form with an "ADD USER" button
btns = self.driver.find_elements_by_tag_name("button")
assert "ADD USER" in [el.text for el in btns]
Expand All @@ -349,7 +349,7 @@ def _admin_adds_a_user(self, is_admin=False, new_username=""):

self.wait_for(lambda: self.driver.find_element_by_id("username"))

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
# The add user page has a form with an "ADD USER" button
btns = self.driver.find_elements_by_tag_name("button")
assert "ADD USER" in [el.text for el in btns]
Expand All @@ -364,7 +364,7 @@ def _admin_adds_a_user(self, is_admin=False, new_username=""):
last_name=self.new_user['last_name'],
is_admin=is_admin)

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
# Clicking submit on the add user form should redirect to
# the FreeOTP page
h1s = [h1.text for h1 in self.driver.find_elements_by_tag_name("h1")]
Expand All @@ -380,7 +380,7 @@ def _admin_adds_a_user(self, is_admin=False, new_username=""):
self.safe_click_by_css_selector("button[type=submit]")

def user_token_added():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
# Successfully verifying the code should redirect to the admin
# interface, and flash a message indicating success
flash_msg = self.driver.find_elements_by_css_selector(".flash")
Expand All @@ -403,7 +403,7 @@ def _admin_deletes_user(self):
logging.info("Selenium has failed to click yet again; retrying.")

def user_deleted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Deleted user" in flash_msg.text

Expand All @@ -414,7 +414,7 @@ def _admin_can_send_test_alert(self):
alert_button.click()

def test_alert_sent():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Test alert sent. Please check your email." in flash_msg.text

Expand Down Expand Up @@ -566,7 +566,7 @@ def can_edit_user():
self.safe_click_by_css_selector("button[type=submit]")

def user_edited():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Invalid username" in flash_msg.text

Expand Down Expand Up @@ -608,7 +608,7 @@ def can_edit_user():
self.safe_click_by_css_selector("button[type=submit]")

def user_edited():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
flash_msg = self.driver.find_element_by_css_selector(".flash")
assert "Account updated." in flash_msg.text

Expand Down Expand Up @@ -676,7 +676,7 @@ def _journalist_checks_messages(self):
assert 0 != len(code_names), code_names
assert 1 <= len(code_names), code_names

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
# There should be a "1 unread" span in the sole collection entry
unread_span = self.driver.find_element_by_css_selector("span.unread")
assert "1 unread" in unread_span.text
Expand Down Expand Up @@ -776,7 +776,7 @@ def _journalist_sends_reply_to_source(self):
self.driver.find_element_by_id("reply-button").click()

def reply_stored():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
assert "Thanks. Your reply has been stored." in self.driver.page_source

self.wait_for(reply_stored)
Expand Down Expand Up @@ -805,7 +805,7 @@ def explanatory_tooltip_is_correct():
explanatory_tooltip_opacity = explanatory_tooltip.value_of_css_property("opacity")
assert explanatory_tooltip_opacity == "1"

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
assert explanatory_tooltip.text == tooltip_text

self.wait_for(explanatory_tooltip_is_correct)
Expand Down Expand Up @@ -895,7 +895,7 @@ def _admin_visits_reset_2fa_hotp_step():

assert tip_opacity == "1"

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
assert tip_text == "Reset two-factor authentication for security keys like Yubikey"

self.safe_click_by_id("button-reset-two-factor-hotp")
Expand Down Expand Up @@ -925,7 +925,7 @@ def _admin_visits_reset_2fa_totp_step():
"#button-reset-two-factor-totp span")[0].text

assert tip_opacity == "1"
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
expected_text = (
"Reset two-factor authentication for mobile apps such as FreeOTP "
"or Google Authenticator"
Expand Down
16 changes: 8 additions & 8 deletions securedrop/tests/functional/source_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def _source_enters_codename_in_login_form(self):
def _source_hits_cancel_at_submit_page(self):
self.driver.find_element_by_id("cancel").click()

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
headline = self.driver.find_element_by_class_name("headline")
assert "Submit Files or Messages" == headline.text

def _source_continues_to_submit_page(self):
self.safe_click_by_id("continue-button")

def submit_page_loaded():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
headline = self.driver.find_element_by_class_name("headline")
assert "Submit Files or Messages" == headline.text

Expand All @@ -144,7 +144,7 @@ def _source_submits_a_file(self):
self.wait_for_source_key(self.source_name)

def file_submitted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
notification = self.driver.find_element_by_css_selector(".success")
expected_notification = "Thank you for sending this information to us"
assert expected_notification in notification.text
Expand All @@ -160,7 +160,7 @@ def _source_submits_a_message(self):
self._source_clicks_submit_button_on_submission_page()

def message_submitted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
notification = self.driver.find_element_by_css_selector(".success")
assert "Thank" in notification.text

Expand Down Expand Up @@ -198,7 +198,7 @@ def confirm_displayed():
confirm_button.click()

def reply_deleted():
if not hasattr(self, "accept_languages"):
if not self.accept_languages:
notification = self.driver.find_element_by_class_name("notification")
assert "Reply deleted" in notification.text

Expand Down Expand Up @@ -228,7 +228,7 @@ def _source_waits_for_session_to_timeout(self):
def _source_sees_session_timeout_message(self):
notification = self.driver.find_element_by_css_selector(".important")

if not hasattr(self, "accept_languages"):
if not self.accept_languages:
expected_text = "You were logged out due to inactivity."
assert expected_text in notification.text

Expand All @@ -242,13 +242,13 @@ def _source_does_not_sees_document_attachment_item(self):
def _source_sees_already_logged_in_in_other_tab_message(self):
notification = self.driver.find_element_by_css_selector(".notification")

if not hasattr(self, "accepted_languages"):
if not self.accept_languages:
expected_text = "You are already logged in."
assert expected_text in notification.text

def _source_sees_redirect_already_logged_in_message(self):
notification = self.driver.find_element_by_css_selector(".notification")

if not hasattr(self, "accepted_languages"):
if not self.accept_languages:
expected_text = "You were redirected because you are already logged in."
assert expected_text in notification.text

0 comments on commit f7899e1

Please sign in to comment.