-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parameterized test to handle every possible use case ever /s
- Loading branch information
Showing
1 changed file
with
15 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -165,16 +165,26 @@ def test_schema(client): | |
|
||
|
||
@responses.activate | ||
def test_clean_token_url_response(): | ||
@pytest.mark.parametrize( | ||
"secret, redacted", | ||
[ | ||
("usdf:v987wefVMPz", "us***:v9***"), | ||
("u:v", "u***:v***"), | ||
("ulysses", "ul***"), | ||
(":alberta94", "***:al***"), | ||
], | ||
) | ||
def test_clean_token_url_response(secret, redacted): | ||
"""Test tokens URL is cleaned when an error is thrown from requests | ||
Use with pytest raises assert an error, | ||
Use with pytest raises assert an error' | ||
assert that url does not contain tokens | ||
""" | ||
complex_client = ConsDbClient("https://usdf:[email protected]/consdb") | ||
domain = "@usdf-fake.slackers.stanford.edu/consdb" | ||
complex_client = ConsDbClient(f"https://{secret}{domain}") | ||
|
||
obs_type = "exposure" | ||
responses.post( | ||
"https://usdf:[email protected]/consdb/flex/bad_instrument/exposure/addkey", | ||
f"https://{secret}{domain}/flex/bad_instrument/exposure/addkey", | ||
status=404, | ||
) | ||
with pytest.raises(HTTPError, match="404") as error: | ||
|
@@ -183,11 +193,7 @@ def test_clean_token_url_response(): | |
) | ||
|
||
url = error.value.args[0].split()[-1] | ||
sanitized = ( | ||
"https://us***:v9***@usdf-fake.slackers.stanford.edu/consdb/flex/bad_instrument/exposure/addkey" | ||
) | ||
|
||
assert "v987wefVMPz" not in url | ||
sanitized = f"https://{redacted}{domain}/flex/bad_instrument/exposure/addkey" | ||
assert url == sanitized | ||
|
||
|
||
|