pankajastro commented on code in PR #24038:
URL: https://github.com/apache/airflow/pull/24038#discussion_r886634414


##########
tests/providers/microsoft/azure/hooks/test_asb_message.py:
##########
@@ -0,0 +1,157 @@
+# 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.
+
+import json
+from unittest import mock
+
+import pytest
+from azure.servicebus import ServiceBusClient, ServiceBusMessage, 
ServiceBusMessageBatch
+
+from airflow import AirflowException
+from airflow.models import Connection
+from airflow.providers.microsoft.azure.hooks.asb_message import 
ServiceBusMessageHook
+
+
+class TestServiceBusMessageHook:
+    def setup_class(self) -> None:
+        self.queue_name: str = "test_queue"
+        self.conn_id: str = 'azure_service_bus_default'
+        self.connection_string = (
+            "Endpoint=sb://test-service-bus-provider.servicebus.windows.net/;"
+            "SharedAccessKeyName=Test;SharedAccessKey=1234566acbc"
+        )
+        self.client_id = "test_client_id"
+        self.secret_key = "test_client_secret"
+        self.conn = Connection(
+            conn_id='azure_service_bus_default',
+            conn_type='azure_service_bus',
+            login=self.client_id,
+            password=self.secret_key,
+            extra=json.dumps({'connection_string': self.connection_string}),
+        )
+
+    
@mock.patch("airflow.providers.microsoft.azure.hooks.asb_message.ServiceBusMessageHook.get_connection")
+    def test_get_service_bus_message_conn(self, mock_connection):
+        mock_connection.return_value = self.conn
+        hook = ServiceBusMessageHook(azure_service_bus_conn_id=self.conn_id)
+        assert isinstance(hook.get_conn(), ServiceBusClient)
+
+    
@mock.patch("airflow.providers.microsoft.azure.hooks.asb_message.ServiceBusMessageHook.get_connection")
+    def test_get_conn_value_error(self, mock_connection):
+        mock_connection.return_value = Connection(
+            conn_id='azure_service_bus_default',
+            conn_type='azure_service_bus',
+            login=self.client_id,
+            password=self.secret_key,
+            extra=json.dumps({"connection_string": "test connection"}),
+        )
+        hook = ServiceBusMessageHook(azure_service_bus_conn_id=self.conn_id)
+        with pytest.raises(ValueError):
+            hook.get_conn()
+
+    @pytest.mark.parametrize(
+        "mock_message, mock_batch_flag",
+        [
+            ("Test message", True),
+            ("Test message", False),
+            (["Test message 1", "Test message 2"], True),

Review Comment:
   what about keeping this as a list in setup and reusing that here 
   
   ```
   batch_message = ["Test message 1", "Test message 2"
   ```
   then 
   ```
   @pytest.mark.parametrize(
           "mock_message, mock_batch_flag",
           [
               (batch_message, True),
                (batch_message, False),
          ]
   )
   ```
   
   



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