Skip to content

Commit

Permalink
Fixing the python unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Aug 30, 2016
1 parent 14d59ec commit 02ee3b9
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 632 deletions.
5 changes: 2 additions & 3 deletions caravel/assets/javascripts/SqlLab/components/QuerySearch.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import SplitPane from 'react-split-pane';
import Select from 'react-select';
import { Button } from 'react-bootstrap';

Expand All @@ -21,7 +20,7 @@ class QuerySearch extends React.Component {
render() {
const queries = this.props.queries;
return (
<SplitPane split="vertical" minSize={200} defaultSize={300}>
<div>
<div className="pane-cell pane-west m-t-5">
<div className="panel panel-default Workspace">
<div className="panel-heading">
Expand Down Expand Up @@ -49,7 +48,7 @@ class QuerySearch extends React.Component {
/>
</div>
<Button>Search!</Button>
</SplitPane>
</div>
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class CeleryConfig(object):
CELERY_CONFIG = CeleryConfig
"""
CELERY_CONFIG = None
SQL_CELERY_DB_FILE_PATH = os.path.join(DATA_DIR, 'celery.db')
SQL_CELERY_RESULTS_DB_FILE_PATH = os.path.join(DATA_DIR, 'celery.db')
SQL_CELERY_DB_FILE_PATH = os.path.join(DATA_DIR, 'celerydb.sqlite')
SQL_CELERY_RESULTS_DB_FILE_PATH = os.path.join(DATA_DIR, 'celery_results.sqlite')

# The db id here results in selecting this one as a default in SQL Lab
DEFAULT_DB_ID = None
Expand Down
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
echo $DB
rm ~/.caravel/caravel_unittests.db
rm ~/.caravel/unittests.db
rm ~/.caravel/celerydb.sqlite
rm ~/.caravel/celery_results.sqlite
rm -f .coverage
Expand Down
93 changes: 93 additions & 0 deletions tests/base_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""Unit tests for Caravel"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os
import unittest

from flask_appbuilder.security.sqla import models as ab_models

import caravel
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
app.config['PUBLIC_ROLE_LIKE_GAMMA'] = True
'''
BASE_DIR = app.config.get("BASE_DIR")


class CaravelTestCase(unittest.TestCase):

def __init__(self, *args, **kwargs):
super(CaravelTestCase, self).__init__(*args, **kwargs)
self.client = app.test_client()

utils.init(caravel)

admin = appbuilder.sm.find_user('admin')
if not admin:
appbuilder.sm.add_user(
'admin', 'admin', ' user', 'admin@fab.org',
appbuilder.sm.find_role('Admin'),
password='general')

gamma = appbuilder.sm.find_user('gamma')
if not gamma:
appbuilder.sm.add_user(
'gamma', 'gamma', 'user', 'gamma@fab.org',
appbuilder.sm.find_role('Gamma'),
password='general')

alpha = appbuilder.sm.find_user('alpha')
if not alpha:
appbuilder.sm.add_user(
'alpha', 'alpha', 'user', 'alpha@fab.org',
appbuilder.sm.find_role('Alpha'),
password='general')

utils.init(caravel)

def login(self, username='admin', password='general'):
resp = self.client.post(
'/login/',
data=dict(username=username, password=password),
follow_redirects=True)
assert 'Welcome' in resp.data.decode('utf-8')

def get_query_by_sql(self, sql):
session = db.create_scoped_session()
query = session.query(models.Query).filter_by(sql=sql).first()
session.close()
return query

def logout(self):
self.client.get('/logout/', follow_redirects=True)

def test_welcome(self):
self.login()
resp = self.client.get('/caravel/welcome')
assert 'Welcome' in resp.data.decode('utf-8')

def setup_public_access_for_dashboard(self, table_name):
public_role = appbuilder.sm.find_role('Public')
perms = db.session.query(ab_models.PermissionView).all()
for perm in perms:
if (perm.permission.name == 'datasource_access' and
perm.view_menu and table_name in perm.view_menu.name):
appbuilder.sm.add_permission_role(public_role, perm)

def revoke_public_access(self, table_name):
public_role = appbuilder.sm.find_role('Public')
perms = db.session.query(ab_models.PermissionView).all()
for perm in perms:
if (perm.permission.name == 'datasource_access' and
perm.view_menu and table_name in perm.view_menu.name):
appbuilder.sm.del_permission_role(public_role, perm)
6 changes: 6 additions & 0 deletions tests/caravel_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
SQL_SELECT_AS_CTA = True
SQL_MAX_ROW = 666

TESTING = True
CSRF_ENABLED = False
SECRET_KEY = 'thisismyscretkey'
WTF_CSRF_ENABLED = False
PUBLIC_ROLE_LIKE_GAMMA = True


class CeleryConfig(object):
BROKER_URL = 'sqla+sqlite:///' + SQL_CELERY_DB_FILE_PATH
Expand Down

0 comments on commit 02ee3b9

Please sign in to comment.