2015-09-26 18:55:33 -04:00
|
|
|
import imp
|
2016-02-10 12:34:09 -05:00
|
|
|
import doctest
|
2015-09-26 18:55:33 -04:00
|
|
|
import os
|
|
|
|
import unittest
|
2016-03-28 11:09:46 -04:00
|
|
|
|
|
|
|
from flask import escape
|
2015-09-26 18:55:33 -04:00
|
|
|
|
2016-03-29 00:55:58 -04:00
|
|
|
import caravel
|
2016-03-28 11:09:46 -04:00
|
|
|
from caravel import app, db, models, utils, appbuilder
|
|
|
|
|
|
|
|
os.environ['CARAVEL_CONFIG'] = 'tests.caravel_test_config'
|
|
|
|
|
|
|
|
app.config['TESTING'] = True
|
|
|
|
app.config['CSRF_ENABLED'] = False
|
|
|
|
app.config['SECRET_KEY'] = 'thisismyscretkey'
|
|
|
|
app.config['WTF_CSRF_ENABLED'] = False
|
2015-09-26 18:55:33 -04:00
|
|
|
BASE_DIR = app.config.get("BASE_DIR")
|
2016-03-29 00:55:58 -04:00
|
|
|
cli = imp.load_source('cli', BASE_DIR + "/bin/caravel")
|
2015-09-26 18:55:33 -04:00
|
|
|
|
|
|
|
|
2016-03-28 11:09:46 -04:00
|
|
|
class CaravelTests(unittest.TestCase):
|
2015-09-26 18:55:33 -04:00
|
|
|
|
2016-03-28 11:09:46 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(CaravelTests, self).__init__(*args, **kwargs)
|
|
|
|
self.client = app.test_client()
|
|
|
|
role_admin = appbuilder.sm.find_role('Admin')
|
|
|
|
user = appbuilder.sm.find_user('admin')
|
|
|
|
if not user:
|
|
|
|
appbuilder.sm.add_user(
|
|
|
|
'admin', 'admin',' user', 'admin@fab.org',
|
|
|
|
role_admin, 'general')
|
|
|
|
utils.init(caravel)
|
|
|
|
self.load_examples()
|
2015-09-26 18:55:33 -04:00
|
|
|
|
|
|
|
def setUp(self):
|
2015-09-29 00:31:04 -04:00
|
|
|
pass
|
2015-09-26 18:55:33 -04:00
|
|
|
|
2016-03-28 11:09:46 -04:00
|
|
|
def tearDown(self):
|
|
|
|
pass
|
2015-09-22 14:36:54 -04:00
|
|
|
|
2016-03-28 11:09:46 -04:00
|
|
|
def login(self):
|
|
|
|
self.client.post(
|
|
|
|
'/login/',
|
|
|
|
data=dict(username='admin', password='general'),
|
|
|
|
follow_redirects=True)
|
|
|
|
|
|
|
|
def load_examples(self):
|
2015-09-26 18:55:33 -04:00
|
|
|
cli.load_examples(sample=True)
|
|
|
|
|
|
|
|
def test_slices(self):
|
2016-02-10 09:56:35 -05:00
|
|
|
# Testing by running all the examples
|
2016-03-28 11:09:46 -04:00
|
|
|
self.login()
|
2015-09-26 18:55:33 -04:00
|
|
|
Slc = models.Slice
|
2016-03-28 11:09:46 -04:00
|
|
|
urls = []
|
2015-09-26 18:55:33 -04:00
|
|
|
for slc in db.session.query(Slc).all():
|
2016-03-28 11:09:46 -04:00
|
|
|
urls += [
|
|
|
|
slc.slice_url,
|
|
|
|
slc.viz.json_endpoint,
|
|
|
|
]
|
|
|
|
for url in urls:
|
|
|
|
self.client.get(url)
|
2015-09-26 18:55:33 -04:00
|
|
|
|
2015-12-17 21:08:43 -05:00
|
|
|
def test_csv(self):
|
2016-03-29 00:55:58 -04:00
|
|
|
self.client.get('/caravel/explore/table/1/?viz_type=table&granularity=ds&since=100+years&until=now&metrics=count&groupby=name&limit=50&show_brush=y&show_brush=false&show_legend=y&show_brush=false&rich_tooltip=y&show_brush=false&show_brush=false&show_brush=false&show_brush=false&y_axis_format=&x_axis_showminmax=y&show_brush=false&line_interpolation=linear&rolling_type=None&rolling_periods=&time_compare=&num_period_compare=&where=&having=&flt_col_0=gender&flt_op_0=in&flt_eq_0=&flt_col_0=gender&flt_op_0=in&flt_eq_0=&slice_id=14&slice_name=Boys&collapsed_fieldsets=&action=&datasource_name=birth_names&datasource_id=1&datasource_type=table&previous_viz_type=line&csv=true')
|
2015-12-17 21:08:43 -05:00
|
|
|
|
2015-09-26 18:55:33 -04:00
|
|
|
def test_dashboard(self):
|
2016-03-28 11:09:46 -04:00
|
|
|
self.login()
|
|
|
|
urls = {}
|
2015-09-26 18:55:33 -04:00
|
|
|
for dash in db.session.query(models.Dashboard).all():
|
2016-03-28 11:09:46 -04:00
|
|
|
urls[dash.dashboard_title] = dash.url
|
|
|
|
for title, url in urls.items():
|
|
|
|
print(url)
|
|
|
|
assert escape(title) in self.client.get(url).data
|
2015-09-26 18:55:33 -04:00
|
|
|
|
2016-02-10 12:34:09 -05:00
|
|
|
def test_doctests(self):
|
|
|
|
modules = [utils]
|
|
|
|
for mod in modules:
|
|
|
|
failed, tests = doctest.testmod(mod)
|
|
|
|
if failed:
|
|
|
|
raise Exception("Failed a doctest")
|
|
|
|
|
2016-03-28 11:09:46 -04:00
|
|
|
def test_misc(self):
|
|
|
|
assert self.client.get('/health').data == "OK"
|
|
|
|
assert self.client.get('/ping').data == "OK"
|
2016-03-27 17:23:33 -04:00
|
|
|
|
2015-09-26 18:55:33 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|