Beispiel #1
0
    def test_returns_content_when_user_in_allowed_list(self):
        settings.GOOGLE_APPS_DOMAIN = "example.com"
        settings.ALLOWED_EXTERNAL_USERS = ["*****@*****.**"]

        with app.test_client() as c, authenticated_user(c, user="******"):
            rv = c.get("/")
            self.assertEquals(200, rv.status_code)
    def test_submit_incorrect_password(self):
        user = user_factory.create()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login', data={'username': user.email, 'password': ''})
            self.assertEquals(rv.status_code, 200)
            self.assertFalse(login_user_mock.called)
Beispiel #3
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))
Beispiel #4
0
    def test_returns_content_when_google_apps_domain_empty(self):
        settings.GOOGLE_APPS_DOMAIN = ""
        settings.ALLOWED_EXTERNAL_USERS = []

        with app.test_client() as c, authenticated_user(c, user="******"):
            rv = c.get("/")
            self.assertEquals(200, rv.status_code)
Beispiel #5
0
    def test_submit_incorrect_password(self):
        user = user_factory.create()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login', data={'username': user.email, 'password': ''})
            self.assertEquals(rv.status_code, 200)
            self.assertFalse(login_user_mock.called)
Beispiel #6
0
 def test_redirect_for_correct_signature_and_no_expires(self):
     with app.test_client() as c:
         rv = c.get(
             '/api/queries/{0}/results/{1}.csv'.format(
                 self.query.id, self.query_result.id),
             query_string={'signature': self.signature(time.time() + 3600)})
         self.assertEquals(rv.status_code, 302)
Beispiel #7
0
    def test_update_query(self):
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/queries/{0}'.format(query.id), data={'name': 'Testing'})
            self.assertEqual(rv.status_code, 200)
            self.assertEquals(rv.json['name'], 'Testing')
Beispiel #8
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())
Beispiel #9
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)
            self.assertEquals(models.Visualization.select().count(), 0)
Beispiel #10
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)
            self.assertEquals(models.Visualization.select().count(), 0)
Beispiel #11
0
    def test_update_query(self):
        query = query_factory.create()

        with app.test_client() as c, authenticated_user(c):
            rv = json_request(c.post, '/api/queries/{0}'.format(query.id), data={'name': 'Testing'})
            self.assertEqual(rv.status_code, 200)
            self.assertEquals(rv.json['name'], 'Testing')
 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())
Beispiel #13
0
 def test_redirects_to_google_login_if_password_disabled(self):
     with app.test_client() as c, patch.object(settings,
                                               'PASSWORD_LOGIN_ENABLED',
                                               False):
         rv = c.get('/login')
         self.assertEquals(rv.status_code, 302)
         self.assertTrue(rv.location.endswith(url_for('GoogleAuth.login')))
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
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)
Beispiel #19
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)
Beispiel #20
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')
    def test_submit_correct_user_and_password_and_remember_me(self):
        user = user_factory.create()
        user.hash_password('password')
        user.save()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login', data={'username': user.email, 'password': '******', 'remember': True})
            self.assertEquals(rv.status_code, 302)
            login_user_mock.assert_called_with(user, remember=True)
Beispiel #22
0
 def test_create_new_dashboard(self):
     user_email = '*****@*****.**'
     with app.test_client() as c, authenticated_user(c, user=user_email):
         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'], user_email)
         self.assertEquals(rv.json['layout'], [])
 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'], [])
Beispiel #24
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'], [])
Beispiel #25
0
    def test_submit_correct_user_and_password_and_remember_me(self):
        user = user_factory.create()
        user.hash_password('password')
        user.save()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login', data={'username': user.email, 'password': '******', 'remember': True})
            self.assertEquals(rv.status_code, 302)
            login_user_mock.assert_called_with(user, remember=True)
Beispiel #26
0
 def test_redirect_for_wrong_signature(self):
     with app.test_client() as c:
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(
             self.query.id, self.query_result.id),
                    query_string={
                        'signature': 'whatever',
                        'expires': 0
                    })
         self.assertEquals(rv.status_code, 302)
Beispiel #27
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')
Beispiel #28
0
 def test_returns_200_for_correct_signature(self):
     with app.test_client() as c:
         expires = time.time() + 1800
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(
             self.query.id, self.query_result.id),
                    query_string={
                        'signature': self.signature(expires),
                        'expires': expires
                    })
         self.assertEquals(rv.status_code, 200)
Beispiel #29
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, '[]')
Beispiel #30
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)
            d = query.to_dict(with_visualizations=True)
            d.pop('created_at')
            self.assertDictContainsSubset(d, rv.json)
Beispiel #31
0
 def test_submit_incorrect_user(self):
     with app.test_client() as c, patch(
             'redash.controllers.login_user') as login_user_mock:
         rv = c.post('/login',
                     data={
                         'username': '******',
                         'password': '******'
                     })
         self.assertEquals(rv.status_code, 200)
         self.assertFalse(login_user_mock.called)
Beispiel #32
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, '[]')
Beispiel #33
0
 def test_redirect_for_correct_signature_and_expires_too_long(self):
     with app.test_client() as c:
         expires = time.time() + (10 * 3600)
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(
             self.query.id, self.query_result.id),
                    query_string={
                        'signature': self.signature(expires),
                        'expires': expires
                    })
         self.assertEquals(rv.status_code, 302)
Beispiel #34
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)
            d = query.to_dict(with_visualizations=True)
            d.pop('created_at')
            self.assertDictContainsSubset(d, rv.json)
    def test_submit_correct_user_and_password_with_next(self):
        user = user_factory.create()
        user.hash_password('password')
        user.save()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login?next=/test',
                        data={'username': user.email, 'password': '******'})
            self.assertEquals(rv.status_code, 302)
            self.assertEquals(rv.location, 'http://localhost/test')
            login_user_mock.assert_called_with(user, remember=False)
Beispiel #36
0
    def test_submit_correct_user_and_password_with_next(self):
        user = user_factory.create()
        user.hash_password('password')
        user.save()

        with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
            rv = c.post('/login?next=/test',
                        data={'username': user.email, 'password': '******'})
            self.assertEquals(rv.status_code, 302)
            self.assertEquals(rv.location, 'http://localhost/test')
            login_user_mock.assert_called_with(user, remember=False)
Beispiel #37
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
Beispiel #38
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
    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.')
Beispiel #40
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)
Beispiel #41
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.')
Beispiel #42
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)
Beispiel #43
0
    def test_create_query(self):
        user = '******'
        query_data = {
            'name': 'Testing',
            'query': 'SELECT 1',
            'ttl': 3600
        }

        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'], user)
            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)
Beispiel #44
0
    def test_create_query(self):
        user = user_factory.create()
        data_source = data_source_factory.create()
        query_data = {
            'name': 'Testing',
            'query': 'SELECT 1',
            'ttl': 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)
Beispiel #45
0
 def test_get_non_existint_dashbaord(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/api/dashboards/not_existing')
         self.assertEquals(rv.status_code, 404)
Beispiel #46
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))
Beispiel #47
0
 def test_ping(self):
     with app.test_client() as c:
         rv = c.get('/ping')
         self.assertEquals(200, rv.status_code)
         self.assertEquals('PONG.', rv.data)
Beispiel #48
0
 def test_returns_content_when_authenticated(self):
     with app.test_client() as c, authenticated_user(c):
         for path in self.paths:
             rv = c.get(path)
             self.assertEquals(200, rv.status_code)
Beispiel #49
0
 def test_redirects_when_not_authenticated(self):
     with app.test_client() as c:
         for path in self.paths:
             rv = c.get(path)
             self.assertEquals(302, rv.status_code)
Beispiel #50
0
 def test_returns_200_for_authenticated_user(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(self.query_result.query.id, self.query_result.id))
         self.assertEquals(rv.status_code, 200)
Beispiel #51
0
 def test_returns_data_for_admin(self):
     admin = user_factory.create(permissions=['admin'])
     with app.test_client() as c, authenticated_user(c, user=admin):
         rv = c.get('/status.json')
         self.assertEqual(rv.status_code, 200)
Beispiel #52
0
 def test_redirect_for_correct_signature_and_expires_too_long(self):
     with app.test_client() as c:
         expires = time.time()+(10*3600)
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(self.query_result.query.id, self.query_result.id), query_string={'signature': self.signature(expires), 'expires': expires})
         self.assertEquals(rv.status_code, 302)
Beispiel #53
0
 def test_redirect_for_correct_signature_and_no_expires(self):
     with app.test_client() as c:
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(self.query_result.query.id, self.query_result.id), query_string={'signature': self.signature(time.time()+3600)})
         self.assertEquals(rv.status_code, 302)
Beispiel #54
0
 def test_redirect_for_wrong_signature(self):
     with app.test_client() as c:
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(self.query_result.query.id, self.query_result.id), query_string={'signature': 'whatever', 'expires': 0})
         self.assertEquals(rv.status_code, 302)
Beispiel #55
0
 def test_user_already_loggedin(self):
     with app.test_client() as c, authenticated_user(c), patch(
             'redash.controllers.login_user') as login_user_mock:
         rv = c.get('/login')
         self.assertEquals(rv.status_code, 302)
         self.assertFalse(login_user_mock.called)
Beispiel #56
0
 def test_redirects_for_nonsigned_in_user(self):
     with app.test_client() as c:
         rv = c.get("/")
         self.assertEquals(302, rv.status_code)
Beispiel #57
0
 def test_ping(self):
     with app.test_client() as c:
         rv = c.get('/ping')
         self.assertEquals(200, rv.status_code)
         self.assertEquals('PONG.', rv.data)
Beispiel #58
0
 def test_returns_200_for_correct_signature(self):
     with app.test_client() as c:
         expires = time.time()+3600
         rv = c.get('/api/queries/{0}/results/{1}.csv'.format(self.query_result.query.id, self.query_result.id), query_string={'signature': self.signature(expires), 'expires': expires})
         self.assertEquals(rv.status_code, 200)
Beispiel #59
0
 def test_returns_403_for_non_admin(self):
     with app.test_client() as c, authenticated_user(c):
         rv = c.get('/status.json')
         self.assertEqual(rv.status_code, 403)
Beispiel #60
0
 def test_redirects_non_authenticated_user(self):
     with app.test_client() as c:
         rv = c.get('/status.json')
         self.assertEqual(rv.status_code, 302)