Move feature flag utility function into superset/__init__.py

This commit is contained in:
Christine Chambers 2019-02-01 13:21:25 -08:00
parent b70a9ae524
commit 19b3753d2c
4 changed files with 18 additions and 36 deletions

View File

@ -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'))

View File

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

View File

@ -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'))

View File

@ -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'))