From 19b3753d2c4dd6826f73feeb9db253edf9761c28 Mon Sep 17 00:00:00 2001 From: Christine Chambers Date: Fri, 1 Feb 2019 13:21:25 -0800 Subject: [PATCH] Move feature flag utility function into superset/__init__.py --- superset/__init__.py | 8 ++++++++ superset/utils/feature_flags.py | 25 ------------------------- tests/base_tests.py | 12 ++++++++++-- tests/utils_tests.py | 9 --------- 4 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 superset/utils/feature_flags.py diff --git a/superset/__init__.py b/superset/__init__.py index 82d75761e..500bcaa85 100644 --- a/superset/__init__.py +++ b/superset/__init__.py @@ -212,6 +212,14 @@ results_backend = app.config.get('RESULTS_BACKEND') feature_flags = app.config.get('DEFAULT_FEATURE_FLAGS') feature_flags.update(app.config.get('FEATURE_FLAGS') or {}) + +def is_feature_enabled(feature): + """ + Utility function for checking whether a feature is turned on + """ + return feature_flags.get(feature) + + # Registering sources module_datasource_map = app.config.get('DEFAULT_MODULE_DS_MAP') module_datasource_map.update(app.config.get('ADDITIONAL_MODULE_DS_MAP')) diff --git a/superset/utils/feature_flags.py b/superset/utils/feature_flags.py deleted file mode 100644 index cac9d8023..000000000 --- a/superset/utils/feature_flags.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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. -# pylint: disable=C,R,W -from superset import feature_flags - - -def is_feature_enabled(feature): - """ - Utility function for checking whether a feature is turned on - """ - return feature_flags.get(feature) diff --git a/tests/base_tests.py b/tests/base_tests.py index f3029c020..1f3b4c5a9 100644 --- a/tests/base_tests.py +++ b/tests/base_tests.py @@ -19,10 +19,10 @@ import json import unittest from flask_appbuilder.security.sqla import models as ab_models -from mock import Mock +from mock import Mock, patch import pandas as pd -from superset import app, db, security_manager +from superset import app, db, is_feature_enabled, security_manager from superset.connectors.druid.models import DruidCluster, DruidDatasource from superset.connectors.sqla.models import SqlaTable from superset.models import core as models @@ -185,3 +185,11 @@ class SupersetTestCase(unittest.TestCase): if raise_on_error and 'error' in resp: raise Exception('run_sql failed') return resp + + @patch.dict('superset.feature_flags', {'FOO': True}, clear=True) + def test_existing_feature_flags(self): + self.assertTrue(is_feature_enabled('FOO')) + + @patch.dict('superset.feature_flags', {}, clear=True) + def test_nonexistent_feature_flags(self): + self.assertFalse(is_feature_enabled('FOO')) diff --git a/tests/utils_tests.py b/tests/utils_tests.py index fbee59fe5..587e07fc8 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -39,7 +39,6 @@ from superset.utils.core import ( zlib_compress, zlib_decompress_to_string, ) -from superset.utils.feature_flags import is_feature_enabled def mock_parse_human_datetime(s): @@ -757,11 +756,3 @@ class UtilsTestCase(unittest.TestCase): } convert_legacy_filters_into_adhoc(form_data) self.assertEquals(form_data, expected) - - @patch.dict('superset.feature_flags', {'FOO': True}, clear=True) - def test_existing_feature_flags(self): - self.assertTrue(is_feature_enabled('FOO')) - - @patch.dict('superset.feature_flags', {}, clear=True) - def test_nonexistent_feature_flags(self): - self.assertFalse(is_feature_enabled('FOO'))