def test_fetch_reports_by_name(self): owner_id = uuid.uuid1() all_rs = [ Report.insert(owner_id, 'rep%02d' % i) for i in range(10, 20) ] all_rs[:0] = [ Report.insert(owner_id, 'rep%02d' % i) for i in range(10) ] rs = reports.fetch_reports_by_name(owner_id) self.assertEqual(all_rs, rs) rs = reports.fetch_reports_by_name(owner_id, limit=5) self.assertEqual(all_rs[:5], rs) rs = reports.fetch_reports_by_name(owner_id, name_prefix='rep1') self.assertEqual(all_rs[10:], rs) rs = reports.fetch_reports_by_name(owner_id, name_prefix='rep1', after_name='rep15') self.assertEqual(all_rs[16:], rs) rs = reports.fetch_reports_by_name(owner_id, after_name='rep15') self.assertEqual(all_rs[16:], rs) rs = reports.fetch_reports_by_name(owner_id, after_name='x') self.assertFalse(rs) rs = reports.fetch_reports_by_name(uuid.uuid1()) self.assertFalse(rs) rs = reports.fetch_reports_by_name(owner_id, after_name='a', limit=1) self.assertEqual(all_rs[:1], rs)
def test_delete_simple(self): owner_id = uuid.uuid1() r1 = Report.insert(owner_id, 'r1') r1.process_input('1') r2 = Report.insert(owner_id, 'r2') r2.process_input('2') ids = reports.fetch_reports_by_name(owner_id, 'r') self.assertEqual(2, len(ids)) r2.delete() reps = reports.fetch_reports_by_name(owner_id, 'r') self.assertEqual([r1], reps) self.assertIsNone(Report.select(r2.report_id))
def render_recent_reports(): check_access(lambda: auth.access_profile()) report_list = reports.fetch_reports_by_name(auth.logged_owner_id(), limit=RECENT_REPORTS_LIMIT) report_names = [report.report_name for report in report_list] html = get_template_attribute('m.html', 'recent_reports')(report_names) return success(result=dict(html=html))
def autocomplete_report_name(): term = request.get_json()['term'] check_access(lambda: auth.access_profile()) report_list = reports.fetch_reports_by_name(auth.logged_owner_id(), term, None, AUTOCOMPLETE_REPORT_NAME_LIMIT) report_names = [report.report_name for report in report_list] return success(result=dict(data=report_names))
def _report_list(filter_s, last_report_id): if not filter_s: filter_s = None if last_report_id: last_report_name = Report.select(last_report_id).report_name else: last_report_name = None report_list = reports.fetch_reports_by_name(auth.logged_owner_id(), filter_s, last_report_name, REPORTS_PER_PAGE) res = [{'report': report} for report in report_list] # fill latest_instance_dt for report_d in res: report_d['latest_instance_dt'] = None latest_instance_id = report_d['report'].fetch_latest_instance_id() if latest_instance_id: latest_ri = report_d['report'].fetch_single_instance(latest_instance_id) if latest_ri: report_d['latest_instance_dt'] = latest_ri.created return res
def get_reports(): prefix = parse_string(request.args.get('prefix')) last_name = parse_string(request.args.get('lastName')) limit = get_limit() report_list = reports.fetch_reports_by_name(g.owner_id, prefix, last_name, limit) r = ApiResponse(200) r.result = [ OrderedDict([('name', report.report_name), ('href', href('/reports/%s' % report.report_name))]) for report in report_list ] if len(report_list) == limit: r.set_detail( 'next', set_query_param(request.url, 'lastName', report_list[-1]['report_name'])) else: r.set_detail('next', None) return r.get()
def test_delete_with_tiles(self): owner_id = uuid.uuid1() r1 = Report.insert(owner_id, 'r1') r1.process_input('1') r2 = Report.insert(owner_id, 'r2') r2.process_input('2') r3 = Report.insert(owner_id, 'r3') r3.process_input('3') tile_config = { 'series_spec_list': [SeriesSpec(0, -1, { 'op': 'eq', 'args': '0' })], } od = OwnerDashboards(owner_id) od.insert_dashboard('Second') od.insert_dashboard('Third') tile1_1 = Tile.insert(owner_id, r1.report_id, od.dashboards[0].dashboard_id, tile_config) assert tile1_1.get_tile_data()['series_data'] tile2_1 = Tile.insert(owner_id, r2.report_id, od.dashboards[1].dashboard_id, tile_config) assert tile2_1.get_tile_data()['series_data'] tile3_1 = Tile.insert(owner_id, r3.report_id, od.dashboards[2].dashboard_id, tile_config) assert tile3_1.get_tile_data()['series_data'] layouts.place_tile(tile1_1) layouts.place_tile(tile2_1) layouts.place_tile(tile3_1) r2.delete() reps = reports.fetch_reports_by_name(owner_id, '') self.assertEqual([r1, r3], reps) self.assertEqual( 1, len( layouts.Layout.select( owner_id, od.dashboards[0].dashboard_id).layout_dict)) self.assertEqual( 0, len( layouts.Layout.select( owner_id, od.dashboards[1].dashboard_id).layout_dict)) self.assertEqual( 1, len( layouts.Layout.select( owner_id, od.dashboards[2].dashboard_id).layout_dict)) tile1_2 = Tile.insert(owner_id, r1.report_id, od.dashboards[0].dashboard_id, tile_config) tile1_3 = Tile.insert(owner_id, r1.report_id, od.dashboards[1].dashboard_id, tile_config) tile1_4 = Tile.insert(owner_id, r1.report_id, od.dashboards[1].dashboard_id, tile_config) tile1_5 = Tile.insert(owner_id, r1.report_id, od.dashboards[2].dashboard_id, tile_config) layouts.place_tile(tile1_2) layouts.place_tile(tile1_3) layouts.place_tile(tile1_4) layouts.place_tile(tile1_5) r1.delete() self.assertEqual( 0, len( layouts.Layout.select( owner_id, od.dashboards[0].dashboard_id).layout_dict)) self.assertEqual( 0, len( layouts.Layout.select( owner_id, od.dashboards[1].dashboard_id).layout_dict)) self.assertEqual( 1, len( layouts.Layout.select( owner_id, od.dashboards[2].dashboard_id).layout_dict)) reps = reports.fetch_reports_by_name(owner_id, '') self.assertEqual([r3], reps)