feat: import/export dashboards via cli (#5991)

* feat: import/export dashboards via cli

* style: fixed lint error

* test: added test for import and export util

* test: removing import test as it is causing integrity issues

Import is a wrapper around exist functionality so we can go ahead without a test or mock the actual db operation using https://docs.python.org/3/library/unittest.mock.html

And validate the wrapper operations only.

* test: remove test data file

* test: removed usage of reserved keyword id
This commit is contained in:
Arpit
2018-10-02 02:32:16 +05:30
committed by Maxime Beauchemin
parent 604524b671
commit 73882945bf
4 changed files with 124 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ import unittest
from sqlalchemy.orm.session import make_transient
from superset import db, utils
from superset import dashboard_import_export_util, db, utils
from superset.connectors.druid.models import (
DruidColumn, DruidDatasource, DruidMetric,
)
@@ -149,6 +149,9 @@ class ImportExportTests(SupersetTestCase):
return db.session.query(SqlaTable).filter_by(
table_name=name).first()
def get_num_dashboards(self):
return db.session.query(models.Dashboard).count()
def assert_dash_equals(self, expected_dash, actual_dash,
check_position=True):
self.assertEquals(expected_dash.slug, actual_dash.slug)
@@ -547,6 +550,34 @@ class ImportExportTests(SupersetTestCase):
self.assert_datasource_equals(
copy_datasource, self.get_datasource(imported_id))
def test_export_dashboards_util(self):
dashboards_json_dump = dashboard_import_export_util.export_dashboards(
db.session)
dashboards_objects = json.loads(
dashboards_json_dump,
object_hook=utils.decode_dashboards,
)
exported_dashboards = dashboards_objects['dashboards']
for dashboard in exported_dashboards:
id_ = dashboard.id
dash = self.get_dash(id_)
self.assert_dash_equals(dash, dashboard)
self.assertEquals(
dash.id, json.loads(
dashboard.json_metadata,
object_hook=utils.decode_dashboards,
)['remote_id'],
)
numDasboards = self.get_num_dashboards()
self.assertEquals(numDasboards, len(exported_dashboards))
exported_tables = dashboards_objects['datasources']
for exported_table in exported_tables:
id_ = exported_table.id
table = self.get_table(id_)
self.assert_table_equals(table, exported_table)
if __name__ == '__main__':
unittest.main()