shahar1 commented on code in PR #75694:
URL: https://github.com/apache/airflow/pull/75694#discussion_r4409063118


##########
providers/google/tests/unit/google/cloud/links/test_dataproc.py:
##########
@@ -0,0 +1,234 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Tests for Google Cloud Dataproc links.
+
+Expected URLs are fully hard-coded: the path and query parts are never derived 
from the
+constants under test, so a broken or hand-edited ``format_str`` always fails 
the test. The
+``key`` values are asserted as literals too - they are stored in XComs and 
serialized DAGs,
+so values that merely mirror the module constants would not catch a rename.
+"""
+
+from __future__ import annotations
+
+from unittest import mock
+
+import pytest
+
+from airflow.exceptions import AirflowProviderDeprecationWarning
+from airflow.providers.google.cloud.links import dataproc
+from airflow.providers.google.cloud.links.base import BASE_LINK
+from airflow.providers.google.cloud.links.dataproc import (
+    DataprocBatchesListLink,
+    DataprocBatchLink,
+    DataprocClusterLink,
+    DataprocJobLink,
+    DataprocLink,
+    DataprocListLink,
+    DataprocWorkflowLink,
+    DataprocWorkflowTemplateLink,
+)
+
+TEST_PROJECT_ID = "test-project"
+TEST_REGION = "us-central1"
+
+# The legacy links store the whole URL template in the XCom, not just the 
identifiers.
+LEGACY_JOB_URL_TEMPLATE = (
+    
"https://console.cloud.google.com/dataproc/jobs/{resource}?region={region}&project={project_id}";
+)
+LEGACY_BATCHES_URL_TEMPLATE = 
"https://console.cloud.google.com/dataproc/batches?project={project_id}";
+
+
+def _legacy_link_instance_with_warning():
+    with pytest.warns(AirflowProviderDeprecationWarning):
+        return DataprocListLink()
+
+
+class TestDataprocLink:
+    def test_class_attributes(self):
+        assert DataprocLink.key == "conf"
+        assert DataprocLink.name == "Dataproc resource"
+
+    def test_persist(self):
+        mock_context = mock.MagicMock()
+
+        DataprocLink.persist(
+            context=mock_context,
+            url=LEGACY_JOB_URL_TEMPLATE,
+            resource="test-job-1",
+            region=TEST_REGION,
+            project_id=TEST_PROJECT_ID,
+        )
+
+        mock_context["task_instance"].xcom_push.assert_called_once_with(
+            key="conf",
+            value={
+                "region": TEST_REGION,
+                "project_id": TEST_PROJECT_ID,
+                "url": LEGACY_JOB_URL_TEMPLATE,
+                "resource": "test-job-1",
+            },
+        )
+
+    def test_get_link_formats_the_xcom_url(self):
+        link = DataprocLink()
+        conf = {
+            "url": LEGACY_JOB_URL_TEMPLATE,
+            "region": TEST_REGION,
+            "project_id": TEST_PROJECT_ID,
+            "resource": "test-job-1",
+        }
+
+        with 
mock.patch("airflow.providers.google.cloud.links.dataproc.XCom.get_value", 
return_value=conf):
+            result = link.get_link(operator=mock.MagicMock(), 
ti_key=mock.MagicMock())
+
+        assert (
+            result
+            == 
"https://console.cloud.google.com/dataproc/jobs/test-job-1?region=us-central1&project=test-project";
+        )
+
+    def test_get_link_returns_empty_string_when_xcom_missing(self):
+        link = DataprocLink()
+
+        with 
mock.patch("airflow.providers.google.cloud.links.dataproc.XCom.get_value", 
return_value=None):
+            result = link.get_link(operator=mock.MagicMock(), 
ti_key=mock.MagicMock())
+
+        assert result == ""
+
+
+class TestDataprocListLink:
+    def test_instantiation_warns_about_deprecation(self):
+        with pytest.warns(AirflowProviderDeprecationWarning):
+            DataprocListLink()
+
+    def test_class_attributes(self):
+        link = _legacy_link_instance_with_warning()
+        assert link.key == "list_conf"
+        assert link.name == "Dataproc resources"

Review Comment:
   Please drop from this PR all tests that assert on values of attributes like 
the one above, and retain only tests that check for actual behavior.
   See: https://github.com/apache/airflow/pull/74924



-- 
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