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

Refactor functional test fixtures in source timeout and metadata tests #6307

Conversation

nabla-c0d3
Copy link
Contributor

@nabla-c0d3 nabla-c0d3 commented Feb 27, 2022

Status

Ready for review

Description of Changes

This PR includes and replaces the changes in #6207, and also addresses @legoktm 's feedback, such as putting the classes and functions in their "final" location in the code base.

Besides this addition, the intent and goals of the changes haven't changed, and are described there in details.

@nabla-c0d3 nabla-c0d3 force-pushed the refactor-source-functional-tests-timeout-metadata-notfound branch from 22cdf95 to a0c6e68 Compare February 27, 2022 20:30
@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2022

Codecov Report

Merging #6307 (c407a44) into develop (4b2399f) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #6307      +/-   ##
===========================================
- Coverage    83.99%   83.98%   -0.02%     
===========================================
  Files           61       61              
  Lines         4293     4301       +8     
  Branches       521      522       +1     
===========================================
+ Hits          3606     3612       +6     
- Misses         564      565       +1     
- Partials       123      124       +1     
Impacted Files Coverage Δ
securedrop/source_app/session_manager.py 96.66% <100.00%> (ø)
securedrop/store.py 90.04% <100.00%> (-0.05%) ⬇️
securedrop/journalist_app/__init__.py 89.07% <0.00%> (-1.11%) ⬇️
securedrop/source_app/__init__.py 90.52% <0.00%> (-0.10%) ⬇️
securedrop/models.py 89.55% <0.00%> (-0.02%) ⬇️
...d22043_remove_partial_index_on_valid_until_set_.py
...6f4d1e_remove_partial_index_on_valid_until_set_.py 40.90% <0.00%> (ø)
securedrop/source_app/main.py 93.20% <0.00%> (+0.06%) ⬆️
securedrop/template_filters.py 96.66% <0.00%> (+0.23%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@nabla-c0d3 nabla-c0d3 marked this pull request as ready for review February 27, 2022 21:08
@nabla-c0d3 nabla-c0d3 requested a review from a team as a code owner February 27, 2022 21:08
@nabla-c0d3 nabla-c0d3 force-pushed the refactor-source-functional-tests-timeout-metadata-notfound branch 2 times, most recently from 4f50a17 to ce09086 Compare March 5, 2022 15:09
@nabla-c0d3 nabla-c0d3 force-pushed the refactor-source-functional-tests-timeout-metadata-notfound branch from ce09086 to e6166d5 Compare March 13, 2022 09:37

Can be used for tests and utility scripts that need to add data to the DB outside of the
context of the source & journalist Flask applications.
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also eventually be used in utility scripts (to not have to instantiate a fake Flask app just to get "raw" access to the DB).

SECUREDROP_DATA_ROOT: Path,
SESSION_EXPIRATION_MINUTES: float = 120,
NOUNS: Path = DEFAULT_SECUREDROP_ROOT / "dictionaries" / "nouns.txt",
ADJECTIVES: Path = DEFAULT_SECUREDROP_ROOT / "dictionaries" / "adjectives.txt",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These arguments allow configuring the SD config that gets generated.

@@ -0,0 +1,79 @@
from pathlib import Path
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains two factories, which follow the API convention of the factoryboy library (in case this library is ever added to the unit tests dependencies). The factories can later be used in more code locations.

@nabla-c0d3 nabla-c0d3 marked this pull request as draft March 13, 2022 10:27
@nabla-c0d3 nabla-c0d3 force-pushed the refactor-source-functional-tests-timeout-metadata-notfound branch from e6166d5 to 6cca52f Compare March 13, 2022 10:47
@@ -0,0 +1,140 @@
from contextlib import contextmanager
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this is existing code taken from FunctionalTest.

def spawn_sd_servers(
config_to_use: SecureDropConfig
) -> Generator[SdServersFixtureResult, None, None]:
"""Spawn the source and journalist apps as separate processes with the supplied config."""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is the "killer" feature of the new spawn_sd_servers fixture and other factory code: the source and journalist apps to be spawned will use the supplied config_to_use regardless of the content of securedrop/config.py.

The confusion that comes from having to deal with live SDConfig objects that don't match the content of securedrop/config.py has been one of the biggest challenges for me when updating the test suite. This also comes from having different parts of the code sometimes use the live object or sometimes securedrop/config.py (it also depends on the order of imports in the code base...).

I think one medium term goal (started with some of the changes here) is to get rid of securedrop/config.py in the context of the test suite.

@nabla-c0d3 nabla-c0d3 marked this pull request as ready for review March 13, 2022 17:35
@nabla-c0d3
Copy link
Contributor Author

This should be ready for review again. Thanks!

@@ -0,0 +1,252 @@
import time
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this is existing code taken from FunctionalTest but "repackaged" as separate, smaller/simpler classes.

Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay in reviewing, this looks great! The two places you flagged as being duplicates, let's just remove them as part of this cleanup. Otherwise I think this is ready to go. Thank you for continuing to work on it!

securedrop/tests/functional/sd_config_v2.py Show resolved Hide resolved
securedrop/tests/functional/test_source_notfound.py Outdated Show resolved Hide resolved
securedrop/tests/functional/test_source_session_timeout.py Outdated Show resolved Hide resolved
Refactor source app warning tests using new fixtures

Refactor source app metadata test using new fixtures
@nabla-c0d3 nabla-c0d3 force-pushed the refactor-source-functional-tests-timeout-metadata-notfound branch from 6cca52f to c407a44 Compare March 26, 2022 21:30
@@ -1,17 +0,0 @@
from . import source_navigation_steps
Copy link
Contributor Author

@nabla-c0d3 nabla-c0d3 Mar 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because it was duplicating TestSourceSessionLayout.

@@ -1,10 +0,0 @@
from . import source_navigation_steps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because it was duplicating TestSourceLayout.test_notfound().

@nabla-c0d3
Copy link
Contributor Author

@legoktm Thanks for looking at this again; I removed the two duplicate tests.

@nabla-c0d3 nabla-c0d3 requested a review from legoktm March 26, 2022 21:38
Copy link
Member

@legoktm legoktm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@legoktm legoktm merged commit 1cc675f into freedomofpress:develop Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants