def test_widget_filters(self): widgets = [{ 'text': 'asdf', 'options': { 'ex': 1 } }, { 'text': 'asdf', 'options': { 'ex': 2 } }, { 'visualization': {}, 'options': { 'ex': 1 } }, { 'visualization': {}, 'options': { 'ex': 2 } }, { 'visualization': {}, 'options': { 'ex': 3 } }] self.assertEqual(len(get_text_widgets(widgets)), 2) self.assertEqual(len(get_visualization_widgets(widgets)), 3)
def test_widget_filters(self) -> None: widgets: List[Dict[str, Any]] = [{ 'text': 'asdf', 'options': { 'ex': 1 } }, { 'text': 'asdf', 'options': { 'ex': 2 } }, { 'visualization': {}, 'options': { 'ex': 1 } }, { 'visualization': {}, 'options': { 'ex': 2 } }, { 'visualization': {}, 'options': { 'ex': 3 } }] self.assertEqual(len(get_text_widgets(widgets)), 2) self.assertEqual(len(get_visualization_widgets(widgets)), 3)
def test_descriptions_from_text(self) -> None: text_widgets = get_text_widgets([ {'text': 'T1'}, {'text': 'T2'} ]) viz_widgets = get_visualization_widgets([ { 'visualization': { 'query': { 'id': 1, 'data_source_id': 1, 'name': 'Q1', 'query': 'n/a' } } }, { 'visualization': { 'query': { 'id': 2, 'data_source_id': 1, 'name': 'Q2', 'query': 'n/a' } } } ]) # both text and viz widgets desc1 = generate_dashboard_description(text_widgets, viz_widgets) self.assertTrue('T1' in desc1) self.assertTrue('T2' in desc1) self.assertTrue('Q1' not in desc1) # only text widgets desc2 = generate_dashboard_description(text_widgets, []) self.assertEqual(desc1, desc2) # only viz widgets desc3 = generate_dashboard_description([], viz_widgets) self.assertTrue('Q1' in desc3) self.assertTrue('Q2' in desc3) # no widgets desc4 = generate_dashboard_description([], []) self.assertTrue('empty' in desc4)
def _get_extract_iter(self) -> Iterator[Any]: while True: record = self._extractor.extract() if not record: break # the end. record = next(self._transformer.transform(record=record), None) if not self._is_published_dashboard(record): continue # filter this one out identity_data = { 'cluster': self._cluster, 'product': RedashDashboardExtractor.PRODUCT, 'dashboard_group_id': str(RedashDashboardExtractor.DASHBOARD_GROUP_ID), 'dashboard_id': str(record['dashboard_id']) } dash_data = { 'dashboard_group': RedashDashboardExtractor.DASHBOARD_GROUP_NAME, 'dashboard_group_url': self._redash_base_url, 'dashboard_name': record['dashboard_name'], 'dashboard_url': f'{self._redash_base_url}/dashboards/{record["dashboard_id"]}', 'created_timestamp': record['created_timestamp'] } dash_data.update(identity_data) widgets = sort_widgets(record['widgets']) text_widgets = get_text_widgets(widgets) viz_widgets = get_visualization_widgets(widgets) # generate a description for this dashboard, since Redash does not have descriptions dash_data['description'] = generate_dashboard_description( text_widgets, viz_widgets) yield DashboardMetadata(**dash_data) last_mod_data = { 'last_modified_timestamp': record['last_modified_timestamp'] } last_mod_data.update(identity_data) yield DashboardLastModifiedTimestamp(**last_mod_data) owner_data = {'email': record['user']['email']} owner_data.update(identity_data) yield DashboardOwner(**owner_data) table_keys = set() for viz in viz_widgets: query_data = { 'query_id': str(viz.query_id), 'query_name': viz.query_name, 'url': self._redash_base_url + viz.query_relative_url, 'query_text': viz.raw_query } query_data.update(identity_data) yield DashboardQuery(**query_data) chart_data = { 'query_id': str(viz.query_id), 'chart_id': str(viz.visualization_id), 'chart_name': viz.visualization_name, 'chart_type': viz.visualization_type, } chart_data.update(identity_data) yield DashboardChart(**chart_data) # if a table parser is provided, retrieve tables from this viz if self._parse_tables: for tbl in self._parse_tables(viz): table_keys.add(tbl.key) if len(table_keys) > 0: yield DashboardTable(table_ids=list(table_keys), **identity_data)
def test_text_widget_props(self) -> None: widget_data = {'text': 'asdf'} widget = get_text_widgets([widget_data])[0] self.assertEqual(widget.text, 'asdf')