-
Notifications
You must be signed in to change notification settings - Fork 688
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
Rewrite tests with pytest fixtures #2948
Conversation
e114fd3
to
3cfd549
Compare
b0acd4e
to
b38cdbf
Compare
ba9e6ca
to
40fc5f5
Compare
I think somehow the cache is causing trouble in CircleCI. |
@kushaldas That's what I thought too. I guess I'll open a ticket for that. |
For now, it seems like this PR is blocked by #3033. Once that is merged, the strange test failure logic related to this line: c = imp.load_module('c', *imp.find_module('config')) should go away. But to be fair, I'm not positive that's the line that's causing problems, but it's definitely the most likely one. |
90de09a
to
e118c6a
Compare
Codecov Report
@@ Coverage Diff @@
## develop #2948 +/- ##
===========================================
+ Coverage 84.31% 88.64% +4.33%
===========================================
Files 34 32 -2
Lines 2027 1849 -178
Branches 221 212 -9
===========================================
- Hits 1709 1639 -70
+ Misses 262 162 -100
+ Partials 56 48 -8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent 💯, really happy this is done. I won't lie: it is not the most entertaining PR to review. But you made it very easy for the reviewer by clearly separating each commit, thanks a lot for this.
I have just one quesiton and two nits, other than this I think it is good to merge.
securedrop/tests/test_source.py
Outdated
assert "BEGIN PGP PUBLIC KEY BLOCK" in text | ||
|
||
def test_login_and_logout(self, source_app): | ||
with source_app.test_client() as app: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Would it be a problem to keep multiple with source_app.test_client() as app:
to separate the blocks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the grounds for that nit? I think it might do some silly things to sessions and whatnot (but could be wrong).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the code in each block is a separate test case, having them use a different test client makes sense (really they should be in different tests entirely - but in the spirit of not expanding the scope of this PR beyond strictly rewriting the tests to use pytest fixtures, @dachary's suggestion seems reasonable)
securedrop/tests/test_source.py
Outdated
login_test(app, codename_) | ||
|
||
@staticmethod | ||
def _dummy_submission(app): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: for clarity removal of the old _dummy_submission is in commit pytest fixtures: test_csrf_error_page but should be in commit pytest fixtures: test_initial_submission_notification where the static version is introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't move all the tests at once, so I leave it in the old class because there are tests that required it,
securedrop/tests/test_source.py
Outdated
session.pop('csrf_token', None) | ||
assert not session, session | ||
text = resp.data.decode('utf-8') | ||
assert 'Your session timed out due to inactivity' in text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it different from You have been logged out due to inactivity
? It indicates the test does not behave in the same way and this is either cause for concern or a detailed explanation in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That string never appears in the source app, and also that test was prefixed with _test
so it was never actually run before. We have higher coverage now that it is actually run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks for the organized git history here :) one nit inline and one optional suggestion to look at - otherwise I'm happy with this being merged
securedrop/tests/test_source.py
Outdated
follow_redirects=True) | ||
assert resp.status_code == 200 | ||
text = resp.data.decode('utf-8') | ||
assert "Submit Materials" in text, text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in text, text
-> in text
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken the idea here is to display text
in case the assert fails but ... pytest
instruments the assert
and displays the actual values being compared when it fails. So +1 on the Nit ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, we should probably do that with all cases since seeing ...
in the error output is not very helpful, but that one probably got left in by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
securedrop/tests/test_source.py
Outdated
|
||
overly_long_codename = 'a' * (Source.MAX_CODENAME_LEN + 1) | ||
|
||
|
||
class TestSourceApp(TestCase): | ||
class TestSourceApp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of the TestSourceApp
class now, which I think would be nice to flatten this file a bit (if you make this change you could do it in an additional commit if it's easier)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need this class for setup
and teardown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use those anymore. Lifecycles are managed by pytest
alone.
7f58b73
to
0b25f12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff looks good, thanks for making those changes! 👍 to merge from me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on @redshiftzero review. I would dismiss my review if only it was posssible.
We have not used the flask_testing library since <#2948> (2018), a small part of it was directly copied into SecureDrop. Plus that version of the library was incompatible with Flask 2.0+ and by getting rid of it we don't explicitly have to pin Jinja nor markupsafe.
We have not used the flask_testing library since <#2948> (2018), a small part of it was directly copied into SecureDrop. Plus that version of the library was incompatible with Flask 2.0+ and by getting rid of it we don't explicitly have to pin Jinja nor markupsafe. (cherry picked from commit 65f092c)
Status
Ready for review
Description of Changes
Work towards #2877
Added
pytest
fixtures to centralize app creation logic for the source appTesting
make test
Checklist
If you made changes to the app code: