Skip to content

Commit

Permalink
refactor: move locale parameterization from tests to the firefox_web_…
Browse files Browse the repository at this point in the history
…driver fixture

That is, instead of receiving a "locale" fixture directly, tests that
use the "firefox_web_driver" fixture are now parameterized indirectly,
via the firefox_web_driver.locale attribute received from the
parameterized fixture.
  • Loading branch information
cfm committed Oct 11, 2024
1 parent f8ecf5e commit 7900e21
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 81 deletions.
12 changes: 7 additions & 5 deletions securedrop/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
from tests.utils.i18n import get_test_locales


# Function-scoped so that tests can be run in parallel if needed
@pytest.fixture
def firefox_web_driver(locale: str = "en_US") -> WebDriver: # type: ignore
# Function-scoped so that tests can be run in parallel if needed. The fixture
# needs to know the locale at setup time, so we do that parameterization here
# rather than at the test level.
@pytest.fixture(params=get_test_locales())
def firefox_web_driver(request) -> WebDriver: # type: ignore
locale = request.param.replace("_", "-")
with get_web_driver(
web_driver_type=WebDriverTypeEnum.FIREFOX,
accept_languages=locale.replace("_", "-"),
web_driver_type=WebDriverTypeEnum.FIREFOX, accept_languages=locale
) as web_driver:
yield web_driver

Expand Down
33 changes: 16 additions & 17 deletions securedrop/tests/functional/pageslayout/test_journalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
#
import pytest
from tests.functional.app_navigators.journalist_app_nav import JournalistAppNavigator
from tests.functional.pageslayout.utils import list_locales, save_static_data
from tests.functional.pageslayout.utils import save_static_data


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestJournalistLayout:
def test_login_index_and_edit(self, locale, sd_servers, firefox_web_driver):
def test_login_index_and_edit(self, sd_servers, firefox_web_driver, request):
locale = firefox_web_driver.locale
# Given an SD server
# And a journalist accessing the journalist interface
locale_with_commas = locale.replace("_", "-")
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.driver.get(f"{sd_servers.journalist_app_base_url}/login")
journ_app_nav.got_expected_language(locale)
Expand All @@ -55,14 +54,14 @@ def test_login_index_and_edit(self, locale, sd_servers, firefox_web_driver):
journ_app_nav.journalist_visits_edit_account()
save_static_data(journ_app_nav.driver, locale, "journalist-edit_account_user")

def test_index_entered_text(self, locale, sd_servers, firefox_web_driver):
def test_index_entered_text(self, sd_servers, firefox_web_driver):
# Given an SD server
# And a journalist accessing the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)

# Take a screenshot of the login page with the form completed
Expand All @@ -75,15 +74,15 @@ def test_index_entered_text(self, locale, sd_servers, firefox_web_driver):
save_static_data(journ_app_nav.driver, locale, "journalist-index_with_text")

def test_index_with_submission_and_select_documents(
self, locale, sd_servers_with_submitted_file, firefox_web_driver
self, sd_servers_with_submitted_file, firefox_web_driver
):
# Given an SD server with an already-submitted file
# And a journalist logging into the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_submitted_file.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)

# Take a screenshot of the index page when there is a source and submission
Expand Down Expand Up @@ -116,27 +115,27 @@ def test_index_with_submission_and_select_documents(
)
save_static_data(journ_app_nav.driver, locale, "journalist-composes_reply")

def test_fail_to_visit_admin(self, locale, sd_servers, firefox_web_driver):
def test_fail_to_visit_admin(self, sd_servers, firefox_web_driver):
# Given an SD server
# And someone accessing the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
# Take a screenshot of them trying to force-browse to the admin interface
journ_app_nav.driver.get(f"{sd_servers.journalist_app_base_url}/admin")
save_static_data(journ_app_nav.driver, locale, "journalist-code-fail_to_visit_admin")

def test_fail_login(self, locale, sd_servers, firefox_web_driver):
def test_fail_login(self, sd_servers, firefox_web_driver):
# Given an SD server
# And someone accessing the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)

# Take a screenshot of trying to log in using invalid credentials
Expand Down
17 changes: 7 additions & 10 deletions securedrop/tests/functional/pageslayout/test_journalist_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from tests.functional.app_navigators.journalist_app_nav import JournalistAppNavigator
from tests.functional.pageslayout.utils import list_locales, save_static_data
from tests.functional.pageslayout.utils import save_static_data


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestJournalistLayoutAccount:
def test_account_edit_and_set_hotp_secret(
self, locale, sd_servers_with_clean_state, firefox_web_driver
self, sd_servers_with_clean_state, firefox_web_driver
):
# Given an SD server
# And a journalist logging into the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_clean_state.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_clean_state.journalist_username,
Expand Down Expand Up @@ -97,16 +96,14 @@ def explanatory_tooltip_is_correct() -> None:
alert = journ_app_nav.driver.switch_to.alert
alert.accept()

def test_account_new_two_factor_totp(
self, locale, sd_servers_with_clean_state, firefox_web_driver
):
def test_account_new_two_factor_totp(self, sd_servers_with_clean_state, firefox_web_driver):
# Given an SD server
# And a journalist logging into the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_clean_state.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_clean_state.journalist_username,
Expand Down
28 changes: 13 additions & 15 deletions securedrop/tests/functional/pageslayout/test_journalist_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from tests.functional.app_navigators.journalist_app_nav import JournalistAppNavigator
from tests.functional.pageslayout.utils import list_locales, save_static_data
from tests.functional.pageslayout.utils import save_static_data


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestAdminLayoutAddAndEditUser:
def test_admin_adds_user_hotp_and_edits_hotp(
self, locale, sd_servers_with_clean_state, firefox_web_driver
self, sd_servers_with_clean_state, firefox_web_driver
):
# Given an SD server
# And a journalist logging into the journalist interface as an admin
assert sd_servers_with_clean_state.journalist_is_admin
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_clean_state.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_clean_state.journalist_username,
Expand Down Expand Up @@ -118,16 +117,16 @@ def _admin_visits_reset_2fa_hotp_step() -> None:
)

def test_admin_adds_user_totp_and_edits_totp(
self, locale, sd_servers_with_clean_state, firefox_web_driver
self, sd_servers_with_clean_state, firefox_web_driver
):
# Given an SD server
# And a journalist logging into the journalist interface as an admin
assert sd_servers_with_clean_state.journalist_is_admin
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_clean_state.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_clean_state.journalist_username,
Expand Down Expand Up @@ -223,18 +222,17 @@ def _retry_2fa_pop_ups(
logging.info("Selenium has failed to click; retrying.")


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestAdminLayoutEditConfig:
def test_admin_changes_logo(self, locale, sd_servers_with_clean_state, firefox_web_driver):
def test_admin_changes_logo(self, sd_servers_with_clean_state, firefox_web_driver):
# Given an SD server
# And a journalist logging into the journalist interface as an admin
assert sd_servers_with_clean_state.journalist_is_admin
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_clean_state.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_clean_state.journalist_username,
Expand Down Expand Up @@ -264,15 +262,15 @@ def updated_image() -> None:
# Take a screenshot
save_static_data(journ_app_nav.driver, locale, "journalist-admin_changes_logo_image")

def test_ossec_alert_button(self, locale, sd_servers, firefox_web_driver):
def test_ossec_alert_button(self, sd_servers, firefox_web_driver):
# Given an SD server
# And a journalist logging into the journalist interface as an admin
assert sd_servers.journalist_is_admin
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers.journalist_username,
Expand Down
15 changes: 7 additions & 8 deletions securedrop/tests/functional/pageslayout/test_journalist_col.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tests.factories import SecureDropConfigFactory
from tests.functional.app_navigators.journalist_app_nav import JournalistAppNavigator
from tests.functional.conftest import SdServersFixtureResult, spawn_sd_servers
from tests.functional.pageslayout.utils import list_locales, save_static_data
from tests.functional.pageslayout.utils import save_static_data


def _create_source_and_submission_and_delete_source_key(config_in_use: SecureDropConfig) -> None:
Expand Down Expand Up @@ -63,19 +63,18 @@ def sd_servers_with_deleted_source_key(
yield sd_servers_result


@pytest.mark.parametrize("locale", list_locales())
@pytest.mark.pagelayout
class TestJournalistLayoutCol:
def test_col_with_and_without_documents(
self, locale, sd_servers_with_submitted_file, firefox_web_driver
self, sd_servers_with_submitted_file, firefox_web_driver
):
# Given an SD server with an already-submitted file
# And a journalist logging into the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_submitted_file.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_submitted_file.journalist_username,
Expand Down Expand Up @@ -105,14 +104,14 @@ def submission_deleted() -> None:
journ_app_nav.nav_helper.wait_for(submission_deleted)
save_static_data(journ_app_nav.driver, locale, "journalist-col_no_document")

def test_col_has_no_key(self, locale, sd_servers_with_deleted_source_key, firefox_web_driver):
def test_col_has_no_key(self, sd_servers_with_deleted_source_key, firefox_web_driver):
# Given an SD server with an already-submitted file, but the source's key was deleted
# And a journalist logging into the journalist interface
locale_with_commas = locale.replace("_", "-")
locale = firefox_web_driver.locale
journ_app_nav = JournalistAppNavigator(
journalist_app_base_url=sd_servers_with_deleted_source_key.journalist_app_base_url,
web_driver=firefox_web_driver,
accept_languages=locale_with_commas,
accept_languages=locale,
)
journ_app_nav.journalist_logs_in(
username=sd_servers_with_deleted_source_key.journalist_username,
Expand Down
Loading

0 comments on commit 7900e21

Please sign in to comment.