From 3190db52469f9d9a338231a9e8e7f333a6fbb638 Mon Sep 17 00:00:00 2001 From: "Agastiya S. Mohammad" <39547572+egibbm@users.noreply.github.com> Date: Wed, 24 Jun 2020 14:15:14 +0700 Subject: [PATCH] [AIRFLOW-9347] Fix QuboleHook unable to add list to tags (#9349) --- airflow/providers/qubole/hooks/qubole.py | 2 +- tests/providers/qubole/hooks/test_qubole.py | 40 +++++++++++++++++++++ tests/test_project_structure.py | 1 - 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/providers/qubole/hooks/test_qubole.py diff --git a/airflow/providers/qubole/hooks/qubole.py b/airflow/providers/qubole/hooks/qubole.py index cdd5cac67a8fa..508ead3f9d5c0 100644 --- a/airflow/providers/qubole/hooks/qubole.py +++ b/airflow/providers/qubole/hooks/qubole.py @@ -254,4 +254,4 @@ def _add_tags(tags, value): if isinstance(value, str): tags.add(value) elif isinstance(value, (list, tuple)): - tags.extend(value) + tags.update(value) diff --git a/tests/providers/qubole/hooks/test_qubole.py b/tests/providers/qubole/hooks/test_qubole.py new file mode 100644 index 0000000000000..a3718010b58d5 --- /dev/null +++ b/tests/providers/qubole/hooks/test_qubole.py @@ -0,0 +1,40 @@ +# +# 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 unittest + +from airflow.providers.qubole.hooks.qubole import QuboleHook + +add_tags = QuboleHook._add_tags + + +class TestQuboleHook(unittest.TestCase): + def test_add_string_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, 'string') + self.assertEqual({'dag_id', 'task_id', 'string'}, tags) + + def test_add_list_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, ['value1', 'value2']) + self.assertEqual({'dag_id', 'task_id', 'value1', 'value2'}, tags) + + def test_add_tuple_to_tags(self): + tags = {'dag_id', 'task_id'} + add_tags(tags, ('value1', 'value2')) + self.assertEqual({'dag_id', 'task_id', 'value1', 'value2'}, tags) diff --git a/tests/test_project_structure.py b/tests/test_project_structure.py index b30fd1a8f825e..13bf962dbe1b0 100644 --- a/tests/test_project_structure.py +++ b/tests/test_project_structure.py @@ -43,7 +43,6 @@ 'tests/providers/jenkins/hooks/test_jenkins.py', 'tests/providers/microsoft/azure/sensors/test_azure_cosmos.py', 'tests/providers/microsoft/mssql/hooks/test_mssql.py', - 'tests/providers/qubole/hooks/test_qubole.py', 'tests/providers/samba/hooks/test_samba.py', 'tests/providers/yandex/hooks/test_yandex.py' }