From 0afd99a7f101bb83e0be7b43bcdd8d3dd23820ba Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 14 Jul 2022 11:40:59 +0100 Subject: [PATCH] fix request call in lookml test method + add test --- .gitignore | 1 + spectacles/client.py | 4 ++-- tests/test_client.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5c5f7606..be383756 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Project specifics logs/ +branch_comparison/results/* # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/spectacles/client.py b/spectacles/client.py index 1c40de98..0156191d 100644 --- a/spectacles/client.py +++ b/spectacles/client.py @@ -133,7 +133,7 @@ def authenticate(self) -> None: @backoff.on_exception( backoff.expo, BACKOFF_EXCEPTIONS, - max_tries=2, + max_tries=3, ) def request(self, method: str, url: str, *args, **kwargs) -> requests.Response: if self.access_token and self.access_token.expired: @@ -558,7 +558,7 @@ def run_lookml_test( params["model"] = model if test is not None: params["test"] = test - response = self.session.get(url=url, params=params, timeout=TIMEOUT_SEC) + response = self.get(url=url, params=params, timeout=TIMEOUT_SEC) try: response.raise_for_status() diff --git a/tests/test_client.py b/tests/test_client.py index d1d24521..25650ed9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -171,3 +171,14 @@ def test_authenticate_should_set_session_headers(mock_post, monkeypatch): mock_post.return_value = mock_post_response client = LookerClient("base_url", "client_id", "client_secret") assert client.session.headers == {"Authorization": "token test_access_token"} + + +@patch( + "spectacles.client.requests.Session.request", + side_effect=requests.exceptions.ReadTimeout, +) +def test_timeout_gets_handled_with_retries(mock_request, looker_client): + with pytest.raises(requests.exceptions.ReadTimeout): + looker_client.run_lookml_test(project="project_name") + + assert mock_request.call_count == 3