Initial version of tests.

This commit is contained in:
Arik Fraimovich 2014-01-31 18:50:25 +02:00
parent 7c838bf54e
commit e97d3172eb
2 changed files with 70 additions and 0 deletions

1
tests/__init__.py Normal file
View File

@ -0,0 +1 @@
from tests import controllers

69
tests/controllers.py Normal file
View 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 = []