mirror of
https://github.com/valitydev/redash.git
synced 2024-11-06 17:15:17 +00:00
Initial version of tests.
This commit is contained in:
parent
7c838bf54e
commit
e97d3172eb
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from tests import controllers
|
69
tests/controllers.py
Normal file
69
tests/controllers.py
Normal file
@ -0,0 +1,69 @@
|
||||
from contextlib import contextmanager
|
||||
import unittest
|
||||
from redash import app
|
||||
|
||||
|
||||
@contextmanager
|
||||
def authenticated_user(c):
|
||||
with c.session_transaction() as sess:
|
||||
sess['openid'] = {'email': 'test@example.com', 'name': 'John Test'}
|
||||
|
||||
yield
|
||||
|
||||
|
||||
class AuthenticationTestMixin():
|
||||
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)
|
||||
|
||||
def test_returns_content_when_authenticated(self):
|
||||
with app.test_client() as c:
|
||||
with authenticated_user(c):
|
||||
for path in self.paths:
|
||||
rv = c.get(path)
|
||||
self.assertEquals(200, rv.status_code)
|
||||
|
||||
|
||||
class PingTest(unittest.TestCase):
|
||||
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)
|
||||
|
||||
|
||||
class IndexTest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = ['/', '/dashboard/example', '/queries/1', '/admin/status']
|
||||
|
||||
|
||||
class StatusTest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = ['/status.json']
|
||||
|
||||
|
||||
class DashboardAPITest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = ['/api/dashboards']
|
||||
|
||||
|
||||
class QueryAPITest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = ['/api/queries']
|
||||
|
||||
|
||||
class QueryResultAPITest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = []
|
||||
|
||||
|
||||
class JobAPITest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = []
|
||||
|
||||
|
||||
class CsvQueryResultAPITest(unittest.TestCase, AuthenticationTestMixin):
|
||||
def setUp(self):
|
||||
self.paths = []
|
Loading…
Reference in New Issue
Block a user