mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Fix tests
This commit is contained in:
parent
4287d9a2e2
commit
1c095bcd99
@ -38,19 +38,10 @@ class Sequence(object):
|
||||
|
||||
return self.string.format(self.sequence)
|
||||
|
||||
default_group_factory = ModelFactory(redash.models.Group,
|
||||
group_factory = ModelFactory(redash.models.Group,
|
||||
name='default', permissions=redash.models.Group.DEFAULT_PERMISSIONS,
|
||||
tables='{*}')
|
||||
|
||||
api_group_factory = ModelFactory(redash.models.Group,
|
||||
name='api', permissions=['view_query'],
|
||||
tables='{*}')
|
||||
|
||||
admin_group_factory = ModelFactory(redash.models.Group,
|
||||
name='admin', permissions=['admin'],
|
||||
tables='{*}')
|
||||
|
||||
|
||||
user_factory = ModelFactory(redash.models.User,
|
||||
name='John Doe', email=Sequence('test{}@example.com'),
|
||||
is_admin=False, groups=['default'])
|
||||
|
@ -7,8 +7,7 @@ from flask.ext.login import current_user
|
||||
from mock import patch
|
||||
from tests import BaseTestCase
|
||||
from tests.factories import dashboard_factory, widget_factory, visualization_factory, query_factory, \
|
||||
query_result_factory, user_factory, data_source_factory, default_group_factory, api_group_factory, \
|
||||
admin_group_factory
|
||||
query_result_factory, user_factory, data_source_factory, group_factory
|
||||
from redash import app, models, settings
|
||||
from redash.utils import json_dumps
|
||||
from redash.authentication import sign
|
||||
@ -19,7 +18,7 @@ settings.GOOGLE_APPS_DOMAIN = "example.com"
|
||||
@contextmanager
|
||||
def authenticated_user(c, user=None):
|
||||
if not user:
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
|
||||
with c.session_transaction() as sess:
|
||||
@ -79,8 +78,8 @@ class IndexTest(BaseTestCase, AuthenticationTestMixin):
|
||||
|
||||
class StatusTest(BaseTestCase):
|
||||
def test_returns_data_for_admin(self):
|
||||
admin_group_factory.create()
|
||||
default_group_factory.create()
|
||||
group_factory.create(name='admin', permissions=['admin'], tables='{*}')
|
||||
group_factory.create()
|
||||
admin = user_factory.create(groups=['admin','default'], is_admin=True)
|
||||
with app.test_client() as c, authenticated_user(c, user=admin):
|
||||
rv = c.get('/status.json')
|
||||
@ -115,7 +114,7 @@ class DashboardAPITest(BaseTestCase, AuthenticationTestMixin):
|
||||
self.assertEquals(rv.status_code, 404)
|
||||
|
||||
def test_create_new_dashboard(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
with app.test_client() as c, authenticated_user(c, user=user):
|
||||
dashboard_name = 'Test Dashboard'
|
||||
@ -232,7 +231,7 @@ class QueryAPITest(BaseTestCase, AuthenticationTestMixin):
|
||||
self.assertEquals(rv.json['name'], 'Testing')
|
||||
|
||||
def test_create_query(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
data_source = data_source_factory.create()
|
||||
query_data = {
|
||||
@ -327,7 +326,7 @@ class JobAPITest(BaseTestCase, AuthenticationTestMixin):
|
||||
class CsvQueryResultAPITest(BaseTestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
super(CsvQueryResultAPITest, self).setUp()
|
||||
api_group_factory.create()
|
||||
group_factory.create(name='api', permissions=['view_query'], tables='{*}')
|
||||
|
||||
self.paths = []
|
||||
self.query_result = query_result_factory.create()
|
||||
@ -400,7 +399,7 @@ class TestLogin(BaseTestCase):
|
||||
self.assertFalse(login_user_mock.called)
|
||||
|
||||
def test_submit_correct_user_and_password(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
user.hash_password('password')
|
||||
user.save()
|
||||
@ -411,7 +410,7 @@ class TestLogin(BaseTestCase):
|
||||
login_user_mock.assert_called_with(user, remember=False)
|
||||
|
||||
def test_submit_correct_user_and_password_and_remember_me(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
user.hash_password('password')
|
||||
user.save()
|
||||
@ -422,7 +421,7 @@ class TestLogin(BaseTestCase):
|
||||
login_user_mock.assert_called_with(user, remember=True)
|
||||
|
||||
def test_submit_correct_user_and_password_with_next(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
user.hash_password('password')
|
||||
user.save()
|
||||
@ -441,7 +440,7 @@ class TestLogin(BaseTestCase):
|
||||
self.assertFalse(login_user_mock.called)
|
||||
|
||||
def test_submit_incorrect_password(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
user.hash_password('password')
|
||||
user.save()
|
||||
@ -452,7 +451,7 @@ class TestLogin(BaseTestCase):
|
||||
self.assertFalse(login_user_mock.called)
|
||||
|
||||
def test_submit_incorrect_password(self):
|
||||
default_group_factory.create()
|
||||
group_factory.create()
|
||||
user = user_factory.create()
|
||||
|
||||
with app.test_client() as c, patch('redash.controllers.login_user') as login_user_mock:
|
||||
|
Loading…
Reference in New Issue
Block a user