Exemplo n.º 1
0
    def test_list_charts(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        self.session.add(dashboard)
        dashboard2 = Dashboard(title='Dashboard Title 2')
        self.session.add(dashboard2)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        chart = create_chart_view(req)

        req.json_body = {
            'title': 'Title 2',
            'dashboard_id': dashboard2.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        create_chart_view(req)

        req = dummy_request(self.session)
        req.params = {}
        charts = list_charts_view(req)
        self.assertEqual(len(charts), 2)

        req.params = {'dashboard_id': dashboard.id}
        charts = list_charts_view(req)
        self.assertEqual(len(charts), 1)
        self.assertEqual(charts[0]['id'], chart['id'])
Exemplo n.º 2
0
    def test_get_chart(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        self.session.add(dashboard)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        with self.assertRaises(exc.HTTPBadRequest):
            get_chart_view(req)

        with self.assertRaises(exc.HTTPNotFound):
            req.matchdict = {'id': 100}
            get_chart_view(req)

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }

        chart = create_chart_view(req)
        chart_id = chart['id']
        req.matchdict = {'id': chart_id}

        chart = get_chart_view(req)
        self.assertEqual(chart_id, chart['id'])
Exemplo n.º 3
0
    def test_delete_chart(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        self.session.add(dashboard)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        chart = create_chart_view(req)

        with self.assertRaises(exc.HTTPNotFound):
            req.matchdict = {'id': 0}
            delete_chart(req)

        req.matchdict = {"id": chart['id']}
        delete_chart(req)

        with self.assertRaises(exc.HTTPNotFound):
            get_chart_view(req)
Exemplo n.º 4
0
    def test_reorder_charts(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        self.session.add(dashboard)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        chart = create_chart_view(req)
        req.json_body = {
            'title': 'Title 2',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        create_chart_view(req)

        with self.assertRaises(exc.HTTPNotFound):
            req.matchdict = {'id': 100}
            req.json_body = {'dashboard_id': dashboard.id, 'index': 1}
            reorder_chart_view(req)

        req = dummy_request(self.session)
        req.params = {}

        charts = list_charts_view(req)
        self.assertEqual(charts[0]['id'], chart['id'])

        req.matchdict = {'id': chart['id']}
        req.json_body = {'dashboard_id': dashboard.id, 'index': 1}
        reorder_chart_view(req)
        charts = list_charts_view(req)
        self.assertEqual(charts[1]['id'], chart['id'])
        self.assertEqual(charts[1]['index'], 1)
        self.assertEqual(charts[0]['index'], 0)
Exemplo n.º 5
0
    def test_copy_chart(self):
        req = dummy_request(self.session)
        dashboard_view = DashboardView(name='Dashboard View', icon='icon')
        self.session.add(dashboard_view)
        dashboard1 = Dashboard(title='Dashboard Title 1')
        self.session.add(dashboard1)
        dashboard2 = Dashboard(title='Dashboard Title 2')
        self.session.add(dashboard2)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard1.id,
            'data_source_id': data_source.id,
            'unit': 'U',
            'group_by': [{
                'dashboard_view_id': dashboard_view.id,
                'value': 1
            }]
        }

        chart = create_chart_view(req)
        chart_id = chart['id']

        req.json_body = {}
        with self.assertRaises(exc.HTTPBadRequest):
            paste_chart_view(req)

        req.matchdict = {'id': chart_id}
        req.json_body = {'dashboard_id': dashboard1.id}
        chart = paste_chart_view(req)

        req.matchdict = {'id': chart['id']}
        chart = get_chart_view(req)
        self.assertEqual(chart['title'], 'Copy of Title')

        req.matchdict = {'id': chart_id}
        req.json_body = {'dashboard_id': dashboard2.id}
        chart = paste_chart_view(req)

        req.matchdict = {'id': chart['id']}
        chart = get_chart_view(req)
        self.assertEqual(chart['title'], 'Title')
Exemplo n.º 6
0
    def test_edit_chart_with_group_by(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        dashboard_view = DashboardView(name='Name', icon='')
        self.session.add(dashboard)
        self.session.add(dashboard_view)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U',
            'group_by': [{
                'value': '10',
                'dashboard_view_id': dashboard_view.id
            }]
        }

        chart = create_chart_view(req)
        self.assertEqual(chart['group_by'][0]['value'], '10')
        chart_id = chart['id']

        req.json_body = {}
        req.matchdict = {'id': chart_id}
        req.json_body = {
            'title': 'Title Edit',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'R',
            'group_by': [{
                'value': '100',
                'dashboard_view_id': dashboard_view.id
            }]
        }
        edit_chart(req)

        chart = get_chart_view(req)
        self.assertEqual(chart['title'], 'Title Edit')
        self.assertEqual(chart['group_by'][0]['value'], '100')
Exemplo n.º 7
0
    def test_create_chart(self):
        req = dummy_request(self.session)
        dashboard = Dashboard(title='Dashboard Title')
        self.session.add(dashboard)
        data_source = DataSource(name='Datasource')
        self.session.add(data_source)
        self.session.flush()

        # Test error validation
        with self.assertRaises(exc.HTTPBadRequest):
            req.json_body = {
                'data_source_id': data_source.id,
                'dashboard_id': dashboard.id
            }
            create_chart_view(req)

        with self.assertRaises(exc.HTTPBadRequest):
            req.json_body = {'title': 'Title', 'dashboard_id': dashboard.id}
            create_chart_view(req)

        req.json_body = {
            'title': 'Title',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }

        chart = create_chart_view(req)
        self.assertIsNotNone(chart.get('id'))
        self.assertEqual(chart['unit'], 'U')

        req.json_body = {
            'title': 'Title 2',
            'dashboard_id': dashboard.id,
            'data_source_id': data_source.id,
            'unit': 'U'
        }
        chart2 = create_chart_view(req)
        self.assertEqual(chart2['index'], 1)