Skip to content

Commit

Permalink
expose /slice/<slice_id>/ endpoint to redirect to a slice's url (#633)
Browse files Browse the repository at this point in the history
* expose /slice/<slice_id>/ endpoint to redirect to a slice's url

* remove residual print statement

* add unit test for caravel/slices/id endpoint
  • Loading branch information
williaster authored and mistercrunch committed Jun 20, 2016
1 parent deb197a commit 668ede1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,19 @@ def favstar(self, class_name, obj_id, action):
json.dumps({'count': count}),
mimetype="application/json")

@has_access
@expose("/slice/<slice_id>/")
def slice(self, slice_id):
"""Redirects a request for a slice id to its corresponding URL"""
session = db.session()
qry = session.query(models.Slice).filter_by(id=int(slice_id))
slc = qry.first()
if slc:
return redirect(slc.slice_url)
else:
flash("The specified slice could not be found", "danger")
return redirect('/slicemodelview/list/')

@has_access
@expose("/dashboard/<dashboard_id>/")
def dashboard(self, dashboard_id):
Expand Down
5 changes: 3 additions & 2 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ def test_save_slice(self):
assert 'Energy' in resp.data.decode('utf-8')

def test_slices(self):
# Testing by running all the examples
# Testing by hitting the two supported end points for all slices
self.login(username='admin')
Slc = models.Slice
urls = []
for slc in db.session.query(Slc).all():
urls += [
(slc.slice_name, 'slice_url', slc.slice_url),
(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),
]
Expand Down

0 comments on commit 668ede1

Please sign in to comment.