Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 8, 2017
1 parent 1035821 commit 7f8800c
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 188 deletions.
13 changes: 8 additions & 5 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,17 @@ class CeleryConfig(object):
BLUEPRINTS = []

try:

if CONFIG_PATH_ENV_VAR in os.environ:
# Explicitly import config module that is not in pythonpath; useful
# for case where app is being executed via pex.
print('Loaded your LOCAL configuration at [{}]'.format(
os.environ[CONFIG_PATH_ENV_VAR]))
imp.load_source('superset_config', os.environ[CONFIG_PATH_ENV_VAR])

from superset_config import * # noqa
import superset_config
print('Loaded your LOCAL configuration at [{}]'.format(
superset_config.__file__))
else:
from superset_config import * # noqa
import superset_config
print('Loaded your LOCAL configuration at [{}]'.format(
superset_config.__file__))
except ImportError:
pass
81 changes: 79 additions & 2 deletions superset/connectors/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import json

from sqlalchemy import Column, Integer, String, Text, Boolean

from superset import utils
from superset.models.helpers import AuditMixinNullable, ImportMixin


class Datasource(object):
class BaseDatasource(AuditMixinNullable, ImportMixin):

"""A common interface to objects that are queryable (tables and datasources)"""

__tablename__ = None # {connector_name}_datasource

# Used to do code highlighting when displaying the query in the UI
query_language = None

Expand Down Expand Up @@ -60,7 +65,7 @@ def data(self):
d = {
'all_cols': utils.choicify(self.column_names),
'column_formats': self.column_formats,
'edit_url' : self.url,
'edit_url': self.url,
'filter_select': self.filter_select_enabled,
'filterable_cols': utils.choicify(self.filterable_column_names),
'gb_cols': utils.choicify(self.groupby_column_names),
Expand All @@ -79,3 +84,75 @@ def data(self):
return d


class BaseColumn(AuditMixinNullable, ImportMixin):
"""Interface for column"""

__tablename__ = None # {connector_name}_column

id = Column(Integer, primary_key=True)
column_name = Column(String(255))
verbose_name = Column(String(1024))
is_active = Column(Boolean, default=True)
type = Column(String(32))
groupby = Column(Boolean, default=False)
count_distinct = Column(Boolean, default=False)
sum = Column(Boolean, default=False)
avg = Column(Boolean, default=False)
max = Column(Boolean, default=False)
min = Column(Boolean, default=False)
filterable = Column(Boolean, default=False)
description = Column(Text)

# [optional] Set this to support import/export functionality
export_fields = []

def __repr__(self):
return self.column_name

num_types = ('DOUBLE', 'FLOAT', 'INT', 'BIGINT', 'LONG', 'REAL', 'NUMERIC')
date_types = ('DATE', 'TIME', 'DATETIME')
str_types = ('VARCHAR', 'STRING', 'CHAR')

@property
def is_num(self):
return any([t in self.type.upper() for t in self.num_types])

@property
def is_time(self):
return any([t in self.type.upper() for t in self.date_types])

@property
def is_string(self):
return any([t in self.type.upper() for t in self.str_types])


class BaseMetric(AuditMixinNullable, ImportMixin):

"""Interface for Metrics"""

__tablename__ = None # {connector_name}_metric

id = Column(Integer, primary_key=True)
metric_name = Column(String(512))
verbose_name = Column(String(1024))
metric_type = Column(String(32))
description = Column(Text)
is_restricted = Column(Boolean, default=False, nullable=True)
d3format = Column(String(128))

"""
The interface should also declare a datasource relationship pointing
to a derivative of BaseDatasource, along with a FK
datasource_name = Column(
String(255),
ForeignKey('datasources.datasource_name'))
datasource = relationship(
# needs to be altered to point to {Connector}Datasource
'BaseDatasource',
backref=backref('metrics', cascade='all, delete-orphan'),
enable_typechecks=False)
"""
@property
def perm(self):
raise NotImplementedError()
Loading

0 comments on commit 7f8800c

Please sign in to comment.