Skip to content

Commit

Permalink
test that a single slice redirects rather than testing them all. upda…
Browse files Browse the repository at this point in the history
…te standalone redirect logic for Javascript 'false' instead of Python False
  • Loading branch information
williaster committed Aug 10, 2016
1 parent 541ab3a commit 77f2593
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion caravel/templates/caravel/standalone.html
Expand Up @@ -5,7 +5,6 @@
<link rel="stylesheet" type="text/css" href="/static/assets/stylesheets/caravel.css" />
<link rel="stylesheet" type="text/css" href="/static/appbuilder/css/flags/flags16.css" />
<link rel="icon" type="image/png" href="/static/assets/images/favicon.png">

{% set CSS_THEME = appbuilder.get_app.config.get("CSS_THEME") %}
{% set height = request.args.get("height", 700) %}
{% if CSS_THEME %}
Expand All @@ -18,6 +17,7 @@
id="{{ viz.token }}"
class="widget viz slice {{ viz.viz_type }}"
data-slice="{{ viz.json_data }}"
data-standalone="true"
style="height: {{ height }}px;">
<img src="{{ url_for("static", filename="assets/images/loading.gif") }}" class="loading" alt="loading">
<div id="{{ viz.token }}_con" class="slice_container" style="height: 100%; width: 100%"></div>
Expand Down
2 changes: 1 addition & 1 deletion caravel/views.py
Expand Up @@ -1141,7 +1141,7 @@ def slice(self, slice_id):
slc = qry.first()
if slc:
url = '{slc.slice_url}&standalone={standalone}'.format(
slc=slc, standalone=request.args.get('standalone', False))
slc=slc, standalone=request.args.get('standalone', 'false'))
return redirect(url)
else:
flash("The specified slice could not be found", "danger")
Expand Down
43 changes: 36 additions & 7 deletions tests/core_tests.py
Expand Up @@ -29,7 +29,6 @@
BASE_DIR = app.config.get("BASE_DIR")
cli = imp.load_source('cli', BASE_DIR + "/bin/caravel")


class CaravelTestCase(unittest.TestCase):

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -149,17 +148,47 @@ def test_slices(self):
(slc.slice_name, 'slice_url', slc.slice_url),
(slc.slice_name, 'json_endpoint', slc.viz.json_endpoint),
(slc.slice_name, 'csv_endpoint', slc.viz.csv_endpoint),
(slc.slice_name, 'slice_id',
'/caravel/slices/{}/'.format(slc.id)),
(slc.slice_name, 'slice_id_standalone',
'/caravel/slices/{}/?standalone=true'.format(slc.id)),
(slc.slice_name, 'slice_id_not_standalone',
'/caravel/slices/{}/?standalone=false'.format(slc.id)),
]
for name, method, url in urls:
print("[{name}]/[{method}]: {url}".format(**locals()))
self.client.get(url)

def test_slice_id_redirects(self, username='admin'):
def make_assertions(resp, standalone):
decoded = resp.data.decode('utf-8')
if standalone:
assert "Query" not in decoded
assert 'data-standalone="true"' in decoded

else:
assert "Query" in decoded
assert 'data-standalone="true"' not in decoded

self.login(username=username)
slc = db.session.query(models.Slice).filter_by(slice_name="Name Cloud").first()
get = self.client.get

# Standard redirect
slc_url = slc.slice_url
id_url = '/caravel/slice/{slc.id}'.format(slc=slc)

make_assertions(get(slc_url, follow_redirects=True), False)
make_assertions(get(id_url, follow_redirects=True), False)

# Explicit standalone
slc_url_standalone = '{slc_url}&standalone=true'.format(slc_url=slc_url)
id_url_standalone = '{id_url}?standalone=true'.format(id_url=id_url)

make_assertions(get(slc_url_standalone, follow_redirects=True), True)
make_assertions(get(id_url_standalone, follow_redirects=True), True)

# Explicit not-standalone
slc_url_notstandalone = '{slc_url}&standalone=false'.format(slc_url=slc_url)
id_url_notstandalone = '{id_url}?standalone=false'.format(id_url=id_url)

make_assertions(get(slc_url_notstandalone, follow_redirects=True), False)
make_assertions(get(id_url_notstandalone, follow_redirects=True), False)

def test_dashboard(self):
self.login(username='admin')
urls = {}
Expand Down

0 comments on commit 77f2593

Please sign in to comment.