Copilot commented on code in PR #64591:
URL: https://github.com/apache/airflow/pull/64591#discussion_r3025323103


##########
providers/zendesk/tests/unit/zendesk/hooks/test_zendesk.py:
##########
@@ -83,3 +83,32 @@ def test_delete_tickets(self):
         with patch.object(zenpy_client.tickets, "delete") as search_mock:
             self.hook.delete_tickets(ticket, extra_parameter="extra_parameter")
             search_mock.assert_called_once_with(ticket, 
extra_parameter="extra_parameter")
+
+    def test_hook_init_with_token_flag(self):
+        conn_id = "zendesk_token_flag"
+        conn = Connection(
+            conn_id=conn_id,
+            conn_type="zendesk",
+            host="yoursubdomain.zendesk.com",
+            login="[email protected]",
+            password="my_api_token",
+            extra={"use_token": True},
+        )
+        with 
patch("airflow.providers.zendesk.hooks.zendesk.ZendeskHook.get_connection", 
return_value=conn):
+            hook = ZendeskHook(zendesk_conn_id=conn_id)
+            zenpy_client = hook.get_conn()
+            assert zenpy_client.users.session.auth == ("[email protected]/token", 
"my_api_token")
+
+    def test_hook_init_with_direct_token(self):
+        conn_id = "zendesk_direct_token"
+        conn = Connection(
+            conn_id=conn_id,
+            conn_type="zendesk",
+            host="yoursubdomain.zendesk.com",
+            login="[email protected]",
+            extra={"token": "direct_token"},
+        )
+        with 
patch("airflow.providers.zendesk.hooks.zendesk.ZendeskHook.get_connection", 
return_value=conn):
+            hook = ZendeskHook(zendesk_conn_id=conn_id)
+            zenpy_client = hook.get_conn()
+            assert zenpy_client.users.session.auth == ("[email protected]/token", 
"direct_token")

Review Comment:
   New auth branch for `oauth_token` in `ZendeskHook._init_conn()` is not 
covered by unit tests. Please add a test case that builds a Connection with 
`extra={"oauth_token": ...}` and asserts that the Zenpy client is initialized 
with OAuth (and does not fall back to password/token basic auth).



##########
providers/zendesk/src/airflow/providers/zendesk/hooks/zendesk.py:
##########
@@ -74,7 +74,22 @@ def _init_conn(self) -> tuple[Zenpy, str]:
                 dot_splitted_string = conn.host.rsplit(".", 2)
                 subdomain = dot_splitted_string[0]
                 domain = ".".join(dot_splitted_string[1:])
-        return Zenpy(domain=domain, subdomain=subdomain, email=conn.login, 
password=conn.password), url
+        kwargs = {
+            "domain": domain,
+            "subdomain": subdomain,
+            "email": conn.login,
+        }
+        extra = conn.extra_dejson
+        if extra.get("use_token"):
+            kwargs["token"] = conn.password
+        elif extra.get("token"):
+            kwargs["token"] = extra.get("token")
+        elif extra.get("oauth_token"):
+            kwargs["oauth_token"] = extra.get("oauth_token")
+        else:
+            kwargs["password"] = conn.password

Review Comment:
   `_init_conn()` now supports multiple authentication modes via connection 
extras (`use_token`, `token`, `oauth_token`) with a specific precedence order. 
Please document these supported extra keys (and precedence) in the `_init_conn` 
docstring or inline comments so users know how to configure the connection in 
the UI.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to