Skip to content

Commit

Permalink
Merge pull request #6361 from nabla-c0d3/refactor-source-functional-t…
Browse files Browse the repository at this point in the history
…ests-codenames-and-collision

Refactor source functional tests codenames and collision
  • Loading branch information
legoktm authored Apr 13, 2022
2 parents 1458290 + c187124 commit f0dd9a8
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 204 deletions.
18 changes: 15 additions & 3 deletions securedrop/tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import multiprocessing
from contextlib import contextmanager
from dataclasses import dataclass
from multiprocessing.context import Process
from pathlib import Path
from typing import Generator
import requests
Expand Down Expand Up @@ -100,9 +100,21 @@ def spawn_sd_servers(
# Spawn the source and journalist web apps in separate processes
source_port = _get_unused_port()
journalist_port = _get_unused_port()
source_app_process = Process(target=_start_source_server, args=(source_port, config_to_use))

# Start the server subprocesses using the "spawn" method instead of "fork".
# This is needed for the config_to_use argument to work; if "fork" is used, the subprocess
# will inherit all the globals from the parent process, which will include the Python
# variables declared as "global" in the SD code base
# (example: see _DesignationGenerator.get_default()).
# This means the config_to_use will be ignored if these globals have already been
# initialized (for example by tests running before the code here).
mp_spawn_ctx = multiprocessing.get_context("spawn")

source_app_process = mp_spawn_ctx.Process( # type: ignore
target=_start_source_server, args=(source_port, config_to_use)
)
source_app_process.start()
journalist_app_process = Process(
journalist_app_process = mp_spawn_ctx.Process( # type: ignore
target=_start_journalist_server, args=(journalist_port, config_to_use)
)
journalist_app_process.start()
Expand Down
4 changes: 2 additions & 2 deletions securedrop/tests/functional/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def create(
) -> SecureDropConfig:
"""Create a securedrop config suitable for the unit tests.
It will automatically create an initialized DB at SECUREDROP_DATA_ROOT/db.sqlite which will
be set as the DATABASE_FILE.
It will erase any existing file within SECUREDROP_DATA_ROOT and then create an initialized
DB at SECUREDROP_DATA_ROOT/db.sqlite which will be set as the DATABASE_FILE.
"""
# Clear the data root directory
if SECUREDROP_DATA_ROOT.exists():
Expand Down
8 changes: 0 additions & 8 deletions securedrop/tests/functional/source_navigation_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ def submit_page_loaded():

self.wait_for(submit_page_loaded)

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

self.wait_for(lambda: self.driver.find_element_by_css_selector(".error"))
flash_error = self.driver.find_element_by_css_selector(".error")
assert "There was a temporary problem creating your account. Please try again." \
== flash_error.text

def _source_submits_a_file(self):
with tempfile.NamedTemporaryFile() as file:
file.write(self.secret_message.encode("utf-8"))
Expand Down
Loading

0 comments on commit f0dd9a8

Please sign in to comment.