示例#1
0
    def test_dashboard_max_panel_id(self):
        dashboard = mock_dashboard('any_dashboard')

        self.assertEqual(dashboard.max_panel_id(), 4)

        dashboard.rows[0].panels.append(Panel(panel_source(5, "Low id panel"), 5))
        dashboard.rows[1].panels.append(Panel(panel_source(15, "High id panel"), 15))

        self.assertEqual(dashboard.max_panel_id(), 15)
示例#2
0
    def test_row_with_panel_with_custom_id(self):
        row = Row(row_source("Any row", [panel_source(99, "Any panel")]))
        self.assertEqual(row.panel('99-any-panel').id, 99)

        row.update(Panel(panel_source(10, "New panel")))
        self.assertEqual(len(row.panels), 2)
        self.assertEqual(row.panel('100-new-panel').id, 100)
        self.assertEqual(row.panel('100-new-panel').name, '100-new-panel')
示例#3
0
    def test_row_move_child(self):
        row = Row(row_source("Any row"))
        new_panels = [Panel(panel_source(1, 'A')),
                      Panel(panel_source(2, 'B')),
                      Panel(panel_source(3, 'C')),
                      Panel(panel_source(4, 'D'))]
        for panel in new_panels:
            row.update(panel)

        self.assertListEqual(panels(row), ["1-a", "2-b", "3-c", "4-d"])

        row.move_child("4-d", '1')
        self.assertListEqual(panels(row), ["4-d", "1-a", "2-b", "3-c"])

        row.move_child("4-d", '+1')
        self.assertListEqual(panels(row), ["1-a", "4-d", "2-b", "3-c"])

        row.move_child("2-b", '-2')
        self.assertListEqual(panels(row), ["2-b", "1-a", "4-d", "3-c"])

        row.move_child("1-a", '4')
        self.assertListEqual(panels(row), ["2-b", "4-d", "3-c", "1-a"])
示例#4
0
    def test_panel_update(self):
        panel = mock_panel()
        new_panel = Panel(panel_source(2, "New panel"), 2)

        panel.update(new_panel)

        self.assertEqual(panel.id, 1)
        self.assertEqual(panel.name, '1-new-panel')

        dashboard = mock_dashboard('any_dashboard')
        with self.assertRaises(InvalidDocument):
            panel.update(dashboard)

        row = mock_row()
        with self.assertRaises(InvalidDocument):
            panel.update(row)
示例#5
0
    def test_dashboard_update(self):
        dashboard = mock_dashboard('any_dashboard')

        new_dashboard = mock_dashboard('new_dashboard')
        dashboard.update(new_dashboard)
        self.assertEqual(dashboard.id, 'any_dashboard')

        row = Row(row_source("new row"))
        dashboard.update(row)
        self.assertEqual(len(dashboard.rows), 3)
        self.assertEqual(dashboard.rows[2].id, 3)

        row_with_panels = mock_row()
        dashboard.update(row_with_panels)
        self.assertEqual(dashboard.max_panel_id(), 6)

        panel = Panel(panel_source(1, "any panel"))
        with self.assertRaises(InvalidDocument):
            dashboard.update(panel)
示例#6
0
    def test_save_panel(self):
        res = DummyResources()
        panel = Panel(panel_source(42, "ac"))

        with self.assertRaises(InvalidDocument):
            res.save(panel)

        # Add new panel
        res.save(panel, 'any_dashboard', '1-a')
        self.assertEqual(res._storage.dashboard_id, 'any_dashboard')
        self.assertEqual(len(res._storage.dashboard.row('1-a').panels), 3)
        self.assertEqual(res._storage.dashboard.row('1-a').panel('5-ac').name, '5-ac')

        # Replace panel
        res.save(panel, 'any_dashboard', '1-a', '1-aa')
        self.assertEqual(res._storage.dashboard_id, 'any_dashboard')
        self.assertEqual(len(res._storage.dashboard.row('1-a').panels), 2)

        # Add new panel with custom name
        res._storage.get.side_effect = DocumentNotFound
        with self.assertRaises(DocumentNotFound):
            res.save(panel, 'any_dashboard', '1-a', '100-new-panel')
示例#7
0
def mock_panel(id=1):
    source = panel_source(id, "Any panel")

    return Panel(source, id)