Skip to content

Commit

Permalink
Fix LookerHook serialize missing 1 argument error (#34678)
Browse files Browse the repository at this point in the history
* Fix LookerHook serialize missing 1 argument error

* Add test for LookerHook.get_looker_sdk

* Re-trigger build
  • Loading branch information
cjonesy committed Oct 2, 2023
1 parent 3623b77 commit 562b98a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/providers/google/cloud/hooks/looker.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def get_looker_sdk(self):
return methods40.Looker40SDK(
auth_session.AuthSession(settings, transport, serialize.deserialize40, "4.0"),
serialize.deserialize40,
serialize.serialize,
serialize.serialize40,
transport,
"4.0",
)
Expand Down
25 changes: 25 additions & 0 deletions tests/providers/google/cloud/hooks/test_looker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
from __future__ import annotations

from contextlib import nullcontext as does_not_raise
from unittest import mock

import pytest
Expand All @@ -42,6 +43,30 @@ def setup_method(self):
conn.return_value.extra_dejson = CONN_EXTRA
self.hook = LookerHook(looker_conn_id="test")

@mock.patch("airflow.providers.google.cloud.hooks.looker.requests_transport")
def test_get_looker_sdk(self, _):
"""
Test that get_looker_sdk is setting up the sdk properly
Note: `requests_transport` is mocked so we don't have to test
looker_sdk's functionality, just LookerHook's usage of it
"""
self.hook.get_connection = mock.MagicMock()
sdk = self.hook.get_looker_sdk()

# Attempting to use the instantiated SDK should not throw an error
with does_not_raise():
sdk.get(path="/", structure=None)
sdk.delete(path="/", structure=None)

# The post/patch/put methods call a method internally to serialize
# the body if LookerHook sets the wrong serialize function on init
# there will be TypeErrors thrown
# The body we pass here must be a list, dict, or model.Model
sdk.post(path="/", structure=None, body=[])
sdk.patch(path="/", structure=None, body=[])
sdk.put(path="/", structure=None, body=[])

@mock.patch(HOOK_PATH.format("pdt_build_status"))
def test_wait_for_job(self, mock_pdt_build_status):
# replace pdt_build_status invocation with mock status
Expand Down

0 comments on commit 562b98a

Please sign in to comment.