Fixing the order and coverage report for the unit tests
This commit is contained in:
parent
1b4e750b2a
commit
60bce9ed59
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
rm /tmp/caravel_unittests.db
|
rm /tmp/caravel_unittests.db
|
||||||
|
rm -f .coverage
|
||||||
export CARAVEL_CONFIG=tests.caravel_test_config
|
export CARAVEL_CONFIG=tests.caravel_test_config
|
||||||
caravel/bin/caravel db upgrade
|
caravel/bin/caravel db upgrade
|
||||||
python setup.py nosetests
|
python setup.py nosetests
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ all_files = 1
|
||||||
upload-dir = docs/_build/html
|
upload-dir = docs/_build/html
|
||||||
|
|
||||||
[nosetests]
|
[nosetests]
|
||||||
verbosity=1
|
verbosity=3
|
||||||
detailed-errors=1
|
detailed-errors=1
|
||||||
with-coverage=1
|
with-coverage=1
|
||||||
cover-package=caravel
|
cover-package=caravel
|
||||||
|
|
|
||||||
|
|
@ -2,48 +2,75 @@ import imp
|
||||||
import doctest
|
import doctest
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
os.environ['CARAVEL_CONFIG'] = 'tests.caravel_test_config'
|
|
||||||
from flask.ext.testing import LiveServerTestCase, TestCase
|
from flask import escape
|
||||||
|
|
||||||
import caravel
|
import caravel
|
||||||
from caravel import app, db, models, utils
|
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
|
||||||
BASE_DIR = app.config.get("BASE_DIR")
|
BASE_DIR = app.config.get("BASE_DIR")
|
||||||
cli = imp.load_source('cli', BASE_DIR + "/bin/caravel")
|
cli = imp.load_source('cli', BASE_DIR + "/bin/caravel")
|
||||||
|
|
||||||
|
|
||||||
class LiveTest(TestCase):
|
class CaravelTests(unittest.TestCase):
|
||||||
|
|
||||||
def create_app(self):
|
def __init__(self, *args, **kwargs):
|
||||||
app.config['LIVESERVER_PORT'] = 8873
|
super(CaravelTests, self).__init__(*args, **kwargs)
|
||||||
app.config['TESTING'] = True
|
self.client = app.test_client()
|
||||||
return app
|
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()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_init(self):
|
def tearDown(self):
|
||||||
utils.init(caravel)
|
pass
|
||||||
|
|
||||||
def test_load_examples(self):
|
def login(self):
|
||||||
|
self.client.post(
|
||||||
|
'/login/',
|
||||||
|
data=dict(username='admin', password='general'),
|
||||||
|
follow_redirects=True)
|
||||||
|
|
||||||
|
def load_examples(self):
|
||||||
cli.load_examples(sample=True)
|
cli.load_examples(sample=True)
|
||||||
|
|
||||||
def test_slices(self):
|
def test_slices(self):
|
||||||
# Testing by running all the examples
|
# Testing by running all the examples
|
||||||
|
self.login()
|
||||||
Slc = models.Slice
|
Slc = models.Slice
|
||||||
|
urls = []
|
||||||
for slc in db.session.query(Slc).all():
|
for slc in db.session.query(Slc).all():
|
||||||
print(slc)
|
urls += [
|
||||||
self.client.get(slc.slice_url)
|
slc.slice_url,
|
||||||
viz = slc.viz
|
slc.viz.json_endpoint,
|
||||||
self.client.get(viz.get_url())
|
]
|
||||||
if hasattr(viz, 'get_json'):
|
for url in urls:
|
||||||
self.client.get(viz.get_json())
|
self.client.get(url)
|
||||||
|
|
||||||
def test_csv(self):
|
def test_csv(self):
|
||||||
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')
|
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')
|
||||||
|
|
||||||
def test_dashboard(self):
|
def test_dashboard(self):
|
||||||
|
self.login()
|
||||||
|
urls = {}
|
||||||
for dash in db.session.query(models.Dashboard).all():
|
for dash in db.session.query(models.Dashboard).all():
|
||||||
self.client.get(dash.url)
|
urls[dash.dashboard_title] = dash.url
|
||||||
|
for title, url in urls.items():
|
||||||
|
print(url)
|
||||||
|
assert escape(title) in self.client.get(url).data
|
||||||
|
|
||||||
def test_doctests(self):
|
def test_doctests(self):
|
||||||
modules = [utils]
|
modules = [utils]
|
||||||
|
|
@ -52,12 +79,10 @@ class LiveTest(TestCase):
|
||||||
if failed:
|
if failed:
|
||||||
raise Exception("Failed a doctest")
|
raise Exception("Failed a doctest")
|
||||||
|
|
||||||
def misc(self):
|
def test_misc(self):
|
||||||
self.client.get('/health')
|
assert self.client.get('/health').data == "OK"
|
||||||
self.client.get('/ping')
|
assert self.client.get('/ping').data == "OK"
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
from caravel.config import *
|
|
||||||
|
|
||||||
AUTH_USER_REGISTRATION_ROLE = 'alpha'
|
|
||||||
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/panoramix_unittests.db'
|
|
||||||
DEBUG = True
|
|
||||||
PANORAMIX_WEBSERVER_PORT = 8081
|
|
||||||
Loading…
Reference in New Issue