gopidesupavan commented on code in PR #39592:
URL: https://github.com/apache/airflow/pull/39592#discussion_r1599409105


##########
tests/providers/amazon/aws/operators/test_comprehend.py:
##########
@@ -0,0 +1,163 @@
+# 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.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Generator
+from unittest import mock
+
+import pytest
+from moto import mock_aws
+
+from airflow.providers.amazon.aws.hooks.comprehend import ComprehendHook
+from airflow.providers.amazon.aws.operators.comprehend import (
+    ComprehendBaseOperator,
+    ComprehendStartPiiEntitiesDetectionJobOperator,
+)
+from airflow.utils.types import NOTSET
+
+if TYPE_CHECKING:
+    from airflow.providers.amazon.aws.hooks.base_aws import BaseAwsConnection
+
+INPUT_DATA_CONFIG = {
+    "S3Uri": "s3://input-data-comprehend/sample_data.txt",
+    "InputFormat": "ONE_DOC_PER_LINE",
+}
+OUTPUT_DATA_CONFIG = {"S3Uri": "s3://output-data-comprehend/redacted_output/"}
+LANGUAGE_CODE = "en"
+ROLE_ARN = "role_arn"
+
+
+class TestComprehendBaseOperator:
+    @pytest.mark.parametrize("aws_conn_id", [None, NOTSET, "aws_test_conn"])
+    @pytest.mark.parametrize("region_name", [None, NOTSET, "ca-central-1"])
+    def test_initialize_comprehend_base_operator(self, aws_conn_id, 
region_name):
+        op_kw = {"aws_conn_id": aws_conn_id, "region_name": region_name}
+        op_kw = {k: v for k, v in op_kw.items() if v is not NOTSET}
+
+        comprehend_base_op = ComprehendBaseOperator(
+            task_id="comprehend_base_operator",
+            input_data_config=INPUT_DATA_CONFIG,
+            output_data_config=OUTPUT_DATA_CONFIG,
+            language_code=LANGUAGE_CODE,
+            data_access_role_arn=ROLE_ARN,
+            **op_kw,
+        )
+
+        assert comprehend_base_op.aws_conn_id == (aws_conn_id if aws_conn_id 
is not NOTSET else "aws_default")
+        assert comprehend_base_op.region_name == (region_name if region_name 
is not NOTSET else None)
+
+    @mock.patch.object(ComprehendBaseOperator, "hook", 
new_callable=mock.PropertyMock)
+    def test_initialize_comprehend_base_operator_hook(self, 
comprehend_base_operator_mock_hook):
+        comprehend_base_op = ComprehendBaseOperator(
+            task_id="comprehend_base_operator",
+            input_data_config=INPUT_DATA_CONFIG,
+            output_data_config=OUTPUT_DATA_CONFIG,
+            language_code=LANGUAGE_CODE,
+            data_access_role_arn=ROLE_ARN,
+        )
+        mocked_hook = mock.MagicMock(name="MockHook")
+        mocked_client = mock.MagicMock(name="MockClient")
+        mocked_hook.conn = mocked_client
+        comprehend_base_operator_mock_hook.return_value = mocked_hook
+        assert comprehend_base_op.client == mocked_client
+        comprehend_base_operator_mock_hook.assert_called_once()
+
+
+class TestComprehendStartPiiEntitiesDetectionJobOperator:
+    JOB_ID = "random-job-id-1234567"
+    MODE = "ONE_DOC_PER_LINE"
+    JOB_NAME = "TEST_START_PII_ENTITIES_DETECTION_JOB-1"
+    DEFAULT_JOB_NAME_STARTS_WITH = "start_pii_entities_detection_job"
+
+    @pytest.fixture
+    def mock_conn(self) -> Generator[BaseAwsConnection, None, None]:
+        with mock.patch.object(ComprehendHook, "conn") as _conn:
+            _conn.start_pii_entities_detection_job.return_value = {"JobId": 
self.JOB_ID}
+            yield _conn
+
+    @pytest.fixture
+    def comprehend_hook(self) -> Generator[ComprehendHook, None, None]:
+        with mock_aws():
+            hook = ComprehendHook(aws_conn_id="aws_default")
+            yield hook
+
+    def setup_method(self):
+        self.operator = ComprehendStartPiiEntitiesDetectionJobOperator(
+            task_id="start_pii_entities_detection_job",
+            input_data_config=INPUT_DATA_CONFIG,
+            output_data_config=OUTPUT_DATA_CONFIG,
+            data_access_role_arn=ROLE_ARN,
+            mode=self.MODE,
+            language_code=LANGUAGE_CODE,
+            start_pii_entities_kwargs={"JobName": self.JOB_NAME},
+        )
+        self.operator.defer = mock.MagicMock()
+
+    def test_init(self):
+        assert self.operator.input_data_config == INPUT_DATA_CONFIG
+        assert self.operator.output_data_config == OUTPUT_DATA_CONFIG
+        assert self.operator.data_access_role_arn == ROLE_ARN
+        assert self.operator.mode == self.MODE
+        assert self.operator.language_code == LANGUAGE_CODE
+        assert self.operator.start_pii_entities_kwargs.get("JobName") == 
self.JOB_NAME
+
+    @pytest.mark.parametrize(
+        "start_pii_entities_kwargs",
+        [
+            pytest.param(

Review Comment:
   Updated now.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to