コード例 #1
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_returns_400_when_configuration_invalid(self):
        admin = user_factory.create(groups=['admin', 'default'])
        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = json_request(c.post, '/api/data_sources',
                              data={'name': 'DS 1', 'type': 'pg', 'options': '{}'})

            self.assertEqual(rv.status_code, 400)
コード例 #2
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_creates_data_source(self):
        admin = user_factory.create(groups=['admin', 'default'])
        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = json_request(c.post, '/api/data_sources',
                              data={'name': 'DS 1', 'type': 'pg', 'options': {"dbname": "redash"}})

            self.assertEqual(rv.status_code, 200)
コード例 #3
0
    def test_returns_200_for_admin_changing_other_user(self):
        admin = user_factory.create(groups=['admin', 'default'])
        user = user_factory.create()

        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = json_request(c.post, "/api/users/{}".format(user.id), data={"name": "New Name"})
            self.assertEqual(rv.status_code, 200)
コード例 #4
0
 def test_logout_when_loggedin(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/')
         self.assertTrue(current_user.is_authenticated())
         rv = c.get('/logout')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(current_user.is_authenticated())
コード例 #5
0
ファイル: test_handlers.py プロジェクト: 5t111111/redash
 def test_logout_when_loggedin(self):
     with app.test_client() as c, authenticated_user(c, user=self.factory.user):
         rv = c.get('/default/')
         self.assertTrue(current_user.is_authenticated)
         rv = c.get('/default/logout')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(current_user.is_authenticated)
コード例 #6
0
 def test_doesnt_use_cache_headers_for_non_specific_result(self):
     query_result = query_result_factory.create()
     query = query_factory.create(latest_query_data=query_result)
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.get,
                           '/api/queries/{}/results.json'.format(query.id))
         self.assertNotIn('Cache-Control', rv.headers)
コード例 #7
0
ファイル: test_handlers.py プロジェクト: tsibley/redash
 def test_user_already_loggedin(self):
     with app.test_client() as c, authenticated_user(
             c), patch('redash.handlers.authentication.login_user'
                       ) as login_user_mock:
         rv = c.get('/default/login')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(login_user_mock.called)
コード例 #8
0
ファイル: test_handlers.py プロジェクト: carezone/redash
 def test_logout_when_loggedin(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/')
         self.assertTrue(current_user.is_authenticated())
         rv = c.get('/logout')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(current_user.is_authenticated())
コード例 #9
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_delete_visualization(self):
        visualization = visualization_factory.create()
        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.delete, '/api/visualizations/{0}'.format(visualization.id))

            self.assertEquals(rv.status_code, 200)
            # =1 because each query has a default table visualization.
            self.assertEquals(models.Visualization.select().count(), 1)
コード例 #10
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_get_all_queries(self):
        queries = [query_factory.create() for _ in range(10)]

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.get, '/api/queries')

            self.assertEquals(rv.status_code, 200)
            self.assertEquals(len(rv.json), 10)
コード例 #11
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_get_query(self):
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.get, '/api/queries/{0}'.format(query.id))

            self.assertEquals(rv.status_code, 200)
            self.assertResponseEqual(rv.json, query.to_dict(with_visualizations=True))
コード例 #12
0
ファイル: test_handlers.py プロジェクト: tsibley/redash
 def test_logout_when_loggedin(self):
     with app.test_client() as c, authenticated_user(
             c, user=self.factory.user):
         rv = c.get('/default/')
         self.assertTrue(current_user.is_authenticated)
         rv = c.get('/default/logout')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(current_user.is_authenticated)
コード例 #13
0
ファイル: test_handlers.py プロジェクト: carezone/redash
 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)
コード例 #14
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    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)
コード例 #15
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)
コード例 #16
0
    def test_get_all_queries(self):
        queries = [query_factory.create() for _ in range(10)]

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.get, '/api/queries')

            self.assertEquals(rv.status_code, 200)
            self.assertEquals(len(rv.json), 10)
コード例 #17
0
ファイル: test_handlers.py プロジェクト: carezone/redash
 def test_create_new_dashboard(self):
     user = user_factory.create()
     with app.test_client() as c, authenticated_user(c, user=user):
         dashboard_name = 'Test Dashboard'
         rv = json_request(c.post, '/api/dashboards', data={'name': dashboard_name})
         self.assertEquals(rv.status_code, 200)
         self.assertEquals(rv.json['name'], 'Test Dashboard')
         self.assertEquals(rv.json['user_id'], user.id)
         self.assertEquals(rv.json['layout'], [])
コード例 #18
0
    def test_delete_visualization(self):
        visualization = visualization_factory.create()
        with app.test_client() as c, authenticated_user(c):
            rv = json_request(
                c.delete, '/api/visualizations/{0}'.format(visualization.id))

            self.assertEquals(rv.status_code, 200)
            # =1 because each query has a default table visualization.
            self.assertEquals(models.Visualization.select().count(), 1)
コード例 #19
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_returns_400_when_missing_fields(self):
        admin = user_factory.create(groups=['admin', 'default'])
        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = c.post("/api/data_sources")
            self.assertEqual(rv.status_code, 400)

            rv = json_request(c.post, '/api/data_sources', data={'name': 'DS 1'})

            self.assertEqual(rv.status_code, 400)
コード例 #20
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_update_visualization(self):
        visualization = visualization_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/visualizations/{0}'.format(visualization.id),
                              data={'name': 'After Update'})

            self.assertEquals(rv.status_code, 200)
            self.assertEquals(rv.json['name'], 'After Update')
コード例 #21
0
    def test_get_query(self):
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.get, '/api/queries/{0}'.format(query.id))

            self.assertEquals(rv.status_code, 200)
            self.assertResponseEqual(rv.json,
                                     query.to_dict(with_visualizations=True))
コード例 #22
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    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)
コード例 #23
0
    def test_delete_widget(self):
        widget = widget_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.delete, '/api/widgets/{0}'.format(widget.id))

            self.assertEquals(rv.status_code, 200)
            dashboard = models.Dashboard.get_by_slug(widget.dashboard.slug)
            self.assertEquals(dashboard.widgets.count(), 0)
            self.assertEquals(dashboard.layout, '[]')
コード例 #24
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_post_result_list(self):
        data_source = data_source_factory.create()
        query_result = query_result_factory.create()
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/query_results',
                              data={'data_source_id': data_source.id,
                                    'query': query.query})
            self.assertEquals(rv.status_code, 200)
コード例 #25
0
    def test_returns_400_when_missing_fields(self):
        admin = user_factory.create(groups=['admin', 'default'])

        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = c.post("/api/users")
            self.assertEqual(rv.status_code, 400)

            rv = json_request(c.post, '/api/users', data={'name': 'User'})

            self.assertEqual(rv.status_code, 400)
コード例 #26
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_update_query(self):
        query = query_factory.create()

        other_user = user_factory.create()

        with app.test_client() as c, authenticated_user(c, user=other_user):
            rv = json_request(c.post, '/api/queries/{0}'.format(query.id), data={'name': 'Testing'})
            self.assertEqual(rv.status_code, 200)
            self.assertEqual(rv.json['name'], 'Testing')
            self.assertEqual(rv.json['last_modified_by']['id'], other_user.id)
コード例 #27
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_delete_widget(self):
        widget = widget_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.delete, '/api/widgets/{0}'.format(widget.id))

            self.assertEquals(rv.status_code, 200)
            dashboard = models.Dashboard.get_by_slug(widget.dashboard.slug)
            self.assertEquals(dashboard.widgets.count(), 0)
            self.assertEquals(dashboard.layout, '[]')
コード例 #28
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)
コード例 #29
0
    def test_creates_user(self):
        admin = user_factory.create(groups=['admin', 'default'])

        with app.test_client() as c, authenticated_user(c, user=admin):
            test_user = {'name': 'User', 'email': '*****@*****.**', 'password': '******'}
            rv = json_request(c.post, '/api/users', data=test_user)

            self.assertEqual(rv.status_code, 200)
            self.assertEqual(rv.json['name'], test_user['name'])
            self.assertEqual(rv.json['email'], test_user['email'])
コード例 #30
0
 def test_create_new_dashboard(self):
     user = user_factory.create()
     with app.test_client() as c, authenticated_user(c, user=user):
         dashboard_name = 'Test Dashboard'
         rv = json_request(c.post,
                           '/api/dashboards',
                           data={'name': dashboard_name})
         self.assertEquals(rv.status_code, 200)
         self.assertEquals(rv.json['name'], 'Test Dashboard')
         self.assertEquals(rv.json['user_id'], user.id)
         self.assertEquals(rv.json['layout'], [])
コード例 #31
0
    def test_update_visualization(self):
        visualization = visualization_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post,
                              '/api/visualizations/{0}'.format(
                                  visualization.id),
                              data={'name': 'After Update'})

            self.assertEquals(rv.status_code, 200)
            self.assertEquals(rv.json['name'], 'After Update')
コード例 #32
0
    def test_returns_400_when_configuration_invalid(self):
        admin = user_factory.create(groups=['admin', 'default'])
        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = json_request(c.post,
                              '/api/data_sources',
                              data={
                                  'name': 'DS 1',
                                  'type': 'pg',
                                  'options': '{}'
                              })

            self.assertEqual(rv.status_code, 400)
コード例 #33
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)
コード例 #34
0
    def create_widget(self, dashboard, visualization, width=1):
        data = {
            'visualization_id': visualization.id,
            'dashboard_id': dashboard.id,
            'options': {},
            'width': width
        }

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

        return rv
コード例 #35
0
    def test_update_query(self):
        query = query_factory.create()

        other_user = user_factory.create()

        with app.test_client() as c, authenticated_user(c, user=other_user):
            rv = json_request(c.post,
                              '/api/queries/{0}'.format(query.id),
                              data={'name': 'Testing'})
            self.assertEqual(rv.status_code, 200)
            self.assertEqual(rv.json['name'], 'Testing')
            self.assertEqual(rv.json['last_modified_by']['id'], other_user.id)
コード例 #36
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def create_widget(self, dashboard, visualization, width=1):
        data = {
            'visualization_id': visualization.id,
            'dashboard_id': dashboard.id,
            'options': {},
            'width': width
        }

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

        return rv
コード例 #37
0
    def test_changes_password(self):
        new_password = "******"
        old_password = "******"
        with app.test_client() as c, authenticated_user(c) as user:
            user.hash_password(old_password)
            user.save()

            rv = json_request(c.post, "/api/users/{}".format(user.id), data={"password": new_password, "old_password": old_password})
            self.assertEqual(rv.status_code, 200)

            user = models.User.get_by_id(user.id)
            self.assertTrue(user.verify_password(new_password))
コード例 #38
0
    def test_post_result_list(self):
        data_source = data_source_factory.create()
        query_result = query_result_factory.create()
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post,
                              '/api/query_results',
                              data={
                                  'data_source_id': data_source.id,
                                  'query': query.query
                              })
            self.assertEquals(rv.status_code, 200)
コード例 #39
0
    def test_creates_data_source(self):
        admin = user_factory.create(groups=['admin', 'default'])
        with app.test_client() as c, authenticated_user(c, user=admin):
            rv = json_request(c.post,
                              '/api/data_sources',
                              data={
                                  'name': 'DS 1',
                                  'type': 'pg',
                                  'options': {
                                      "dbname": "redash"
                                  }
                              })

            self.assertEqual(rv.status_code, 200)
コード例 #40
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_create_visualization(self):
        query = query_factory.create()
        data = {
            'query_id': query.id,
            'name': 'Chart',
            'description':'',
            'options': {},
            'type': 'CHART'
        }

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

            self.assertEquals(rv.status_code, 200)
            data.pop('query_id')
            self.assertDictContainsSubset(data, rv.json)
コード例 #41
0
    def test_create_visualization(self):
        query = query_factory.create()
        data = {
            'query_id': query.id,
            'name': 'Chart',
            'description': '',
            'options': {},
            'type': 'CHART'
        }

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

            self.assertEquals(rv.status_code, 200)
            data.pop('query_id')
            self.assertDictContainsSubset(data, rv.json)
コード例 #42
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.')
コード例 #43
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    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.')
コード例 #44
0
    def test_create_query(self):
        user = user_factory.create()
        data_source = data_source_factory.create()
        query_data = {
            'name': 'Testing',
            'query': 'SELECT 1',
            'schedule': "3600",
            'data_source_id': data_source.id
        }

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

            self.assertEquals(rv.status_code, 200)
            self.assertDictContainsSubset(query_data, rv.json)
            self.assertEquals(rv.json['user']['id'], user.id)
            self.assertIsNotNone(rv.json['api_key'])
            self.assertIsNotNone(rv.json['query_hash'])

            query = models.Query.get_by_id(rv.json['id'])
            self.assertEquals(len(list(query.visualizations)), 1)
コード例 #45
0
ファイル: test_handlers.py プロジェクト: carezone/redash
    def test_create_query(self):
        user = user_factory.create()
        data_source = data_source_factory.create()
        query_data = {
            'name': 'Testing',
            'query': 'SELECT 1',
            'schedule': "3600",
            'data_source_id': data_source.id
        }

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

            self.assertEquals(rv.status_code, 200)
            self.assertDictContainsSubset(query_data, rv.json)
            self.assertEquals(rv.json['user']['id'], user.id)
            self.assertIsNotNone(rv.json['api_key'])
            self.assertIsNotNone(rv.json['query_hash'])

            query = models.Query.get_by_id(rv.json['id'])
            self.assertEquals(len(list(query.visualizations)), 1)
コード例 #46
0
 def test_doesnt_return_api_key_for_other_user(self):
     other_user = user_factory.create()
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.get, "/api/users/{}".format(other_user.id))
         self.assertNotIn('api_key', rv.json)
コード例 #47
0
 def test_returns_403_for_non_admin(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.post("/api/users")
         self.assertEqual(rv.status_code, 403)
コード例 #48
0
 def test_returns_403_for_non_admin_changing_not_his_own(self):
     other_user = user_factory.create()
     with app.test_client() as c, authenticated_user(c):
         rv = c.post("/api/users/{}".format(other_user.id), data={"name": "New Name"})
         self.assertEqual(rv.status_code, 403)
コード例 #49
0
 def test_returns_200_for_non_admin_changing_his_own(self):
     with app.test_client() as c, authenticated_user(c) as user:
         rv = json_request(c.post, "/api/users/{}".format(user.id), data={"name": "New Name"})
         self.assertEqual(rv.status_code, 200)
コード例 #50
0
ファイル: test_handlers.py プロジェクト: 5t111111/redash
 def test_user_already_loggedin(self):
     with app.test_client() as c, authenticated_user(c), patch('redash.handlers.authentication.login_user') as login_user_mock:
         rv = c.get('/default/login')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(login_user_mock.called)
コード例 #51
0
ファイル: test_query_results.py プロジェクト: carezone/redash
 def test_uses_cache_headers_for_specific_result(self):
     query_result = query_result_factory.create()
     query = query_factory.create(latest_query_data=query_result)
     with app.test_client() as c, authenticated_user(c):
         rv = json_request(c.get, '/api/queries/{}/results/{}.json'.format(query.id, query_result.id))
         self.assertIn('Cache-Control', rv.headers)
コード例 #52
0
 def test_fails_password_change_with_incorrect_old_password(self):
     with app.test_client() as c, authenticated_user(c) as user:
         rv = json_request(c.post, "/api/users/{}".format(user.id), data={"password": "******", "old_password": "******"})
         self.assertEqual(rv.status_code, 403)