Merge pull request #1035 from whummer/feat/test_params_on_embeds

Add test case for embeds with parameters
This commit is contained in:
Arik Fraimovich
2016-05-05 09:56:56 +03:00
3 changed files with 50 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import json
import pystache
from funcy import project
from flask import render_template, request
@@ -10,6 +11,7 @@ from redash import serializers
from redash.utils import json_dumps, collect_parameters_from_request
from redash.handlers import routes
from redash.handlers.base import org_scoped_rule, record_event
from redash.handlers.query_results import collect_query_parameters
from redash.permissions import require_access, view_only
from authentication import current_org
@@ -34,6 +36,7 @@ def run_query_sync(data_source, parameter_values, query_text):
return None
return data
except Exception, e:
abort(503, message="Unable to get result from the database.")
return None

View File

@@ -71,6 +71,16 @@ query_factory = ModelFactory(redash.models.Query,
data_source=data_source_factory.create,
org=1)
query_with_params_factory = ModelFactory(redash.models.Query,
name='New Query with Params',
description='',
query='SELECT {{param1}}',
user=user_factory.create,
is_archived=False,
schedule=None,
data_source=data_source_factory.create,
org=1)
alert_factory = ModelFactory(redash.models.Alert,
name=Sequence('Alert {}'),
query=query_factory.create,
@@ -199,6 +209,15 @@ class Factory(object):
args.update(kwargs)
return query_factory.create(**args)
def create_query_with_params(self, **kwargs):
args = {
'user': self.user,
'data_source': self.data_source,
'org': self.org
}
args.update(kwargs)
return query_with_params_factory.create(**args)
def create_query_result(self, **kwargs):
args = {
'data_source': self.data_source,
@@ -218,6 +237,13 @@ class Factory(object):
args.update(kwargs)
return visualization_factory.create(**args)
def create_visualization_with_params(self, **kwargs):
args = {
'query': self.create_query_with_params()
}
args.update(kwargs)
return visualization_factory.create(**args)
def create_widget(self, **kwargs):
args = {
'dashboard': self.create_dashboard(),

View File

@@ -1,4 +1,5 @@
from tests import BaseTestCase
from redash import settings
class TestEmbedVisualization(BaseTestCase):
@@ -10,6 +11,26 @@ class TestEmbedVisualization(BaseTestCase):
res = self.make_request("get", "/embed/query/{}/visualization/{}".format(vis.query.id, vis.id), is_json=False)
self.assertEqual(res.status_code, 200)
def test_parameters_on_embeds(self):
previous = settings.ALLOW_PARAMETERS_IN_EMBEDS
# set configuration
settings.ALLOW_PARAMETERS_IN_EMBEDS = True
vis = self.factory.create_visualization_with_params()
param1_name = "param1"
param1_value = "12345"
res = self.make_request("get", "/embed/query/{}/visualization/{}?p_{}={}".format(vis.query.id, vis.id, param1_name, param1_value), is_json=False)
# reset configuration
settings.ALLOW_PARAMETERS_IN_EMBEDS = previous
# Currently we are expecting a 503 error which indicates that
# the database is unavailable. This ensures that the code in embed.py
# reaches the point where a DB query is made, where we then fail
# intentionally (because DB connection is not available in the tests).
self.assertEqual(res.status_code, 503)
class TestPublicDashboard(BaseTestCase):
def test_success(self):