From cb7fbc16b0e8cb06762fa76b502d2b82bfe99269 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Fri, 31 Jan 2014 18:50:25 +0200 Subject: [PATCH] Initial version of tests. --- tests/__init__.py | 1 + tests/controllers.py | 69 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/controllers.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..927ea298 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +from tests import controllers \ No newline at end of file diff --git a/tests/controllers.py b/tests/controllers.py new file mode 100644 index 00000000..4fcf0864 --- /dev/null +++ b/tests/controllers.py @@ -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 = [] \ No newline at end of file