pankajastro commented on code in PR #24038: URL: https://github.com/apache/airflow/pull/24038#discussion_r886618480
########## tests/providers/microsoft/azure/operators/test_azure_service_queue.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. + +import datetime +import unittest +from unittest import mock + +from azure.servicebus import ServiceBusMessage + +from airflow.models.dag import DAG +from airflow.providers.microsoft.azure.operators.azure_service_bus_queue import ( + AzureServiceBusCreateQueueOperator, + AzureServiceBusDeleteQueueOperator, + AzureServiceBusReceiveMessageOperator, + AzureServiceBusSendMessageOperator, +) + +QUEUE_NAME = "test_queue" +OWNER_NAME = "airflow" +DAG_ID = "test_azure_service_bus_queue" + + +class TestAzureServiceBusCreateQueueOperator(unittest.TestCase): + def setUp(self): + args = {'owner': OWNER_NAME, 'start_date': datetime.datetime(2017, 1, 1)} + self.dag = DAG(DAG_ID, default_args=args) + + def test_init(self): + """ + Test init by creating AzureServiceBusCreateQueueOperator with task id, queue_name and + asserting with value + """ + asb_create_queue_operator = AzureServiceBusCreateQueueOperator( + task_id="asb_create_queue", + queue_name=QUEUE_NAME, + dag=self.dag, + max_delivery_count=10, + dead_lettering_on_message_expiration=True, + enable_batched_operations=True, + ) + assert asb_create_queue_operator.task_id == "asb_create_queue" + assert asb_create_queue_operator.queue_name == QUEUE_NAME + assert asb_create_queue_operator.max_delivery_count == 10 + assert asb_create_queue_operator.dead_lettering_on_message_expiration is True + assert asb_create_queue_operator.enable_batched_operations is True + + asb_create_queue_operator = AzureServiceBusCreateQueueOperator( + task_id="asb_create_queue_test", + queue_name=QUEUE_NAME, + dag=self.dag, Review Comment: same here ########## tests/providers/microsoft/azure/operators/test_azure_service_queue.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. + +import datetime +import unittest +from unittest import mock + +from azure.servicebus import ServiceBusMessage + +from airflow.models.dag import DAG +from airflow.providers.microsoft.azure.operators.azure_service_bus_queue import ( + AzureServiceBusCreateQueueOperator, + AzureServiceBusDeleteQueueOperator, + AzureServiceBusReceiveMessageOperator, + AzureServiceBusSendMessageOperator, +) + +QUEUE_NAME = "test_queue" +OWNER_NAME = "airflow" +DAG_ID = "test_azure_service_bus_queue" + + +class TestAzureServiceBusCreateQueueOperator(unittest.TestCase): + def setUp(self): + args = {'owner': OWNER_NAME, 'start_date': datetime.datetime(2017, 1, 1)} + self.dag = DAG(DAG_ID, default_args=args) + + def test_init(self): + """ + Test init by creating AzureServiceBusCreateQueueOperator with task id, queue_name and + asserting with value + """ + asb_create_queue_operator = AzureServiceBusCreateQueueOperator( + task_id="asb_create_queue", + queue_name=QUEUE_NAME, + dag=self.dag, + max_delivery_count=10, + dead_lettering_on_message_expiration=True, + enable_batched_operations=True, + ) + assert asb_create_queue_operator.task_id == "asb_create_queue" + assert asb_create_queue_operator.queue_name == QUEUE_NAME + assert asb_create_queue_operator.max_delivery_count == 10 + assert asb_create_queue_operator.dead_lettering_on_message_expiration is True + assert asb_create_queue_operator.enable_batched_operations is True + + asb_create_queue_operator = AzureServiceBusCreateQueueOperator( + task_id="asb_create_queue_test", + queue_name=QUEUE_NAME, + dag=self.dag, + max_delivery_count=10, + dead_lettering_on_message_expiration=False, + enable_batched_operations=False, + ) + assert asb_create_queue_operator.task_id == "asb_create_queue_test" + assert asb_create_queue_operator.queue_name == QUEUE_NAME + assert asb_create_queue_operator.max_delivery_count == 10 + assert asb_create_queue_operator.dead_lettering_on_message_expiration is False + assert asb_create_queue_operator.enable_batched_operations is False + + @mock.patch( + "airflow.providers.microsoft.azure.hooks.asb_admin_client.AzureServiceBusAdminClientHook.get_conn" + ) + def test_create_queue(self, mock_get_conn): + """ + Test AzureServiceBusCreateQueueOperator passed with the queue name, + mocking the connection details, hook create_queue function + """ + asb_create_queue_operator = AzureServiceBusCreateQueueOperator( + task_id="asb_create_queue_operator", + queue_name=QUEUE_NAME, + max_delivery_count=10, + dead_lettering_on_message_expiration=True, + enable_batched_operations=True, + dag=self.dag, Review Comment: same here -- 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]
