예제 #1
0
    def test_create_widget(self):
        dashboard = dashboard_factory.create()
        vis = visualization_factory.create()

        rv = self.create_widget(dashboard, vis)
        self.assertEquals(rv.status_code, 200)

        dashboard = models.Dashboard.get(models.Dashboard.id == dashboard.id)
        self.assertEquals(unicode(rv.json['layout']), dashboard.layout)

        self.assertEquals(dashboard.widgets, 1)
        self.assertEquals(rv.json['layout'], [[rv.json['widget']['id']]])
        self.assertEquals(rv.json['new_row'], True)

        rv2 = self.create_widget(dashboard, vis)
        self.assertEquals(dashboard.widgets, 2)
        self.assertEquals(
            rv2.json['layout'],
            [[rv.json['widget']['id'], rv2.json['widget']['id']]])
        self.assertEquals(rv2.json['new_row'], False)

        rv3 = self.create_widget(dashboard, vis)
        self.assertEquals(rv3.json['new_row'], True)
        rv4 = self.create_widget(dashboard, vis, width=2)
        self.assertEquals(
            rv4.json['layout'],
            [[rv.json['widget']['id'], rv2.json['widget']['id']],
             [rv3.json['widget']['id']], [rv4.json['widget']['id']]])
        self.assertEquals(rv4.json['new_row'], True)
예제 #2
0
    def test_create_widget(self):
        dashboard = dashboard_factory.create()
        vis = visualization_factory.create()

        rv = self.create_widget(dashboard, vis)
        self.assertEquals(rv.status_code, 200)

        dashboard = models.Dashboard.get(models.Dashboard.id == dashboard.id)
        self.assertEquals(unicode(rv.json['layout']), dashboard.layout)

        self.assertEquals(dashboard.widgets, 1)
        self.assertEquals(rv.json['layout'], [[rv.json['widget']['id']]])
        self.assertEquals(rv.json['new_row'], True)

        rv2 = self.create_widget(dashboard, vis)
        self.assertEquals(dashboard.widgets, 2)
        self.assertEquals(rv2.json['layout'],
                          [[rv.json['widget']['id'], rv2.json['widget']['id']]])
        self.assertEquals(rv2.json['new_row'], False)

        rv3 = self.create_widget(dashboard, vis)
        self.assertEquals(rv3.json['new_row'], True)
        rv4 = self.create_widget(dashboard, vis, width=2)
        self.assertEquals(rv4.json['layout'],
                          [[rv.json['widget']['id'], rv2.json['widget']['id']],
                           [rv3.json['widget']['id']],
                           [rv4.json['widget']['id']]])
        self.assertEquals(rv4.json['new_row'], True)
예제 #3
0
 def test_update_dashboard(self):
     d = dashboard_factory.create()
     new_name = "New Name"
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.post, "/api/dashboards/{0}".format(d.id), data={"name": new_name, "layout": "[]"})
         self.assertEquals(rv.status_code, 200)
         self.assertEquals(rv.json["name"], new_name)
예제 #4
0
 def test_get_dashboard(self):
     d1 = dashboard_factory.create()
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/api/dashboards/{0}'.format(d1.slug))
         self.assertEquals(rv.status_code, 200)
         self.assertDictEqual(json.loads(rv.data),
                              d1.to_dict(with_widgets=True))
예제 #5
0
    def test_delete_dashboard(self):
        d = dashboard_factory.create()
        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.delete, '/api/dashboards/{0}'.format(d.slug))
            self.assertEquals(rv.status_code, 200)

            d = models.Dashboard.get_by_slug(d.slug)
            self.assertTrue(d.is_archived)
예제 #6
0
 def test_update_dashboard(self):
     d = dashboard_factory.create()
     new_name = 'New Name'
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.post, '/api/dashboards/{0}'.format(d.id),
                           data={'name': new_name, 'layout': '[]'})
         self.assertEquals(rv.status_code, 200)
         self.assertEquals(rv.json['name'], new_name)
예제 #7
0
    def test_delete_dashboard(self):
        d = dashboard_factory.create()
        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.delete, '/api/dashboards/{0}'.format(d.slug))
            self.assertEquals(rv.status_code, 200)

            d = models.Dashboard.get_by_slug(d.slug)
            self.assertTrue(d.is_archived)
예제 #8
0
 def test_update_dashboard(self):
     d = dashboard_factory.create()
     new_name = 'New Name'
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.post, '/api/dashboards/{0}'.format(d.id),
                           data={'name': new_name, 'layout': '[]'})
         self.assertEquals(rv.status_code, 200)
         self.assertEquals(rv.json['name'], new_name)
예제 #9
0
    def test_get_dashboard(self):
        d1 = dashboard_factory.create()
        with app.test_client() as c, authenticated_user(c):
            rv = c.get('/api/dashboards/{0}'.format(d1.slug))
            self.assertEquals(rv.status_code, 200)

            expected = d1.to_dict(with_widgets=True)
            actual = json.loads(rv.data)

            self.assertResponseEqual(expected, actual)
예제 #10
0
    def test_create_text_widget(self):
        dashboard = dashboard_factory.create()

        data = {
            'visualization_id': None,
            'text': 'Sample text.',
            'dashboard_id': dashboard.id,
            'options': {},
            'width': 2
        }

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/widgets', data=data)

        self.assertEquals(rv.status_code, 200)
        self.assertEquals(rv.json['widget']['text'], 'Sample text.')
예제 #11
0
    def test_create_text_widget(self):
        dashboard = dashboard_factory.create()

        data = {
            'visualization_id': None,
            'text': 'Sample text.',
            'dashboard_id': dashboard.id,
            'options': {},
            'width': 2
        }

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/widgets', data=data)

        self.assertEquals(rv.status_code, 200)
        self.assertEquals(rv.json['widget']['text'], 'Sample text.')
예제 #12
0
    def test_create_text_widget(self):
        dashboard = dashboard_factory.create()

        data = {
            "visualization_id": None,
            "text": "Sample text.",
            "dashboard_id": dashboard.id,
            "options": {},
            "width": 2,
        }

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, "/api/widgets", data=data)

        self.assertEquals(rv.status_code, 200)
        self.assertEquals(rv.json["widget"]["text"], "Sample text.")