feluelle commented on a change in pull request #11015: URL: https://github.com/apache/airflow/pull/11015#discussion_r501621234
########## File path: tests/providers/microsoft/azure/hooks/test_azure_data_factory.py ########## @@ -0,0 +1,440 @@ +# 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 re import A +from unittest.mock import patch + +import pytest +from pytest import fixture + +from airflow.exceptions import AirflowException +from airflow.models.connection import Connection +from airflow.providers.microsoft.azure.hooks.azure_data_factory import AzureDataFactoryHook +from airflow.utils import db + + +DEFAULT_RESOURCE_GROUP = "defaultResourceGroup" +RESOURCE_GROUP = "testResourceGroup" + +DEFAULT_FACTORY = "defaultFactory" +FACTORY = "testFactory" + +MODEL = object() + + +def setup_module(module): + connection = Connection( + conn_id="azure_data_factory_test", + conn_type="azure_data_factory", + login="clientId", + password="clientSecret", + extra=json.dumps( + { + "tenantId": "tenantId", + "subscriptionId": "subscriptionId", + "resourceGroup": DEFAULT_RESOURCE_GROUP, + "factory": DEFAULT_FACTORY, + } + ), + ) + + db.merge_conn(connection) + + +@fixture +def hook(): + with patch("airflow.providers.microsoft.azure.hooks.base_azure.ServicePrincipalCredentials"): + with patch("airflow.providers.microsoft.azure.hooks.azure_data_factory.DataFactoryManagementClient"): + return AzureDataFactoryHook(conn_id="azure_data_factory_test") + + +def test_hook_initialization(hook: AzureDataFactoryHook): + assert hook._resource_group_name == DEFAULT_RESOURCE_GROUP + assert hook._factory_name == DEFAULT_FACTORY + + +def test_targeted_factory(hook: AzureDataFactoryHook): + expected = (RESOURCE_GROUP, FACTORY) + + result = hook._get_targeted_factory(*expected) + + assert result == expected + + +def test_targeted_factory_defaults(hook: AzureDataFactoryHook): + expected = (DEFAULT_RESOURCE_GROUP, DEFAULT_FACTORY) + + result = hook._get_targeted_factory(None, None) + + assert result == expected Review comment: For tests with different input and/or output parameters and basically have the same testing logic [parameterized](https://pypi.org/project/parameterized/) tests is a great tool :) See [this](https://github.com/apache/airflow/blob/9549274d110f689a0bd709db829a4d69e274eed9/tests/providers/google/cloud/operators/test_cloud_build.py#L48-L67) for example. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
