diff --git a/pennylane_ionq/api_client.py b/pennylane_ionq/api_client.py index 08f9365..18065b7 100644 --- a/pennylane_ionq/api_client.py +++ b/pennylane_ionq/api_client.py @@ -116,7 +116,7 @@ class APIClient: HOSTNAME = "api.ionq.co/v0.1" BASE_URL = "https://{}".format(HOSTNAME) - def __init__(self, **kwargs): + def __init__(self, timeout_seconds=600, **kwargs): self.AUTHENTICATION_TOKEN = os.getenv("IONQ_API_KEY") or kwargs.get("api_key", None) self.DEBUG = False @@ -130,7 +130,7 @@ def __init__(self, **kwargs): self.HEADERS = {"User-Agent": self.USER_AGENT} # Ten minute timeout on requests. - self.TIMEOUT_SECONDS = 60 * 10 + self.TIMEOUT_SECONDS = timeout_seconds if self.AUTHENTICATION_TOKEN: self.set_authorization_header(self.AUTHENTICATION_TOKEN) diff --git a/tests/test_api_client.py b/tests/test_api_client.py index e30d8e8..e0014ee 100755 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -190,6 +190,27 @@ def test_get(self, monkeypatch): mock_client.get.assert_called_once() manager.handle_response.assert_called_once_with(mock_response) + def test_timeout_setting(self, monkeypatch): + """ + Test that the APIClient uses a custom timeout setting correctly for its requests. + """ + custom_timeout = 1200 # Custom timeout in seconds + client = api_client.APIClient(api_key="test", timeout_seconds=custom_timeout) + assert ( + client.TIMEOUT_SECONDS == custom_timeout + ), "The custom timeout should be set correctly." + + # Mock the requests method to check if the custom timeout is being used + mock_request = MagicMock() + monkeypatch.setattr(requests, "get", mock_request) + + client.get("https://example.com") + mock_request.assert_called_once() + _, kwargs = mock_request.call_args + assert ( + kwargs["timeout"] == custom_timeout + ), "The custom timeout should be used in the request." + def test_create_unsupported(self): """ Test a POST (create) request with a resource that does not support that type or request.