pass the standalone request arg in the /caravel/slices/<slice_id>/ endpoint redirect (#876)

* pass the  request arg in the /caravel/slices/<slice_id>/ endpoint.

remove unused import.

* test that a single slice redirects rather than testing them all. update standalone redirect logic for Javascript 'false' instead of Python False
This commit is contained in:
Chris Williams
2016-08-10 23:11:53 -07:00
committed by Maxime Beauchemin
parent 71bdabe1a1
commit 2bfb9cc7dd
3 changed files with 40 additions and 4 deletions

View File

@@ -29,7 +29,6 @@ app.config['PUBLIC_ROLE_LIKE_GAMMA'] = True
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):
@@ -147,7 +146,6 @@ class CoreTests(CaravelTestCase):
for slc in db.session.query(Slc).all():
urls += [
(slc.slice_name, 'slice_url', slc.slice_url),
(slc.slice_name, 'slice_id_endpoint', '/caravel/slices/{}'.format(slc.id)),
(slc.slice_name, 'json_endpoint', slc.viz.json_endpoint),
(slc.slice_name, 'csv_endpoint', slc.viz.csv_endpoint),
]
@@ -155,6 +153,42 @@ class CoreTests(CaravelTestCase):
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 = {}