Beispiel #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'])
Beispiel #2
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()
        ])
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
def create_tile():
    dashboard_id = request.get_json()['dashboard_id']
    report_id = request.get_json().get('report_id')
    report_instance_id = request.get_json().get('report_instance_id')
    tile_config = request.get_json()['tile_config']
    moveresize = request.get_json()['moveresize']
    for_layout_id = request.get_json()['for_layout_id']

    check_access(lambda: auth.access_dashboard(dashboard_id))
    check_access(lambda: auth.access_report_instances(report_id))

    if tile_config['tags']:
        tile_config['tile_options']['tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
            tile_config['tags'])

    tile = tiles.Tile.insert(auth.logged_owner_id(), report_id, dashboard_id, tile_config)
    mres = layouts.place_tile(tile, for_layout_id=for_layout_id)
    if not mres:
        return error(message='Could not place the new tile on the dashboard, a page refresh is needed')

    dataseries.update_default_options(tile)

    log.info('Created new tile report_id=%s dashboard_id=%s tile_id=%s', report_id, dashboard_id,
             tile.tile_id)

    tile_html = get_template_attribute('m.html', 'dashboard_tile')\
        (tile.tile_id, mres.new_tiles[tile], moveresize)
    return success(result=dict(
        tile_html=tile_html,
        new_layout_id=mres.new_layout.layout_id,
    ))
Beispiel #6
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
Beispiel #7
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
Beispiel #8
0
 def test_tpcreator_creation(self):
     tile = self.test_insert(
         tile_options_ext={
             'tpcreator_uispec':
             tpcreator.suggested_tpcreator_uispec(['ip:192.168.1.1'])
         })
     place_tile(tile)
     self.assertTrue(self._select_tpcreator_rows(tile))
     return tile
Beispiel #9
0
def fetch_tile_settings():
    dashboard_id = request.get_json()['dashboard_id']
    tile_id = request.get_json()['tile_id']

    check_access(lambda: auth.access_dashboard(dashboard_id))

    tile = tiles.Tile.select(dashboard_id, tile_id)
    if not tile:
        return error(message='No tile found, please refresh the page')

    check_access(lambda: auth.access_report_instances(tile.report_id))

    res = {}

    res['report_id'] = tile.report_id
    latest_instance_id = tile.report.fetch_latest_instance_id(tile.tile_options['tags'])
    if not latest_instance_id:
        return error(message='No report instances for report %s - at least one report instance is needed to display tile settings.' % tile.report.report_name)
    ri = tile.report.fetch_single_instance(latest_instance_id, tile.tile_options['tags'])
    res['latest_instance_id'] = latest_instance_id

    res['html_newest_table'] = get_template_attribute('m.html', 'table_as_html_table')(ri.table)

    if tile.tile_options['tags']:
        res['html_selected_tags'] = get_template_attribute('m.html', 'selected_tags')(tile.tile_options['tags'])
        tpcreator_uispec = tile.tile_options.get('tpcreator_uispec')
        if not tpcreator_uispec:
            tpcreator_uispec = tpcreator.suggested_tpcreator_uispec(tile.tile_options['tags'])
        res['html_tpcreator_content'] = get_template_attribute('m.html', 'tpcreator_content')(tpcreator_uispec)

    else:
        res['html_selected_tags'] = None
        res['html_tpcreator_content'] = None

    res['tile_options'] = tile.tile_options
    res['report_name'] = tile.report.report_name


    html_series_specs = []
    for series_spec in tile.series_specs():
        data_d = {}
        cell = series_spec.get_cell(ri)
        if cell:
            data_d['sampled-from'] = {'rowno': cell.rowno, 'colno': cell.colno}
        html_series_specs.append(get_template_attribute('m.html', 'series_spec')(series_spec, ri, data_d))
    res['html_all_series_specs'] = '\n'.join(html_series_specs)

    if tile.tile_options.get('sscs'):
        res['html_sscs'] = get_template_attribute('m.html', 'series_spec_creator_spec')(tile.tile_options['sscs'], ri)
    else:
        res['html_sscs'] = None

    return success(result=res)
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
0
    def test_expire_tiles_without_data_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)

        #rd.report.process_input('1', tags=['p1:10'])

        rd.report.process_input('1\n2\n', tags=['p1:11'])
        rd.report.process_input('1\n2\n3\n', tags=['p1:12'])

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

        tile1_created_ago = datetime.datetime.utcnow(
        ) - util.datetime_from_uuid1(tile1.tile_id)
        tiles.expire_tiles_without_data(
            rd.layout().tile_dict.keys(),
            tile1_created_ago.total_seconds() - 0.00001,
            rd.layout().layout_id)
        self.assertEqual(2, len(rd.layout().layout_dict))
        self.assertTrue(rd.layout_has_tags([['p1:11'], ['p1:12']]))
        master_tile = rd.get_tile_by_tags(['p1:11'])
        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()))
Beispiel #14
0
    def test_handle_tpcreator(self):
        rd = new_report_data('points')

        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)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:10'])
        master_tile = rd.only_tile_from_layout()
        self.assertEqual([], tpcreator.select_tpcreated_tile_ids(master_tile))
        self.assertEqual([master_tile.tile_id],
                         _select_tile_ids(rd.dashboard_id))

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:20'])
        self.assertEqual(2, len(_select_tile_ids(rd.dashboard_id)))
        tiles = Tile.select_multi(rd.dashboard_id,
                                  _select_tile_ids(rd.dashboard_id)).values()
        created_tile = util.first(tiles, key=lambda t: not t.is_master_tile())
        self.assertEqual(['p1:20'], created_tile.tile_options['tags'])
        self.assertEqual(600, created_tile.tile_options['seconds_back'])
        self.assertEqual(tile_config['tile_options']['sscs'],
                         created_tile.tile_options['sscs'])
        td = created_tile.get_tile_data()
        self.assertEqual('points (monique, robert3)',
                         td['generated_tile_title'])
        self.assertEqual('[p1:20]', td['generated_tile_title_postfix'])

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:30', 'p2:30'])
        self.assertEqual(3, len(_select_tile_ids(rd.dashboard_id)))

        del tile_config['tile_options']['tpcreator_uispec']
        tile_config['tile_options']['tile_title'] = 'ot0'
        other_tile = Tile.insert(rd.owner_id, rd.report.report_id,
                                 rd.dashboard_id, tile_config)
        layouts.place_tile(other_tile)
        self.assertEqual(4, len(_select_tile_ids(rd.dashboard_id)))

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

        for i, tile_id in enumerate(
                tpcreator.select_tpcreated_tile_ids(master_tile)):
            tile = Tile.select(rd.dashboard_id, tile_id)
            tile_config = tile.get_tile_config()
            tile_config['tile_options']['tile_title'] = 'tpc%d' % i
            new_tile = tile.insert_similar(tile_config)
            layouts.replace_tiles({tile: new_tile}, None)

        return rd, Tile.select(master_tile.dashboard_id, master_tile.tile_id)
Beispiel #15
0
    def test_handle_tpcreator_multiple_masters(self):
        rd = new_report_data('points')

        tile_config_1 = {
            '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_1['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config_1['tags'])

        master_tile_1 = Tile.insert(rd.owner_id, rd.report.report_id,
                                    rd.dashboard_id, tile_config_1)
        layouts.place_tile(master_tile_1)

        tile_config_2 = {
            'tw_type':
            'Range',
            'tags': ['p2:20'],
            '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_2['tile_options'][
            'tpcreator_uispec'] = tpcreator.suggested_tpcreator_uispec(
                tile_config_2['tags'])

        master_tile_2 = Tile.insert(rd.owner_id, rd.report.report_id,
                                    rd.dashboard_id, tile_config_2)
        layouts.place_tile(master_tile_2)

        # tile config of 2.
        master_tile_3 = Tile.insert(rd.owner_id, rd.report.report_id,
                                    rd.dashboard_id, tile_config_2)
        layouts.place_tile(master_tile_3)

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:11'])
        rd.report.process_input(json.dumps(d), tags=['p1:12'])
        rd.report.process_input(json.dumps(d), tags=['p2:21'])
        rd.report.process_input(json.dumps(d), tags=['p2:22'])
        rd.report.process_input(json.dumps(d), tags=['p2:23'])

        layout = layouts.Layout.select(rd.owner_id, rd.dashboard_id)
        self.assertEqual(
            2, len(layout.get_tpcreated_tile_ids(master_tile_1.tile_id)))
        self.assertEqual(
            3, len(layout.get_tpcreated_tile_ids(master_tile_2.tile_id)))
        self.assertEqual(
            3, len(layout.get_tpcreated_tile_ids(master_tile_3.tile_id)))
Beispiel #16
0
    def test_expire_tiles_without_data_two_masters(self):
        rd = new_report_data('points', ['p3:30'])

        tile_config1 = {
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back': 1000,
                'tile_title': 'tile1'
            }
        }
        tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config1)
        place_tile(tile1)

        tile_config2 = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                1000,
                'tile_title':
                'tile2 [p1:10]',
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p1:10']),
            }
        }
        tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config2)
        place_tile(tile2)

        tile_config3 = {
            'tags': ['p2:20'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                1000,
                'tile_title':
                'tile3',
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p2:20']),
            }
        }
        tile3 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config3)
        place_tile(tile3)

        #rd.report.process_input(json.dumps([dict(user_name='monique', is_active=True, points=128)]), tags=['p1:10'])
        #rd.report.process_input(json.dumps([dict(user_name='monique', is_active=True, points=128)]), tags=['p2:20'])

        time.sleep(1)

        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:11'])
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:12'])
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:13'])

        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p2:21'])
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p2:22'])

        lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(),
                                              2000,
                                              rd.layout().layout_id)
        self.assertFalse(lid)

        lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 1,
                                              rd.layout().layout_id)
        self.assertTrue(lid)

        self.assertEqual(6, len(rd.layout().layout_dict))
        self.assertEqual(6, len(_select_tile_ids(rd.dashboard_id)))
        tile_list = rd.layout().tile_dict.keys()
        self.assertEqual(
            sorted([[], ['p1:11'], ['p1:12'], ['p1:13'], ['p2:21'],
                    ['p2:22']]), sorted([t.tags for t in tile_list]))
        master1 = first(
            t for t in tile_list
            if t.tags and t.tags[0].startswith('p1') and t.is_master_tile())
        master2 = first(
            t for t in tile_list
            if t.tags and t.tags[0].startswith('p2') and t.is_master_tile())
        self.assertEqual(
            2, len(rd.layout().get_tpcreated_tile_ids(master1.tile_id)))
        self.assertEqual(
            1, len(rd.layout().get_tpcreated_tile_ids(master2.tile_id)))

        self.assertEqual(['p1:11'], master1.tags)
        self.assertEqual(['p2:21'], master2.tags)

        self.assertEqual('tile2 [p1:11]', master1.tile_options['tile_title'])
        self.assertEqual('tile3', master2.tile_options['tile_title'])
Beispiel #17
0
    def test_layout_modification_by_tpcreator(self):
        data = {}

        @signals.layout_modified.connect
        def on_tiles_replaced(c, **kwargs):
            if kwargs['reason'] != 'tpcreator':
                return
            data.clear()
            data.update(kwargs)

        rd = new_report_data('points')

        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)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:10'])

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:20'])

        d = [
            OrderedDict([('user_name', 'robert3'), ('is_active', True),
                         ('points', 128)])
        ]
        rd.report.process_input(json.dumps(d), tags=['p1:30', 'p2:30'])

        tile = util.first(tile for tile in rd.layout().tile_dict if tile.tags == \
            ['p1:30'])
        self.assertIsNotNone(tile)
        self.assertEqual(
            tile, data['layout_modification_result'].new_tiles.keys()[0])
        self.assertEqual(rd.layout().layout_id, data['layout_modification_result']. \
                         new_layout.layout_id)
Beispiel #18
0
    def test_set_layout_fails(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:10'])

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

        master_tile_2 = master_tile_1.copy(dashboard_id_1)
        layouts.place_tile(master_tile_2)

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

        layout_1 = Layout.select(master_tile_1.owner_id,
                                 master_tile_1.dashboard_id)
        self.assertEqual(4, len(layout_1.layout_dict))
        self.assertEqual(
            1, len(layout_1.get_tpcreated_tile_ids(master_tile_1.tile_id)))
        self.assertEqual(
            1, len(layout_1.get_tpcreated_tile_ids(master_tile_2.tile_id)))
        self.assertNotEqual(
            layout_1.get_tpcreated_tile_ids(master_tile_1.tile_id),
            layout_1.get_tpcreated_tile_ids(master_tile_2.tile_id))

        dashboard_id_2 = uuid.uuid1()
        master_tile_3 = master_tile_1.copy(dashboard_id_2)
        layouts.place_tile(master_tile_3)

        dashboard_id_3 = uuid.uuid1()
        master_tile_4 = master_tile_1.copy(dashboard_id_3)
        layouts.place_tile(master_tile_4)

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

        layout_1 = Layout.select(master_tile_1.owner_id, dashboard_id_1)
        layout_2 = Layout.select(master_tile_1.owner_id, dashboard_id_2)
        layout_3 = Layout.select(master_tile_1.owner_id, dashboard_id_3)

        self.assertEqual(6, len(layout_1.layout_dict))
        self.assertEqual(2, len(layout_2.layout_dict))
        self.assertEqual(2, len(layout_3.layout_dict))

        mock_data = {'call': 0}

        def mock__set_new_layout(*args, **kwargs):
            mock_data['call'] += 1
            if mock_data['call'] >= 2:
                return None
            return mock__set_new_layout.old_fun(*args, **kwargs)

        with patch(layouts.Layout, layouts.Layout.set, mock__set_new_layout):
            r.process_input('1', tags=['p1:13'])

        layout_1 = Layout.select(master_tile_1.owner_id, dashboard_id_1)
        layout_2 = Layout.select(master_tile_1.owner_id, dashboard_id_2)
        layout_3 = Layout.select(master_tile_1.owner_id, dashboard_id_3)

        self.assertEqual(8, len(layout_1.layout_dict))
        self.assertEqual(2, len(layout_2.layout_dict))
        self.assertEqual(2, len(layout_3.layout_dict))

        mock_data = {'call': 0}

        def mock__set_new_layout(*args, **kwargs):
            mock_data['call'] += 1
            if mock_data['call'] % 5 != 0:
                return None
            return mock__set_new_layout.old_fun(*args, **kwargs)

        with patch(layouts.Layout, layouts.Layout.set, mock__set_new_layout):
            r.process_input('1', tags=['p1:14'])

        layout_1 = Layout.select(master_tile_1.owner_id, dashboard_id_1)
        layout_2 = Layout.select(master_tile_1.owner_id, dashboard_id_2)
        layout_3 = Layout.select(master_tile_1.owner_id, dashboard_id_3)

        self.assertEqual(10, len(layout_1.layout_dict))
        self.assertEqual(3, len(layout_2.layout_dict))
        self.assertEqual(3, len(layout_3.layout_dict))
Beispiel #19
0
    def test_expire_tiles_without_data_master(self):
        rd = new_report_data('points', ['p1:10'])

        tile_config1 = {
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back': 1000,
                'tile_title': 'tile1'
            }
        }
        tile1 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config1)
        place_tile(tile1)

        tile_config2 = {
            'tags': ['p1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(2, 0, dict(op='eq', args=['monique'])),
            ],
            'tile_options': {
                'seconds_back':
                1000,
                'tile_title':
                'tile2',
                'tpcreator_uispec':
                tpcreator.suggested_tpcreator_uispec(['p1:10']),
            }
        }
        tile2 = Tile.insert(rd.owner_id, rd.report.report_id, rd.dashboard_id,
                            tile_config2)
        place_tile(tile2)

        d = [
            OrderedDict([('user_name', 'robert'), ('is_active', True),
                         ('points', 128)]),
            OrderedDict([('user_name', 'monique2'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'monique3'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'monique4'), ('is_active', True),
                         ('points', 210)]),
            OrderedDict([('user_name', 'robert2'), ('is_active', True),
                         ('points', 210)]),
        ]
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:11'])
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:12'])
        rd.report.process_input(json.dumps([
            OrderedDict([('user_name', 'monique'), ('is_active', True),
                         ('points', 128)])
        ]),
                                tags=['p1:13'])

        self.assertEqual(5, len(rd.layout().layout_dict))

        lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(),
                                              2000,
                                              rd.layout().layout_id)
        self.assertFalse(lid)
        self.assertEqual(5, len(rd.layout().layout_dict))

        lid = tiles.expire_tiles_without_data(rd.layout().tile_dict.keys(), 0,
                                              rd.layout().layout_id)
        self.assertTrue(lid)

        self.assertEqual(1, len(rd.layout().layout_dict))
        self.assertEqual(1, len(_select_tile_ids(rd.dashboard_id)))
        self.assertEqual(tile2.tile_id,
                         rd.layout().tile_dict.keys()[0].tile_id)
Beispiel #20
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=['mike'])),
                dataseries.SeriesSpec(2, 0, dict(op='eq',
                                                 args=['nonexisting'])),
            ],
            'tile_options': {
                'drawer_type':
                'TextSingleDrawer',
                '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'], 'TextSingleDrawer')

        d = [
            OrderedDict([('user_name', 'mike'), ('is_active', True),
                         ('points', 32)]),
            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 (mike, nonexisting, robert3)',
                         data['generated_tile_title'])
        self.assertEqual('[ip:192.168.1.1]',
                         data['generated_tile_title_postfix'])
        self.assertNotIn('extra_options', data)
        self.assertNotIn('fetched_from_dt', data)
        self.assertEqual({'ed': 88}, data['latest_extra_ri_data'])
        self.assertEqual('points', data['report_name'])
        self.assertEqual(3, len(data['series_data']))
        for i, sd in enumerate(data['series_data']):
            self.assertIsInstance(sd['series_id'], uuid.UUID)
            self.assertEqual('points', data['common_header'])
            if i == 1:
                self.assertFalse(sd['data_points'])
            else:
                self.assertEqual(1, len(sd['data_points']))
            for dp in sd['data_points']:
                self.assertIsInstance(dp, tilewidgets.DataPoint)
        self.assertEqual(3, len(data['combined_colors']))
        self.assertEqual('points', data['common_header'])

        return tile