Skip to content

Commit

Permalink
fix(client): timeout parameter with default
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Sep 14, 2023
1 parent 536c200 commit 6bb9dc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion eligibility_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
jwe_cek_enc,
server_public_key,
headers={},
timeout=5,
):
self.verify_url = verify_url

Expand All @@ -44,6 +45,7 @@ def __init__(
raise ValueError('"Authorization" should not be set as an additional header.')

self.headers = headers
self.timeout = timeout

def _tokenize_request(self, sub, name, types):
"""Create a request token."""
Expand Down Expand Up @@ -91,7 +93,7 @@ def _request(self, sub, name, types):

try:
logger.debug(f"GET request to {self.verify_url}")
r = requests.get(self.verify_url, headers=self._auth_headers(token))
r = requests.get(self.verify_url, headers=self._auth_headers(token), timeout=self.timeout)
except requests.ConnectionError:
raise ApiError("Connection to verification server failed")
except requests.Timeout:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ def test_create_valid_client():
pytest.fail("Failed to create valid Client")


def test_create_valid_client_timeout():
client = Client(**valid_configuration())

assert client.timeout == 5

client = Client(**valid_configuration(), timeout=1000)

assert client.timeout == 1000


@pytest.mark.parametrize("header_name", ["Authorization", "authorization", "AuThOrIzAtIoN"])
def test_create_invalid_client_bad_headers(header_name):
headers = {header_name: "value"}
Expand Down

0 comments on commit 6bb9dc2

Please # to comment.