superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnbod...@apache.org
Subject [incubator-superset] branch master updated: Moving get_main_db out of tests and into superset utils (#5864)
Date Wed, 12 Sep 2018 05:50:17 GMT
This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 657993d  Moving get_main_db out of tests and into superset utils (#5864)
657993d is described below

commit 657993d6098d01bea0bf4eb3fcc4c663578c5df1
Author: michellethomas <michelle.q.thomas@gmail.com>
AuthorDate: Tue Sep 11 22:50:14 2018 -0700

    Moving get_main_db out of tests and into superset utils (#5864)
---
 superset/cli.py                   |  3 +--
 superset/utils.py                 | 14 ++++++++++----
 tests/base_tests.py               |  2 +-
 tests/celery_tests.py             |  2 +-
 tests/core_tests.py               |  2 +-
 tests/dict_import_export_tests.py |  2 +-
 tests/model_tests.py              |  2 +-
 tests/sqllab_tests.py             |  2 +-
 tests/utils.py                    | 11 -----------
 9 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/superset/cli.py b/superset/cli.py
index 68e3de7..6183601 100755
--- a/superset/cli.py
+++ b/superset/cli.py
@@ -20,7 +20,6 @@ import yaml
 from superset import (
     app, data, db, dict_import_export_util, security_manager, utils,
 )
-from tests.utils import get_main_database
 
 config = app.config
 celery_app = utils.get_celery_app(config)
@@ -390,7 +389,7 @@ def load_test_users_run():
         for perm in security_manager.find_role('Gamma').permissions:
             security_manager.add_permission_role(gamma_sqllab_role, perm)
         utils.get_or_create_main_db()
-        db_perm = get_main_database(security_manager.get_session).perm
+        db_perm = utils.get_main_database(security_manager.get_session).perm
         security_manager.merge_perm('database_access', db_perm)
         db_pvm = security_manager.find_permission_view_menu(
             view_menu_name=db_perm, permission_name='database_access')
diff --git a/superset/utils.py b/superset/utils.py
index 96c1f13..e4a57f2 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -836,10 +836,7 @@ def get_or_create_main_db():
     from superset.models import core as models
 
     logging.info('Creating database reference')
-    dbobj = (
-        db.session.query(models.Database)
-        .filter_by(database_name='main')
-        .first())
+    dbobj = get_main_database(db.session)
     if not dbobj:
         dbobj = models.Database(database_name='main')
     dbobj.set_sqlalchemy_uri(conf.get('SQLALCHEMY_DATABASE_URI'))
@@ -850,6 +847,15 @@ def get_or_create_main_db():
     return dbobj
 
 
+def get_main_database(session):
+    from superset.models import core as models
+    return (
+        session.query(models.Database)
+        .filter_by(database_name='main')
+        .first()
+    )
+
+
 def is_adhoc_metric(metric):
     return (
         isinstance(metric, dict) and
diff --git a/tests/base_tests.py b/tests/base_tests.py
index f89aaf7..051e7c4 100644
--- a/tests/base_tests.py
+++ b/tests/base_tests.py
@@ -18,7 +18,7 @@ from superset import app, cli, db, security_manager
 from superset.connectors.druid.models import DruidCluster, DruidDatasource
 from superset.connectors.sqla.models import SqlaTable
 from superset.models import core as models
-from .utils import get_main_database
+from superset.utils import get_main_database
 
 
 BASE_DIR = app.config.get('BASE_DIR')
diff --git a/tests/celery_tests.py b/tests/celery_tests.py
index 7542abe..58302db 100644
--- a/tests/celery_tests.py
+++ b/tests/celery_tests.py
@@ -18,8 +18,8 @@ from superset import app, cli, db, security_manager
 from superset.models.helpers import QueryStatus
 from superset.models.sql_lab import Query
 from superset.sql_parse import SupersetQuery
+from superset.utils import get_main_database
 from .base_tests import SupersetTestCase
-from .utils import get_main_database
 
 
 BASE_DIR = app.config.get('BASE_DIR')
diff --git a/tests/core_tests.py b/tests/core_tests.py
index d4aeece..4f1e71a 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -27,9 +27,9 @@ from superset.connectors.sqla.models import SqlaTable
 from superset.db_engine_specs import BaseEngineSpec
 from superset.models import core as models
 from superset.models.sql_lab import Query
+from superset.utils import get_main_database
 from superset.views.core import DatabaseView
 from .base_tests import SupersetTestCase
-from .utils import get_main_database
 
 
 class CoreTests(SupersetTestCase):
diff --git a/tests/dict_import_export_tests.py b/tests/dict_import_export_tests.py
index 21a46ee..c96ce63 100644
--- a/tests/dict_import_export_tests.py
+++ b/tests/dict_import_export_tests.py
@@ -15,8 +15,8 @@ from superset.connectors.druid.models import (
     DruidColumn, DruidDatasource, DruidMetric,
 )
 from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
+from superset.utils import get_main_database
 from .base_tests import SupersetTestCase
-from .utils import get_main_database
 
 DBREF = 'dict_import__export_test'
 NAME_PREFIX = 'dict_'
diff --git a/tests/model_tests.py b/tests/model_tests.py
index 565791a..1a78567 100644
--- a/tests/model_tests.py
+++ b/tests/model_tests.py
@@ -10,8 +10,8 @@ from sqlalchemy.engine.url import make_url
 
 from superset import app, db
 from superset.models.core import Database
+from superset.utils import get_main_database
 from .base_tests import SupersetTestCase
-from .utils import get_main_database
 
 
 class DatabaseModelTestCase(SupersetTestCase):
diff --git a/tests/sqllab_tests.py b/tests/sqllab_tests.py
index 1159c4e..a39643a 100644
--- a/tests/sqllab_tests.py
+++ b/tests/sqllab_tests.py
@@ -15,8 +15,8 @@ from superset import db, security_manager, utils
 from superset.dataframe import SupersetDataFrame
 from superset.db_engine_specs import BaseEngineSpec
 from superset.models.sql_lab import Query
+from superset.utils import get_main_database
 from .base_tests import SupersetTestCase
-from .utils import get_main_database
 
 
 class SqlLabTests(SupersetTestCase):
diff --git a/tests/utils.py b/tests/utils.py
index a0ab456..d1a5adb 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -7,20 +7,9 @@ from __future__ import unicode_literals
 import json
 from os import path
 
-from superset import db
-from superset.models import core as models
-
 FIXTURES_DIR = 'tests/fixtures'
 
 
 def load_fixture(fixture_file_name):
     with open(path.join(FIXTURES_DIR, fixture_file_name)) as fixture_file:
         return json.load(fixture_file)
-
-
-def get_main_database(session):
-    return (
-        db.session.query(models.Database)
-        .filter_by(database_name='main')
-        .first()
-    )


Mime
View raw message