[utils.py] gathering/refactoring into a "utils/" folder (#6095)

* [utils] gathering/refactoring into a "utils/" folder

Moving current utils.py into utils/core.py and moving other *util*
modules under this new "utils/" as well.

Following steps include eroding at "utils/core.py" and breaking it down
into smaller modules.

* Improve tests

* Make loading examples in scope for tests

* Remove test class attrs examples_loaded and requires_examples
This commit is contained in:
Maxime Beauchemin
2018-10-16 17:59:34 -07:00
committed by Beto Dealmeida
parent af0ffa44ab
commit bbfd69a138
47 changed files with 227 additions and 179 deletions

View File

@@ -12,9 +12,10 @@ import werkzeug.serving
import yaml
from superset import (
app, dashboard_import_export_util, data, db,
dict_import_export_util, security_manager, utils,
app, data, db, security_manager,
)
from superset.utils import (
core as utils, dashboard_import_export, dict_import_export)
config = app.config
celery_app = utils.get_celery_app(config)
@@ -241,7 +242,7 @@ def import_dashboards(path, recursive=False):
logging.info('Importing dashboard from file %s', f)
try:
with f.open() as data_stream:
dashboard_import_export_util.import_dashboards(
dashboard_import_export.import_dashboards(
db.session, data_stream)
except Exception as e:
logging.error('Error when importing dashboard from file %s', f)
@@ -257,7 +258,7 @@ def import_dashboards(path, recursive=False):
help='Print JSON to stdout')
def export_dashboards(print_stdout, dashboard_file):
"""Export dashboards to JSON"""
data = dashboard_import_export_util.export_dashboards(db.session)
data = dashboard_import_export.export_dashboards(db.session)
if print_stdout or not dashboard_file:
print(data)
if dashboard_file:
@@ -296,7 +297,7 @@ def import_datasources(path, sync, recursive=False):
logging.info('Importing datasources from file %s', f)
try:
with f.open() as data_stream:
dict_import_export_util.import_from_dict(
dict_import_export.import_from_dict(
db.session,
yaml.safe_load(data_stream),
sync=sync_array)
@@ -321,7 +322,7 @@ def import_datasources(path, sync, recursive=False):
def export_datasources(print_stdout, datasource_file,
back_references, include_defaults):
"""Export datasources to YAML"""
data = dict_import_export_util.export_to_dict(
data = dict_import_export.export_to_dict(
session=db.session,
recursive=True,
back_references=back_references,
@@ -340,7 +341,7 @@ def export_datasources(print_stdout, datasource_file,
help='Include parent back references')
def export_datasource_schema(back_references):
"""Export datasource YAML schema to stdout"""
data = dict_import_export_util.export_schema_to_dict(
data = dict_import_export.export_schema_to_dict(
back_references=back_references)
yaml.safe_dump(data, stdout, default_flow_style=False)
@@ -416,6 +417,7 @@ def load_test_users():
Syncs permissions for those users/roles
"""
print(Fore.GREEN + 'Loading a set of users for unit tests')
load_test_users_run()