Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update run_lookml_test to use proper request method #596

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project specifics
logs/
branch_comparison/results/*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 2 additions & 2 deletions spectacles/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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