Refactor twill tool test driver to encode hda id earlier.

And pass an encoded id to display action in root controller.

Would definitely like to simplify or better yet remove root.display if not used anywhere else, it should be coming in through dataset controller.
This commit is contained in:
John Chilton
2013-11-21 19:17:12 -06:00
parent 86bd4f29ba
commit f35c0a89d6
2 changed files with 12 additions and 4 deletions
@@ -172,12 +172,16 @@ class RootController( BaseUIController, UsesHistoryMixin, UsesHistoryDatasetAsso
## ---- Dataset display / editing ----------------------------------------
@web.expose
def display( self, trans, id=None, hid=None, tofile=None, toext=".txt", **kwd ):
def display( self, trans, id=None, hid=None, tofile=None, toext=".txt", encoded_id=None, **kwd ):
"""Returns data directly into the browser.
Sets the mime-type according to the extension.
Used by the twill tool test driver - used anywhere else? Would like to drop hid
argument and path if unneeded now. Likewise, would like to drop encoded_id=XXX
and use assume id is encoded (likely id wouldn't be coming in encoded if this
is used anywhere else though.)
"""
#TODO: unused?
#TODO: unencoded id
if hid is not None:
try:
@@ -192,6 +196,8 @@ class RootController( BaseUIController, UsesHistoryMixin, UsesHistoryDatasetAsso
else:
raise Exception( "No dataset with hid '%d'" % hid )
else:
if encoded_id and not id:
id = trans.security.decode_id( encoded_id )
try:
data = trans.sa_session.query( self.app.model.HistoryDatasetAssociation ).get( id )
except:
+4 -2
View File
@@ -826,8 +826,10 @@ class TwillTestCase( unittest.TestCase ):
if ext != test_ext:
raise AssertionError( errmsg )
else:
hda_id = self.security.encode_id( elem.get( 'id' ) )
self.home()
self.visit_page( "display?hid=" + hid )
# See not in controllers/root.py about encoded_id.
self.visit_page( "display?encoded_id=%s" % hda_id )
data = self.last_page()
if attributes is not None and attributes.get( "assert_list", None ) is not None:
try:
@@ -918,7 +920,7 @@ class TwillTestCase( unittest.TestCase ):
if base_name is None:
base_name = os.path.split(file_name)[-1]
temp_name = self.makeTfname(fname=base_name)
self.visit_url( "%s/datasets/%s/display/%s" % ( self.url, self.security.encode_id( hda_id ), base_name ) )
self.visit_url( "%s/datasets/%s/display/%s" % ( self.url, hda_id, base_name ) )
data = self.last_page()
file( temp_name, 'wb' ).write( data )
if self.keepOutdir > '':