From fa13b77cfabe6b359f0c3557e20f29c6cc71e356 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Sun, 12 Jun 2016 11:01:16 -0700 Subject: [PATCH] Adding postgres to the build matrix (#604) --- .travis.yml | 3 ++- caravel/data/__init__.py | 6 ++--- .../migrations/versions/4e6a06bad7a8_init.py | 2 +- caravel/models.py | 1 + setup.cfg | 2 +- tests/core_tests.py | 25 +++++++++---------- tox.ini | 5 ++++ 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7396b1cc7..52fcc806c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,10 @@ env: matrix: #- TOX_ENV=py27-mysql - TOX_ENV=py27-sqlite - #- TOX_ENV=py27-postgres + - TOX_ENV=py27-postgres - TOX_ENV=py34-sqlite - TOX_ENV=py34-mysql + - TOX_ENV=py34-postgres - TOX_ENV=javascript before_install: - npm install -g npm@'>=2.7.1' diff --git a/caravel/data/__init__.py b/caravel/data/__init__.py index acb57caad..b4121adef 100644 --- a/caravel/data/__init__.py +++ b/caravel/data/__init__.py @@ -581,7 +581,7 @@ def load_birth_names(): print("Done loading table!") print("-" * 80) - print("Creating table reference") + print("Creating table [birth_names] reference") obj = db.session.query(TBL).filter_by(table_name='birth_names').first() if not obj: obj = TBL(table_name='birth_names') @@ -829,7 +829,7 @@ def load_unicode_test_data(): print("Done loading table!") print("-" * 80) - print("Creating table reference") + print("Creating table [unicode_test] reference") obj = db.session.query(TBL).filter_by(table_name='unicode_test').first() if not obj: obj = TBL(table_name='unicode_test') @@ -908,7 +908,7 @@ def load_random_time_series_data(): print("Done loading table!") print("-" * 80) - print("Creating table reference") + print("Creating table [random_time_series] reference") obj = db.session.query(TBL).filter_by(table_name='random_time_series').first() if not obj: obj = TBL(table_name='random_time_series') diff --git a/caravel/migrations/versions/4e6a06bad7a8_init.py b/caravel/migrations/versions/4e6a06bad7a8_init.py index 72579f625..ee1146943 100644 --- a/caravel/migrations/versions/4e6a06bad7a8_init.py +++ b/caravel/migrations/versions/4e6a06bad7a8_init.py @@ -88,7 +88,7 @@ def upgrade(): sa.Column('changed_on', sa.DateTime(), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('datasource_name', sa.String(length=250), nullable=True), - sa.Column('column_name', sa.String(length=255), sa.ForeignKey("datasources.datasource_name"), nullable=True), + sa.Column('column_name', sa.String(length=255), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True), sa.Column('type', sa.String(length=32), nullable=True), sa.Column('groupby', sa.Boolean(), nullable=True), diff --git a/caravel/models.py b/caravel/models.py index 4f9cca4a7..651918dd3 100644 --- a/caravel/models.py +++ b/caravel/models.py @@ -1059,6 +1059,7 @@ class DruidDatasource(Model, AuditMixinNullable, Queryable): flasher("Refreshing datasource [{}]".format(name), "info") session.flush() datasource.cluster = cluster + session.flush() cols = datasource.latest_metadata() if not cols: diff --git a/setup.cfg b/setup.cfg index b67afa9bb..2a035df97 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,7 +18,7 @@ all_files = 1 upload-dir = docs/_build/html [nosetests] -verbosity=4 +verbosity=3 detailed-errors=1 with-coverage=1 nocapture=1 diff --git a/tests/core_tests.py b/tests/core_tests.py index 9e27f7279..c6f1dc029 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -8,7 +8,6 @@ from datetime import datetime import doctest import json import imp -import logging import os import unittest from mock import Mock, patch @@ -70,14 +69,12 @@ class CaravelTestCase(unittest.TestCase): assert 'Welcome' in resp.data.decode('utf-8') def logout(self): - resp = self.client.get('/logout/', follow_redirects=True) + 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') @@ -101,9 +98,13 @@ class CoreTests(CaravelTestCase): def __init__(self, *args, **kwargs): # Load examples first, so that we setup proper permission-view relations # for all example data sources. - self.load_examples() super(CoreTests, self).__init__(*args, **kwargs) - self.table_ids = {tbl.table_name: tbl.id for tbl in ( + + @classmethod + def setUpClass(cls): + cli.load_examples(load_test_data=True) + utils.init(caravel) + cls.table_ids = {tbl.table_name: tbl.id for tbl in ( db.session .query(models.SqlaTable) .all() @@ -115,16 +116,14 @@ class CoreTests(CaravelTestCase): def tearDown(self): pass - def load_examples(self): - cli.load_examples(load_test_data=True) - def test_save_slice(self): self.login(username='admin') - slice_id = ( + slc = ( db.session.query(models.Slice.id) .filter_by(slice_name="Energy Sankey") - .scalar()) + .first()) + slice_id = slc.id copy_name = "Test Sankey Save" tbl_id = self.table_ids.get('energy_usage') @@ -152,7 +151,7 @@ class CoreTests(CaravelTestCase): (slc.slice_name, 'csv_endpoint', slc.viz.csv_endpoint), ] for name, method, url in urls: - logging.info("[{name}]/[{method}]: {url}".format(**locals())) + print("[{name}]/[{method}]: {url}".format(**locals())) self.client.get(url) def test_dashboard(self): @@ -228,7 +227,7 @@ class CoreTests(CaravelTestCase): # Try access after adding appropriate permissions. resp = self.client.get('/slicemodelview/list/') data = resp.data.decode('utf-8') - assert 'birth_names' in data + assert 'birth_names' in data resp = self.client.get('/dashboardmodelview/list/') data = resp.data.decode('utf-8') diff --git a/tox.ini b/tox.ini index 67ddb4d95..2f2b13267 100644 --- a/tox.ini +++ b/tox.ini @@ -65,5 +65,10 @@ basepython = python2.7 setenv = CARAVEL__SQLALCHEMY_DATABASE_URI = postgresql+psycopg2://postgres@localhost/caravel +[testenv:py34-postgres] +basepython = python3.4 +setenv = + CARAVEL__SQLALCHEMY_DATABASE_URI = postgresql+psycopg2://postgres@localhost/caravel + [testenv:javascript] commands = {toxinidir}/caravel/assets/js_build.sh