Skip to content

Commit

Permalink
parameterized test to handle every possible use case ever /s
Browse files Browse the repository at this point in the history
  • Loading branch information
Vebop committed Sep 6, 2024
1 parent d6005d8 commit da14f81
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tests/test_consdbClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand Down

0 comments on commit da14f81

Please sign in to comment.