def test_imports_updates_existing_models(self): importer = import_export.Importer(data_source=data_source_factory.create()) importer.import_dashboard(self.user, self.dashboard) self.dashboard['name'] = 'Testing #2' dashboard = importer.import_dashboard(self.user, self.dashboard) self.assertEqual(dashboard.name, self.dashboard['name']) self.assertEquals(models.Dashboard.select().count(), 1)
def test_using_existing_mapping(self): dashboard = dashboard_factory.create() mapping = {'Dashboard': {"1": dashboard.id}} importer = import_export.Importer( object_mapping=mapping, data_source=data_source_factory.create()) imported_dashboard = importer.import_dashboard(self.user, self.dashboard) self.assertEqual(imported_dashboard, dashboard)
def test_imports_dashboard_correctly(self): importer = import_export.Importer(data_source=data_source_factory.create()) dashboard = importer.import_dashboard(self.user, self.dashboard) self.assertIsNotNone(dashboard) self.assertEqual(dashboard.name, self.dashboard['name']) self.assertEqual(dashboard.slug, self.dashboard['slug']) self.assertEqual(dashboard.user, self.user) self.assertEqual(dashboard.widgets.count(), reduce(lambda s, row: s + len(row), self.dashboard['widgets'], 0)) self.assertEqual(models.Visualization.select().count(), dashboard.widgets.count()-1) self.assertEqual(models.Query.select().count(), dashboard.widgets.count()-2)