From da14f81a35614378994383f76c72b4ab2408a868 Mon Sep 17 00:00:00 2001 From: Valerie Becker Date: Fri, 6 Sep 2024 15:16:18 +0000 Subject: [PATCH] parameterized test to handle every possible use case ever /s --- tests/test_consdbClient.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/test_consdbClient.py b/tests/test_consdbClient.py index 2eae451c..0b8c0289 100644 --- a/tests/test_consdbClient.py +++ b/tests/test_consdbClient.py @@ -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:v987wefVMPz@usdf-fake.slackers.stanford.edu/consdb") + domain = "@usdf-fake.slackers.stanford.edu/consdb" + complex_client = ConsDbClient(f"https://{secret}{domain}") obs_type = "exposure" responses.post( - "https://usdf:v987wefVMPz@usdf-fake.slackers.stanford.edu/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