Skip to content

Commit

Permalink
[druid] Updating Druid refresh metadata tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bodley committed Apr 27, 2018
1 parent fa3da8c commit 8219ea4
Showing 1 changed file with 61 additions and 53 deletions.
114 changes: 61 additions & 53 deletions tests/druid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,38 +346,38 @@ def test_refresh_metadata(self, PyDruid):
self.login(username='admin')
cluster = self.get_cluster(PyDruid)
cluster.refresh_datasources()
datasource = cluster.datasources[0]

for i, datasource in enumerate(cluster.datasources):
cols = (
db.session.query(DruidColumn)
.filter(DruidColumn.datasource_id == datasource.id)
cols = (
db.session.query(DruidColumn)
.filter(DruidColumn.datasource_id == datasource.id)
)

for col in cols:
self.assertIn(
col.column_name,
SEGMENT_METADATA[0]['columns'].keys(),
)

for col in cols:
self.assertIn(
col.column_name,
SEGMENT_METADATA[i]['columns'].keys(),
)
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)
self.assertEqual(
{metric.metric_name for metric in metrics},
{'max__metric1', 'min__metric1', 'sum__metric1'},
)

for metric in metrics:
agg, _ = metric.metric_name.split('__')

self.assertEqual(
{metric.metric_name for metric in metrics},
{'max__metric1', 'min__metric1', 'sum__metric1'},
json.loads(metric.json)['type'],
'double{}'.format(agg.capitalize()),
)

for metric in metrics:
agg, _ = metric.metric_name.split('__')

self.assertEqual(
json.loads(metric.json)['type'],
'double{}'.format(agg.capitalize()),
)

@patch('superset.connectors.druid.models.PyDruid')
def test_refresh_metadata_augment_type(self, PyDruid):
self.login(username='admin')
Expand All @@ -389,52 +389,60 @@ def test_refresh_metadata_augment_type(self, PyDruid):
instance = PyDruid.return_value
instance.segment_metadata.return_value = metadata
cluster.refresh_datasources()
datasource = cluster.datasources[0]

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)
column = (
db.session.query(DruidColumn)
.filter(DruidColumn.datasource_id == datasource.id)
.filter(DruidColumn.column_name == 'metric1')
).one()

for metric in metrics:
agg, _ = metric.metric_name.split('__')
self.assertEqual(column.type, 'LONG')

self.assertEqual(
metric.json_obj['type'],
'long{}'.format(agg.capitalize()),
)
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

for metric in metrics:
agg, _ = metric.metric_name.split('__')

self.assertEqual(
metric.json_obj['type'],
'long{}'.format(agg.capitalize()),
)

@patch('superset.connectors.druid.models.PyDruid')
def test_refresh_metadata_augment_verbose_name(self, PyDruid):
self.login(username='admin')
cluster = self.get_cluster(PyDruid)
cluster.refresh_datasources()
datasource = cluster.datasources[0]

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

for metric in metrics:
metric.verbose_name = metric.metric_name
for metric in metrics:
metric.verbose_name = metric.metric_name

db.session.commit()
db.session.commit()

# The verbose name should not change during a refresh.
cluster.refresh_datasources()
datasource = cluster.datasources[0]

for i, datasource in enumerate(cluster.datasources):
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)
metrics = (
db.session.query(DruidMetric)
.filter(DruidMetric.datasource_id == datasource.id)
.filter(DruidMetric.metric_name.like('%__metric1'))
)

for metric in metrics:
self.assertEqual(metric.verbose_name, metric.metric_name)
for metric in metrics:
self.assertEqual(metric.verbose_name, metric.metric_name)

def test_urls(self):
cluster = self.get_test_cluster_obj()
Expand Down

0 comments on commit 8219ea4

Please sign in to comment.