This repository has been archived by the owner on Jan 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Use pytest without unittest's TestCase class #151
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbb29de
Avoid use of unittest; reorder tests for reliability
eloquence 9cd333e
Update cassettes, including naming of setup method
eloquence 20bc2af
black/isort reformatting
eloquence 55ed8c0
Simplify proxy tests and regenerate cassettes
eloquence 7f86083
Simplify proxy test setup; more useful error when proxy is AWOL
eloquence 3b1b12c
Further README clarifications for running proxy tests
eloquence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ class TestAPIProxy(TestShared): | |
""" | ||
|
||
@dastollervey_datasaver | ||
def setUp(self): | ||
def setup_method(self): | ||
self.totp = pyotp.TOTP("JHCOGO7VCER3EJ4L") | ||
self.username = "journalist" | ||
self.password = "correct horse battery staple profanity oil chewy" | ||
|
@@ -56,6 +56,7 @@ def setUp(self): | |
save_auth(self.api.token) | ||
break | ||
|
||
@dastollervey_datasaver | ||
def test_api_auth(self): | ||
super().api_auth() | ||
|
||
|
@@ -107,22 +108,6 @@ def test_get_all_submissions(self): | |
def test_flag_source(self): | ||
super().flag_source() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_source(self): | ||
super().delete_source() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_source_from_string(self): | ||
super().delete_source(from_string=True) | ||
|
||
@dastollervey_datasaver | ||
def test_delete_submission(self): | ||
super().delete_submission() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_submission_from_string(self): | ||
super().delete_submission(from_string=True) | ||
|
||
@dastollervey_datasaver | ||
def test_get_current_user(self): | ||
super().get_current_user() | ||
|
@@ -135,14 +120,6 @@ def test_get_users(self): | |
def test_error_unencrypted_reply(self): | ||
super().error_unencrypted_reply() | ||
|
||
@dastollervey_datasaver | ||
def test_reply_source(self): | ||
super().reply_source() | ||
|
||
@dastollervey_datasaver | ||
def test_reply_source_with_uuid(self): | ||
super().reply_source_with_uuid() | ||
|
||
@dastollervey_datasaver | ||
def test_get_replies_from_source(self): | ||
super().get_replies_from_source() | ||
|
@@ -155,10 +132,6 @@ def test_get_reply_from_source(self): | |
def test_get_all_replies(self): | ||
super().get_all_replies() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_reply(self): | ||
super().delete_reply() | ||
|
||
@dastollervey_datasaver | ||
def test_download_reply(self): | ||
r = self.api.get_all_replies()[0] | ||
|
@@ -180,7 +153,7 @@ def test_download_reply(self): | |
def test_download_submission(self): | ||
s = self.api.get_all_submissions()[0] | ||
|
||
self.assertFalse(s.is_read) | ||
assert not s.is_read | ||
|
||
# We need a temporary directory to download | ||
tmpdir = tempfile.mkdtemp() | ||
|
@@ -195,15 +168,47 @@ def test_download_submission(self): | |
# is_read should still be False as of SecureDrop 1.6.0 or later. | ||
|
||
s = self.api.get_submission(s) | ||
self.assertFalse(s.is_read) | ||
assert not s.is_read | ||
|
||
# Let us remove the temporary directory | ||
shutil.rmtree(tmpdir) | ||
|
||
# ORDER MATTERS: The following tests add or delete data, and should | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💎 |
||
# not be run before other tests which may rely on the original fixture | ||
# state. | ||
|
||
@dastollervey_datasaver | ||
def test_reply_source(self): | ||
super().reply_source() | ||
|
||
@dastollervey_datasaver | ||
def test_reply_source_with_uuid(self): | ||
super().reply_source_with_uuid() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_source(self): | ||
super().delete_source() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_source_from_string(self): | ||
super().delete_source(from_string=True) | ||
|
||
@dastollervey_datasaver | ||
def test_delete_submission(self): | ||
super().delete_submission() | ||
|
||
@dastollervey_datasaver | ||
def test_delete_submission_from_string(self): | ||
super().delete_submission(from_string=True) | ||
|
||
@dastollervey_datasaver | ||
def test_delete_reply(self): | ||
super().delete_reply() | ||
|
||
@dastollervey_datasaver | ||
def test_logout(self): | ||
r = self.api.logout() | ||
self.assertTrue(r) | ||
assert r | ||
if os.path.exists("login.txt"): | ||
os.unlink("login.txt") | ||
if os.path.exists("testtoken.json"): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: can we call this setup instead of setup_method?
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.
This method name is designated by
pytest
for the setup that runs before each test in class-based tests:https://docs.pytest.org/en/stable/xunit_setup.html#method-and-function-level-setup-teardown