class ReportImporter(RecordImporter): RECORD_TYPE = M5oCollectionParserTypes.Report ALREADY_EXISTS_ERROR = ReportAlreadyExistsError UPDATABLE_ATTRIBUTES = [ "chart_type", "design", "model", "namespace", "name", "query_payload", ] def __init__(self, *args): super().__init__(*args) self.reports_service = ReportsService(self.project) def _get_record(self, id): return self.reports_service.get_report(id) def _save_record(self, report): return self.reports_service.save_report(report) def _update_record(self, report): return self.reports_service.update_report(report)
def get_report_resource(self, resource_id, today=None): project = Project.find() reports_service = ReportsService(project) report = reports_service.get_report(resource_id) reports_helper = ReportsHelper() return reports_helper.get_report_with_query_results(report, today=today)
def get_dashboard_resource(self, resource_id, today=None): project = Project.find() reports_service = ReportsService(project) dashboards_service = DashboardsService(project) dashboard = dashboards_service.get_dashboard(resource_id) reports = [ reports_service.get_report(report_id) for report_id in dashboard["report_ids"] ] dashboards_helper = DashboardsHelper() reports_with_query_results = dashboards_helper.get_dashboard_reports_with_query_results( reports, today=today) return { "dashboard": dashboard, "reports_with_query_results": reports_with_query_results, }
def test_add_dashboard(self, project, cli_runner): def install(): return cli_runner.invoke( cli, ["add", "dashboard", "dashboard-google-analytics"]) res = install() assert res.exit_code == 0 dashboards_service = DashboardsService(project) dashboards_count = len(dashboards_service.get_dashboards()) assert dashboards_count > 0 reports_service = ReportsService(project) reports_count = len(reports_service.get_reports()) assert reports_count > 0 # Verify that reinstalling doesn't duplicate dashboards and reports res = install() assert res.exit_code == 0 assert len(dashboards_service.get_dashboards()) == dashboards_count assert len(reports_service.get_reports()) == reports_count
def reports_service(): project = Project.find() return ReportsService(project)
def __init__(self, *args): super().__init__(*args) self.reports_service = ReportsService(self.project)