Esempio n. 1
0
    def test_get_tile_config(self):
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['ip:192.168.1.1'])
            }
        }
        owner_id = uuid.uuid1()
        report_id = report_data('points').report.report_id
        dashboard_id = report_data('points').dashboard_id

        tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
        res = tile.get_tile_config()
        self.assertDictContainsSubset(dictwithout(tile_config, 'tile_options'),
                                      dictwithout(res, 'tile_options'))
        self.assertDictContainsSubset(tile_config['tile_options'],
                                      res['tile_options'])
Esempio n. 2
0
    def test_single__text_single_drawer(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        tile_config = {
            'tw_type':
            'Single',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'drawer_type':
                'TextSingleDrawer'
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                           tile_config)
        layouts.place_tile(tile)
        self.assertEqual(tile.tile_options['drawer_type'], 'TextSingleDrawer')

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        pr = rd.report.process_input(json.dumps(d),
                                     tags=['ip:192.168.1.1'],
                                     extra_ri_data={'ed': 88})

        tile = rd.only_tile_from_layout()
        data = tile.get_new_tile_data(pr.report_instance.report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual([], data['series_data'][1]['data_points'])

        data = tile.get_new_tile_data(rd.instances[-1].report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        data = tile.get_new_tile_data(rd.instances[-3].report_instance_id)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        data = tile.get_new_tile_data(None)
        self.assertEqual(2, len(data['series_data']))
        self.assertEqual([], data['series_data'][0]['data_points'])
        self.assertEqual(128, data['series_data'][1]['data_points'][0].value)

        return tile
Esempio n. 3
0
    def test_delete(self):
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['ip:192.168.1.1'])
            }
        }
        owner_id = uuid.uuid1()
        report_id = report_data('points').report.report_id
        dashboard_id = report_data('points').dashboard_id
        tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
        place_tile(tile)
        self.assertTrue(self._select_tpcreator_rows(tile))
        self.assertTrue(self._select_sscs_rows(tile))

        tile = tile.select(tile.dashboard_id, tile.tile_id)
        detach_tile(tile)
        deleted_tile = tile.select(tile.dashboard_id, tile.tile_id)
        self.assertIsNone(deleted_tile)
Esempio n. 4
0
    def test_range__chart_range_drawer(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        tile_config = {
            'tw_type':
            'Range',
            'tags': ['ip:192.168.1.1'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'Points by user',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        tile = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                           tile_config)
        layouts.place_tile(tile)
        self.assertEqual(tile.tile_options['drawer_type'], 'ChartRangeDrawer')

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d),
                                tags=['ip:192.168.1.1'],
                                extra_ri_data={'ed': 88})

        tile = rd.only_tile_from_layout()
        data = tile.get_tile_data()

        self.assertEqual('points (monique, robert3)',
                         data['generated_tile_title'])
        self.assertEqual('[ip:192.168.1.1]',
                         data['generated_tile_title_postfix'])
        self.assertEqual(0, data['extra_options']['y_axis_min'])
        self.assertIsInstance(data['fetched_from_dt'], datetime.datetime)
        self.assertIsInstance(data['fetched_to_dt'], datetime.datetime)
        self.assertEqual({'ed': 88}, data['latest_extra_ri_data'])
        self.assertEqual('points', data['report_name'])
        self.assertEqual(2, len(data['series_data']))
        for sd in data['series_data']:
            self.assertIsInstance(sd['series_id'], uuid.UUID)
            self.assertEqual('points', data['common_header'])
            self.assertTrue(sd['data_points'])
            for dp in sd['data_points']:
                self.assertIsInstance(dp, tilewidgets.DataPoint)
        self.assertEqual(mqeconfig.DEFAULT_COLORS[:2], data['combined_colors'])
        self.assertEqual('points', data['common_header'])

        return tile
Esempio n. 5
0
    def test_expire_tiles_without_data(self):
        rd1 = new_report_data('points')
        rd2 = new_report_data('points')

        tile_config_1 = {
            'tw_type':
            'Range',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back': 86400,
            }
        }
        tile1 = tiles.Tile.insert(rd1.owner_id, rd1.report.report_id,
                                  rd1.dashboard_id, tile_config_1)
        place_tile(tile1)
        self.assertTrue(tile1.get_tile_data()['series_data'][0]['data_points'])

        tile_config_2 = {
            'tw_type':
            'Range',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john20'])),
            ],
            'tile_options': {
                'seconds_back': 86400,
            }
        }
        tile2 = tiles.Tile.insert(rd2.owner_id, rd2.report.report_id,
                                  rd2.dashboard_id, tile_config_2)
        place_tile(tile2)
        self.assertFalse(
            tile2.get_tile_data()['series_data'][0]['data_points'])
        res = tiles.expire_tiles_without_data([tile1, tile2],
                                              3600,
                                              Layout.select(
                                                  rd1.owner_id,
                                                  rd1.dashboard_id).layout_id,
                                              optimize_check=True)
        self.assertIsNone(res)

        time.sleep(0.5)
        rd2.report.process_input('0')

        res = tiles.expire_tiles_without_data([tile1, tile2],
                                              0.5,
                                              Layout.select(
                                                  rd1.owner_id,
                                                  rd1.dashboard_id).layout_id,
                                              optimize_check=True)
        self.assertTrue(res)
        self.assertFalse(Tile.select(rd1.dashboard_id, tile1.tile_id))
        self.assertTrue(Tile.select(rd2.dashboard_id, tile2.tile_id))
Esempio n. 6
0
    def test_filling_default_options(self):
        rd = new_report_data('points', tags=['ip:192.168.1.1'])

        for tw_type in ('Range', 'Single'):
            ss1 = dataseries.SeriesSpec(2, 0, dict(op='eq', args=['mike']))
            ss1.promote_colnos_to_headers(rd.instances[-1])
            ss1.set_name('mikepoints')
            tile_config = {
                'tw_type':
                tw_type,
                'tags': ['ip:192.168.1.1'],
                'series_spec_list': [
                    ss1,
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                ],
                'tile_options': {
                    'colors': ['red', 'blue', 'pink', 'cyan'],
                    'seconds_back':
                    600,
                    'tile_title':
                    'Points by user',
                    'sscs':
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                }
            }

            tile = Tile.insert(rd.owner_id, rd.report.report_id,
                               rd.dashboard_id, tile_config)
            dataseries.update_default_options(tile)
            data = tile.get_tile_data()
            self.assertEqual(['red', 'blue'], data['combined_colors'])

            tile_config2 = {
                'tw_type':
                tw_type,
                'tags': ['ip:192.168.1.1'],
                'series_spec_list': [
                    dataseries.guess_series_spec(rd.report, rd.instances[-1],
                                                 1, 2),
                    dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                     args=['monique'])),
                ],
            }
            self.assertEqual('mikepoints',
                             tile_config2['series_spec_list'][0].name())
            tile2 = Tile.insert(rd.owner_id, rd.report.report_id,
                                rd.dashboard_id, tile_config)
            dataseries.update_default_options(tile2)
            data2 = tile2.get_tile_data()
            self.assertEqual('mikepoints', data2['series_data'][0]['name'])
            self.assertEqual(['red', 'blue'], data2['combined_colors'])
Esempio n. 7
0
    def test_layout_sorting(self):
        rd = new_report_data('points', ['p1:10'])
        tile_config = {
            'tw_type':
            'Range',
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                600,
                'tile_title':
                'm0',
                'sscs':
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])

        master_tile = Tile.insert(rd.owner_id, rd.report.report_id,
                                  rd.dashboard_id, tile_config)
        layouts.place_tile(master_tile)

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        nums = [30, 20, 12, 11, 40, 98]
        for num in nums:
            rd.report.process_input(json.dumps(d), tags=['p1:%s' % num])

        ld = rd.layout()
        self.assertEqual(len(nums) + 1, len(ld.layout_dict.keys()))
        self.assertEqual(
            len(nums) + 1, len(ld.layout_props['by_tile_id'].keys()))

        layout_items = sorted(ld.layout_dict.items(),
                              key=lambda (tile_id, vo): (vo['y'], vo['x']))

        layout_tags = [
            ld.layout_props['by_tile_id'][tile_id]['tags'][0]
            for (tile_id, vo) in layout_items
        ]
        expected_tags = ['p1:10'] + sorted(['p1:%s' % num for num in nums])
        self.assertEqual(set(expected_tags), set(layout_tags))
        self.assertEqual(expected_tags, layout_tags)
Esempio n. 8
0
    def test_get_dashboards_by_report_id(self):
        od = self.test_inserting()

        res = od.get_dashboards_by_report_id()
        self.assertEqual({}, res)

        r = Report.insert(od.owner_id, 'r')
        r2 = Report.insert(od.owner_id, 'r2')
        r3 = Report.insert(od.owner_id, 'r3')
        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r.report_id, od.dashboards[0].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r2.report_id, od.dashboards[0].dashboard_id, tile_config))
        place_tile(Tile.insert(od.owner_id, r3.report_id, od.dashboards[1].dashboard_id, tile_config))

        res = od.get_dashboards_by_report_id()
        self.assertEqual(3, len(res))
        self.assertEqual([od.dashboards[0], od.dashboards[3]], res[r.report_id])
        self.assertEqual([od.dashboards[0]], res[r2.report_id])
        self.assertEqual([od.dashboards[1]], res[r3.report_id])
Esempio n. 9
0
def render_empty_series_spec():
    report_id = request.get_json()['report_id']
    report_instance_id = request.get_json()['report_instance_id']

    check_access(lambda: auth.access_report_instances(report_id))

    report = Report.select(report_id)
    
    report_instance = report.fetch_single_instance(report_instance_id)
    if report_instance.table.num_columns > 1:
        series_spec = dataseries.SeriesSpec(0, 0, {'op': 'eq', 'args': []})
    else:
        series_spec = dataseries.SeriesSpec(0, -1, {'op': 'eq', 'args': ['0']})
    series_spec.set_name('')
    series_spec_html = get_template_attribute('m.html', 'series_spec')(series_spec, report_instance)
    return success(result=dict(series_spec_html=series_spec_html))
Esempio n. 10
0
    def test_select_multi(self):
        owner_id = uuid.uuid1()

        d_id1 = uuid.uuid1()
        d_id2 = uuid.uuid1()
        r = Report.insert(owner_id, 'r')

        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual([], res)

        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        t1 = Tile.insert(owner_id, r.report_id, d_id1, tile_config)
        place_tile(t1)

        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual(1, len(res))
        self.assertEqual(
            Layout.select(owner_id, d_id1).layout_id, res[0].layout_id)

        t2 = Tile.insert(owner_id, r.report_id, d_id2, tile_config)
        place_tile(t2)
        res = Layout.select_multi(owner_id, [d_id1, d_id2])
        self.assertEqual(2, len(res))
        self.assertEqual(
            Layout.select(owner_id, d_id1).layout_id, res[0].layout_id)
        self.assertEqual(
            Layout.select(owner_id, d_id2).layout_id, res[1].layout_id)
Esempio n. 11
0
    def test_promote_first_as_master_losing_sscreated(self):
        rd = ReportData('r')

        ss = dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0']))
        tile_config1 = {
            'series_spec_list': [ss],
            'tags': ['p1:10'],
            'tile_options': {
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p1:10']),
                'sscs': ss
            }
        }

        tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config1)
        place_tile(tile1)

        ri1 = rd.report.process_input('1\n2\n',
                                      tags=['p1:9'],
                                      handle_tpcreator=False,
                                      handle_sscreator=False).report_instance
        ri2 = rd.report.process_input('1\n2\n3\n',
                                      tags=['p1:12'],
                                      handle_tpcreator=False,
                                      handle_sscreator=False).report_instance

        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri1,
                                   make_first_master=False)
        sscreator.handle_sscreator(rd.owner_id, rd.report_id, ri1)
        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri2,
                                   make_first_master=False)
        sscreator.handle_sscreator(rd.owner_id, rd.report_id, ri2)

        self.assertEqual(3, len(rd.layout().layout_dict))
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))

        ri3 = rd.report.process_input('1\n2\n3\n',
                                      tags=['p1:13'],
                                      handle_tpcreator=False).report_instance
        tpcreator.handle_tpcreator(rd.owner_id,
                                   rd.report_id,
                                   ri3,
                                   make_first_master=True)

        self.assertEqual(4, len(rd.layout().layout_dict))
        master_tile = rd.get_tile_by_tags(['p1:9'])
        self.assertTrue(master_tile.is_master_tile())
        self.assertEqual(master_tile.tile_id,
                         rd.get_tile_by_tags(['p1:12']).get_master_tile_id())
        self.assertEqual(3, len(rd.get_tile_by_tags(['p1:12']).series_specs()))

        self.assertEqual(['0', '1', '2'], [
            ss.params['filtering_expr']['args'][0]
            for ss in rd.get_tile_by_tags(['p1:12']).series_specs()
        ])
Esempio n. 12
0
    def test_series_values_after_report_instance_deletion_multiple_days(self):
        owner_id = uuid.uuid1()
        r = reports.Report.insert(owner_id, 'rname')

        sd_id = dataseries.SeriesDef.select_id_or_insert(
            r.report_id, [],
            dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': ['0']
            }))
        sd = dataseries.SeriesDef.select(r.report_id, [], sd_id)

        r.process_input('1', created=utcnow() - timedelta(days=10))
        r.process_input('2', created=utcnow() - timedelta(days=5))

        values = dataseries.get_series_values(sd, r,
                                              utcnow() - timedelta(days=11),
                                              utcnow())
        self.assertEqual(2, len(values))

        r.delete_single_instance(r.fetch_instances()[1].report_instance_id)

        inst = r.fetch_instances()
        self.assertEqual(1, len(inst))
        self.assertEqual('1', inst[0].input_string)

        sd = dataseries.SeriesDef.select(r.report_id, [], sd_id)
        values = dataseries.get_series_values(sd, r,
                                              utcnow() - timedelta(days=11),
                                              utcnow())
        self.assertEqual(1, len(values))
        self.assertEqual(1, values[0].value)
Esempio n. 13
0
    def test_repack_performance(self):
        rd = ReportData('r')

        tile_config = {
            'tags': ['p1:1'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:1',
                    'prefix': 'p1:'
                }],
            }
        }
        tile = Tile.insert(rd.owner_id, rd.report_id, rd.dashboard_id,
                           tile_config)
        place_tile(tile)

        start = time()
        for i in range(1, 201):
            rd.report.process_input('1', tags=['p1:%s' % i])
        print 'Tiles created in %.1f' % ((time() - start) * 1000)

        start = time()
        layouts.repack(rd.owner_id, rd.dashboard_id)
        print 'Single repack in %.1f' % ((time() - start) * 1000)
Esempio n. 14
0
    def test_layout_sorting_complex_tag_names_2(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        rep = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tags': ['server:web.1'],
            'series_spec_list':
            [dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': '0'
            })],
            'tile_options': {
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['server:web.1'])
            }
        }
        master_tile = Tile.insert(owner_id, rep.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        rep.process_input('1', tags=['server:worker.1'])
        rep.process_input('1', tags=['server:web.2'])

        layout = layouts.Layout.select(owner_id, dashboard_id)
        tiles = sorted(
            layout.tile_dict,
            key=lambda tile:
            (layout.tile_dict[tile]['y'], layout.tile_dict[tile]['x']))
        tags_lists = [tile.tags for tile in tiles]
        self.assertEqual(
            [['server:web.1'], ['server:web.2'], ['server:worker.1']],
            tags_lists)
Esempio n. 15
0
 def test_sscs_creation(self):
     tile = self.test_insert(tile_options_ext={
         'sscs':
         dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique']))
     })
     place_tile(tile)
     self.assertTrue(self._select_sscs_rows(tile))
Esempio n. 16
0
    def test_creating_ri_reversed_and_fetching_series_values_in_the_middle(
            self):
        owner_id = uuid.uuid1()
        r = reports.Report.insert(owner_id, 'nums')
        sd_id = dataseries.SeriesDef.insert(
            r.report_id, [],
            dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': ['0']
            }))
        sd = dataseries.SeriesDef.select(r.report_id, [], sd_id)

        for i in reversed(xrange(10, 20)):
            r.process_input(str(i), created=utcnow() - timedelta(days=i))
        expected = list(reversed(range(10, 20)))
        values = [
            sv.value for sv in dataseries.get_series_values(
                sd, r,
                utcnow() - timedelta(days=100), utcnow())
        ]
        self.assertEqual(expected, values)

        for i in reversed(xrange(0, 10)):
            r.process_input(str(i), created=utcnow() - timedelta(days=i))

        sd = dataseries.SeriesDef.select(r.report_id, [], sd_id)
        expected = list(reversed(range(0, 20)))
        values = [
            sv.value for sv in dataseries.get_series_values(
                sd, r,
                utcnow() - timedelta(days=100), utcnow())
        ]
        self.assertEqual(expected, values)
Esempio n. 17
0
    def test_insert_skip_db(self):
        inserted_tile = self.test_insert()

        tile = Tile.select(inserted_tile.dashboard_id, inserted_tile.tile_id)
        tile_config = {
            'tw_type':
            'Range',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back': 600,
                'tile_title': 'Points by user'
            }
        }
        tile = tile.insert(tile.owner_id,
                           tile.report_id,
                           tile.dashboard_id,
                           tile_config,
                           skip_db=True)

        self.assertEqual([], tile.tile_options['tags'])
        self.assertEqual(tile.tile_options['seconds_back'], 600)
        self.assertEqual(tile_config['series_spec_list'], tile.series_specs())

        db_tile = Tile.select(inserted_tile.dashboard_id,
                              inserted_tile.tile_id)
        self.assertEqual(db_tile.tile_options['tags'], ['ip:192.168.1.1'])
        self.assertEqual(db_tile.tile_options['seconds_back'], 86400)
Esempio n. 18
0
    def test_promote_first_as_master_multiple_masters_one_apply_mods_run(self):
        rd = self.test_repack_dont_put_master_first()

        tile_config = {
            'tags': ['q1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'q1:10',
                    'prefix': 'q1:'
                }],
            }
        }
        r2 = Report.insert(rd.owner_id, 'r2')
        master_tile2 = Tile.insert(rd.owner_id, r2.report_id, rd.dashboard_id,
                                   tile_config)
        layouts.place_tile(master_tile2)

        ri1 = r2.process_input('0', tags=['q1:8'],
                               handle_tpcreator=False).report_instance
        ri2 = r2.process_input('0', tags=['q1:12'],
                               handle_tpcreator=False).report_instance
        ri3 = r2.process_input('0', tags=['q1:6'],
                               handle_tpcreator=False).report_instance
        ri4 = rd.report.process_input('0',
                                      tags=['p1:2'],
                                      handle_tpcreator=False).report_instance

        layout_rows_tpcreator = c.dao.LayoutDAO.select_layout_by_report_multi(
            rd.owner_id, rd.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri4, layout_rows_tpcreator[0]),
            layouts.repack_mod(put_master_first=False),
            layouts.promote_first_as_master_mod(),
            layouts.if_mod(lambda layout_mod: layout_mod.tile_replacement,
                           layouts.repack_mod())
        ]
        layouts.apply_mods(mods, rd.owner_id, rd.dashboard_id, None)

        self.assertEqual([['p1:2'], ['p1:6'], ['p1:8'], ['p1:10'], ['p1:12'],
                          ['q1:6'], ['q1:8'], ['q1:10'], ['q1:12']],
                         [tile.tags for tile in rd.tiles_sorted_by_vo()])

        master1 = rd.get_tile_by_tags(['p1:2'])
        master2 = rd.get_tile_by_tags(['q1:6'])
        self.assertTrue(master1.is_master_tile())
        self.assertTrue(master2.is_master_tile())
        for tile in rd.tiles_sorted_by_vo():
            if tile.tags[0].startswith(
                    'p') and tile.tile_id != master1.tile_id:
                self.assertEqual(master1.tile_id, tile.get_master_tile_id())
            elif tile.tags[0].startswith(
                    'q') and tile.tile_id != master2.tile_id:
                self.assertEqual(master2.tile_id, tile.get_master_tile_id())
Esempio n. 19
0
 def test_insert_no_tags(self):
     owner_id = uuid.uuid1()
     report_id = report_data('points').report.report_id
     dashboard_id = report_data('points').dashboard_id
     tile_config = {
         'tw_type':
         'Range',
         'series_spec_list': [
             dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
             dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john'])),
         ],
         'tile_options': {
             'seconds_back': 86400,
             'tile_title': 'Points by user'
         }
     }
     tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)
     self.assertEqual(tile.tile_options['tags'], [])
Esempio n. 20
0
    def test_insert_similar_inserting(self):
        old_tile = self.test_insert_similar()
        tile = Tile.select(old_tile.dashboard_id, old_tile.tile_id)

        self.assertEqual([], tile.tile_options['tags'])
        self.assertEqual(tile.tile_options['seconds_back'], 600)
        self.assertEqual(
            [dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique']))],
            tile.series_specs())
Esempio n. 21
0
    def test_get_dashboards_displaying_report(self):
        od = self.test_inserting()

        res = od.get_dashboards_displaying_report(uuid.uuid4())
        self.assertEqual([], res)

        r = Report.insert(od.owner_id, 'r')
        tile_config = {
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
        }

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual([], res)

        t1 = Tile.insert(od.owner_id, r.report_id, od.dashboards[3].dashboard_id, tile_config)
        place_tile(t1)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(1, len(res))
        self.assertEqual('Dash 4', res[0].dashboard_name)

        t2 = Tile.insert(od.owner_id, r.report_id, od.dashboards[1].dashboard_id, tile_config)
        place_tile(t2)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        t3 = Tile.insert(od.owner_id, r.report_id, od.dashboards[1].dashboard_id, tile_config)
        place_tile(t3)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        detach_tile(t3)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(2, len(res))
        self.assertEqual('Dash 2', res[0].dashboard_name)
        self.assertEqual('Dash 4', res[1].dashboard_name)

        detach_tile(t2)

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(1, len(res))
        self.assertEqual('Dash 4', res[0].dashboard_name)

        od.dashboards[3].delete()

        res = od.get_dashboards_displaying_report(r.report_id)
        self.assertEqual(0, len(res))
Esempio n. 22
0
    def test_insert(self,
                    tile_config_ext={},
                    tile_options_ext={},
                    dashboard_id=None,
                    rd=None):
        rd = rd or report_data('points')
        owner_id = rd.owner_id
        report_id = rd.report.report_id
        dashboard_id = dashboard_id or rd.dashboard_id
        tile_config = {
            'tags': ['ip:192.168.1.1'],
            'tw_type':
            'Range',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['john'])),
            ],
            'tile_options': {
                'seconds_back': 86400,
                'tile_title': 'Points by user'
            }
        }
        tile_config.update(tile_config_ext)
        tile_config['tile_options'].update(tile_options_ext)

        tile = Tile.insert(owner_id, report_id, dashboard_id, tile_config)

        self.assertEqual(tile.owner_id, owner_id)
        self.assertEqual(tile.report_id, report_id)
        self.assertEqual(tile.report.report_id, report_id)
        self.assertEqual(dashboard_id, tile.dashboard_id)
        self.assertEqual(tile.tile_options['tags'], ['ip:192.168.1.1'])
        self.assertEqual(tile.tile_options['seconds_back'], 86400)
        self.assertEqual(tile_config['series_spec_list'], tile.series_specs())
        self.assertIsNone(tile.get_master_tile_id())
        self.assertIsInstance(tile.tilewidget, tilewidgets.TilewidgetForRange)
        return tile
Esempio n. 23
0
    def test_synchronize_options_of_tpcreated(self):
        rd, master_tile = self.test_handle_tpcreator()

        self.assertEqual(2,
                         len(tpcreator.select_tpcreated_tile_ids(master_tile)))

        tile_config = master_tile.get_tile_config()
        tile_config['series_spec_list'].append(
            dataseries.SeriesSpec(2, 0, dict(op='eq', args=['chris'])))
        tile_config['tile_options']['seconds_back'] = 125
        tile_config['tile_options']['tile_title'] = 'A B C'
        master_tile = master_tile.insert_similar(tile_config)

        tiles = Tile.select_multi(
            rd.dashboard_id,
            tpcreator.select_tpcreated_tile_ids(master_tile)).values()
        for tile in tiles:
            self.assertIn(
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['chris'])),
                tile.series_specs())
            self.assertEqual(125, tile.tile_options['seconds_back'])
            self.assertEqual(
                'A B C',
                tile.tile_options['tpcreator_data']['tile_title_base'])
Esempio n. 24
0
    def test_deleting_layout_by_report_row(self):
        owner_id = uuid.uuid1()
        dashboard_id_1 = uuid.uuid1()
        r = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tw_type':
            'Single',
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {}
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                ['p1:10'])

        master_tile_1 = Tile.insert(owner_id, r.report_id, dashboard_id_1,
                                    tile_config)
        layouts.place_tile(master_tile_1)

        r.process_input('1', tags=['p1:11'])

        self.assertEqual(
            2,
            len(
                Layout.select(master_tile_1.owner_id,
                              master_tile_1.dashboard_id).layout_dict))

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            master_tile_1.owner_id, master_tile_1.report_id, [], 'tpcreator',
            100)
        self.assertTrue(rows)

        layouts.detach_tile(master_tile_1)

        r.process_input('1', tags=['p1:12'])

        self.assertEqual(
            1,
            len(
                Layout.select(master_tile_1.owner_id,
                              master_tile_1.dashboard_id).layout_dict))

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            master_tile_1.owner_id, master_tile_1.report_id, [], 'tpcreator',
            100)
        self.assertFalse(rows)
Esempio n. 25
0
    def test_layout_sorting_complex_tag_names(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        rep = reports.Report.insert(owner_id, 'r')
        tile_config = {
            'tags': ['server0:0', 'service1:search.1'],
            'series_spec_list':
            [dataseries.SeriesSpec(0, -1, {
                'op': 'eq',
                'args': '0'
            })],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'server0:0',
                    'prefix': 'server0:0'
                }, {
                    'tag': 'service1:search.1',
                    'prefix': 'service1:'
                }],
            }
        }
        tile_config['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config['tags'])
        master_tile = Tile.insert(owner_id, rep.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        for i in range(8, 13):
            rep.process_input(str(i),
                              tags=['server0:0',
                                    'service1:search.%d' % i])

        layout = layouts.Layout.select(owner_id, dashboard_id)
        tiles = sorted(
            layout.tile_dict,
            key=lambda tile:
            (layout.tile_dict[tile]['y'], layout.tile_dict[tile]['x']))
        tags_lists = [tile.tags for tile in tiles]
        self.assertEqual([['server0:0', 'service1:search.1'],
                          ['server0:0', 'service1:search.8'],
                          ['server0:0', 'service1:search.9'],
                          ['server0:0', 'service1:search.10'],
                          ['server0:0', 'service1:search.11'],
                          ['server0:0', 'service1:search.12']], tags_lists)
Esempio n. 26
0
    def test_insert_different_tw_type(self):
        tile = self.test_insert()
        self.assertIsInstance(tile.tilewidget, tilewidgets.TilewidgetForRange)

        tile_config = {
            'tw_type':
            'Single',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'tile_title': 'Points by user'
            }
        }
        tile = tile.insert_similar(tile_config)
        self.assertIsInstance(tile.tilewidget, tilewidgets.TilewidgetForSingle)
        tile = Tile.select(tile.dashboard_id, tile.tile_id)
        self.assertIsInstance(tile.tilewidget, tilewidgets.TilewidgetForSingle)
Esempio n. 27
0
    def test_tpcreator_as_mod_performance(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()
        tile_config = {
            'tags': ['str:sample_string'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'str:sample_string',
                    'prefix': 'str:'
                }],
            }
        }
        r = reports.Report.insert(owner_id, 'r')
        master_tile = Tile.insert(owner_id, r.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        strs = [random_string() for _ in xrange(199)]
        mods = []
        layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            owner_id, r.report_id, [], 'tpcreator', 100)
        start = time()
        for str in strs:
            res = r.process_input('1',
                                  tags=['str:%s' % str],
                                  handle_tpcreator=False)
            mods.append(
                tpcreator.tpcreator_mod(res.report_instance, layout_rows[0],
                                        200))
        print 'Creating report instances took %.1f' % ((time() - start) * 1000)

        start = time()
        layouts.apply_mods(mods, owner_id, dashboard_id, None)
        print 'Applying tpcreator_mods took %.1f' % ((time() - start) * 1000)

        layout = Layout.select(owner_id, dashboard_id)
        self.assertEqual(200, len(layout.layout_dict))
        tags_set = {tile.tags[0].split(':')[1] for tile in layout.tile_dict}
        self.assertEqual(200, len(tags_set))
        self.assertEqual(tags_set, set(strs + ['sample_string']))
Esempio n. 28
0
    def test_no_repack(self):
        tile_config = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:10',
                    'prefix': 'p1:'
                }],
            }
        }
        rd = ReportData('r')
        master_tile = Tile.insert(rd.owner_id, rd.report_id, rd.dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        ri1 = rd.report.process_input('0',
                                      tags=['p1:8'],
                                      handle_tpcreator=False).report_instance
        ri2 = rd.report.process_input('0',
                                      tags=['p1:12'],
                                      handle_tpcreator=False).report_instance
        ri3 = rd.report.process_input('0',
                                      tags=['p1:6'],
                                      handle_tpcreator=False).report_instance

        layout_rows_tpcreator = c.dao.LayoutDAO.select_layout_by_report_multi(
            rd.owner_id, rd.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows_tpcreator[0]),
        ]
        layouts.apply_mods(mods, rd.owner_id, rd.dashboard_id, None)

        self.assertEqual([['p1:10'], ['p1:8'], ['p1:12'], ['p1:6']],
                         [tile.tags for tile in rd.tiles_sorted_by_vo()])

        return rd
Esempio n. 29
0
    def test_insert_similar(self):
        inserted_tile = self.test_insert()
        tile = Tile.select(inserted_tile.dashboard_id, inserted_tile.tile_id)

        tile_config = {
            'tw_type':
            'Range',
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back': 600,
                'tile_title': 'Points by user'
            }
        }
        tile = tile.insert_similar(tile_config)

        self.assertEqual([], tile.tile_options['tags'])
        self.assertEqual(tile.tile_options['seconds_back'], 600)
        self.assertEqual(tile_config['series_spec_list'], tile.series_specs())
        return tile
Esempio n. 30
0
    def test_tpcreator_as_mod(self):
        owner_id = uuid.uuid4()
        dashboard_id = uuid.uuid4()

        tile_config = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'p1:10',
                    'prefix': 'p1:'
                }],
            }
        }
        r = reports.Report.insert(owner_id, 'r')
        master_tile = Tile.insert(owner_id, r.report_id, dashboard_id,
                                  tile_config)
        layouts.place_tile(master_tile)

        ri1 = r.process_input('0', tags=['p1:11'],
                              handle_tpcreator=False).report_instance
        ri2 = r.process_input('0', tags=['p1:12'],
                              handle_tpcreator=False).report_instance
        ri3 = r.process_input('0', tags=['p1:12'],
                              handle_tpcreator=False).report_instance
        layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            owner_id, r.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows[0])
        ]
        layouts.apply_mods(mods, owner_id, dashboard_id, None)

        layout = Layout.select(owner_id, dashboard_id)
        self.assertEqual(3, len(layout.layout_dict))
        self.assertEqual([['p1:10'], ['p1:11'], ['p1:12']],
                         sorted(tile.tags for tile in layout.tile_dict))