This is an automated email from the ASF dual-hosted git repository.

husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 562b98a622 Fix LookerHook serialize missing 1 argument error (#34678)
562b98a622 is described below

commit 562b98a6222912d3a3d859ca3881af3f768ba7b5
Author: Charlie Jones <[email protected]>
AuthorDate: Mon Oct 2 15:31:07 2023 -0500

    Fix LookerHook serialize missing 1 argument error (#34678)
    
    * Fix LookerHook serialize missing 1 argument error
    
    * Add test for LookerHook.get_looker_sdk
    
    * Re-trigger build
---
 airflow/providers/google/cloud/hooks/looker.py    |  2 +-
 tests/providers/google/cloud/hooks/test_looker.py | 25 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/google/cloud/hooks/looker.py 
b/airflow/providers/google/cloud/hooks/looker.py
index 616d583221..a1b018a9ed 100644
--- a/airflow/providers/google/cloud/hooks/looker.py
+++ b/airflow/providers/google/cloud/hooks/looker.py
@@ -194,7 +194,7 @@ class LookerHook(BaseHook):
         return methods40.Looker40SDK(
             auth_session.AuthSession(settings, transport, 
serialize.deserialize40, "4.0"),
             serialize.deserialize40,
-            serialize.serialize,
+            serialize.serialize40,
             transport,
             "4.0",
         )
diff --git a/tests/providers/google/cloud/hooks/test_looker.py 
b/tests/providers/google/cloud/hooks/test_looker.py
index 9fd6f74b97..e06c7a31e0 100644
--- a/tests/providers/google/cloud/hooks/test_looker.py
+++ b/tests/providers/google/cloud/hooks/test_looker.py
@@ -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
@@ -42,6 +43,30 @@ class TestLookerHook:
             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

Reply via email to