From d5ca0742ed7b8b4e247c7284c0a6408ee33f8e8a Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Thu, 11 Jun 2009 12:06:29 -0400 Subject: [PATCH] Restrict the target history list to the users active hisstories when copying datasets between histories, clean up the relavent templates ( fixes ticket # 41 ), and add functional tests for copying history items between histories. --- lib/galaxy/web/controllers/dataset.py | 8 +- templates/dataset/copy_view.mako | 110 +++++++++++----------- templates/dataset/edit_attributes.mako | 16 +++- test/base/twilltestcase.py | 32 ++++++- test/functional/test_history_functions.py | 61 ++++++++++-- 5 files changed, 154 insertions(+), 73 deletions(-) diff --git a/lib/galaxy/web/controllers/dataset.py b/lib/galaxy/web/controllers/dataset.py index 762d2bfe38d..8716e10a8da 100644 --- a/lib/galaxy/web/controllers/dataset.py +++ b/lib/galaxy/web/controllers/dataset.py @@ -159,7 +159,8 @@ class DatasetInterface( BaseController ): raise "Error undeleting" @web.expose - def copy_datasets( self, trans, source_dataset_ids = "", target_history_ids = "", new_history_name="", do_copy = False ): + def copy_datasets( self, trans, source_dataset_ids="", target_history_ids="", new_history_name="", do_copy=False, **kwd ): + params = util.Params( kwd ) user = trans.get_user() history = trans.get_history() create_new_history = False @@ -202,7 +203,7 @@ class DatasetInterface( BaseController ): error_msg = error_msg + "You do not have permission to add datasets to %i requested histories. " % ( len( target_history_ids ) - len( target_histories ) ) for data in map( trans.app.model.HistoryDatasetAssociation.get, source_dataset_ids ): if data is None: - error_msg = error_msg + "You tried to copy a non-existant dataset. " + error_msg = error_msg + "You tried to copy a dataset that does not exist. " invalid_datasets += 1 elif data.history != history: error_msg = error_msg + "You tried to copy a dataset which is not in your current history. " @@ -220,8 +221,7 @@ class DatasetInterface( BaseController ): source_datasets = history.active_datasets target_histories = [history] if user: - target_histories = user.histories - + target_histories = user.active_histories return trans.fill_template( "/dataset/copy_view.mako", source_dataset_ids = source_dataset_ids, target_history_ids = target_history_ids, diff --git a/templates/dataset/copy_view.mako b/templates/dataset/copy_view.mako index 73648499c9f..28308f5add8 100644 --- a/templates/dataset/copy_view.mako +++ b/templates/dataset/copy_view.mako @@ -5,65 +5,67 @@ ${javascripts()} %if error_msg: -

-

${error_msg}
-
-

+

+

${error_msg}
+
+

%endif %if done_msg: -

-

${done_msg}
-
-

+

+

${done_msg}
+
+

%endif

-

-
-
-
Source History Items
-
- %for data in source_datasets: - <% - checked = "" - if data.id in source_dataset_ids: - checked = " checked" - %> -
${data.hid}: ${data.name}
- %endfor -
-
-
-
Target Histories
-
- %for i, hist in enumerate( target_histories ): - <% - checked = "" - if hist.id in target_history_ids: - checked = " checked" - cur_history_text = "" - if hist == trans.get_history(): - cur_history_text = " (current history)" - %> -
${i + 1}${cur_history_text}: ${hist.name}
- %endfor - %if trans.get_user(): - <% - checked = "" - if "create_new_history" in target_history_ids: - checked = " checked" - %> -
-
New history named:
- %endif -
-
-
-
-
-
+
+
+
+
Source History Items
+
+ %for data in source_datasets: + <% + checked = "" + if data.id in source_dataset_ids: + checked = " checked" + %> +
${data.hid}: ${data.name}
+ %endfor +
+
+
+
Target Histories
+
+ %for i, hist in enumerate( target_histories ): + <% + checked = "" + if hist.id in target_history_ids: + checked = " checked" + cur_history_text = "" + if hist == trans.get_history(): + cur_history_text = " (current history)" + %> +
${i + 1}${cur_history_text}: ${hist.name}
+ %endfor + %if trans.get_user(): + <% + checked = "" + if "create_new_history" in target_history_ids: + checked = " checked" + %> +
+
New history named:
+ %endif +
+
+
+
+ +
+
+

-

Select any number of source history items and any number of target histories and click on "Copy History Items" to add a copy of each selected dataset to each selected history.
-
+
Select any number of source history items and any number of target histories and click "Copy History Items" to add a copy of each selected history item to each selected target history.
+

diff --git a/templates/dataset/edit_attributes.mako b/templates/dataset/edit_attributes.mako index d68a0e5d819..77ac38ade52 100644 --- a/templates/dataset/edit_attributes.mako +++ b/templates/dataset/edit_attributes.mako @@ -157,8 +157,16 @@ %endif

-
Copy History Item
-
- Click here to make a copy of this history item. -
+
Copy History Item
+
+
+
+ +
+
+ Make a copy of this history item in your current history or any of your active histories. +
+
+
+
diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index 1833affcc56..8e19d978678 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -181,8 +181,9 @@ class TwillTestCase( unittest.TestCase ): self.home() def new_history( self, name=None ): """Creates a new, empty history""" + self.home() if name: - self.visit_url( "%s/history_new?name=%s" % ( self.url, str( name ) ) ) + self.visit_url( "%s/history_new?name=%s" % ( self.url, name ) ) else: self.visit_url( "%s/history_new" % self.url ) self.check_history_for_string('Your history is empty') @@ -191,7 +192,7 @@ class TwillTestCase( unittest.TestCase ): """Rename an existing history""" self.home() self.visit_page( "history/rename?id=%s&name=%s" %( id, new_name ) ) - check_str = 'History: %s renamed to: %s' % ( old_name, new_name ) + check_str = 'History: %s renamed to: %s' % ( old_name, urllib.unquote( new_name ) ) self.check_page_for_string( check_str ) self.home() def set_history( self ): @@ -330,7 +331,7 @@ class TwillTestCase( unittest.TestCase ): self.check_page_for_string( 'Attributes updated' ) self.home() def convert_format( self, hda_id, target_type ): - """Auto-detect history_dataset_association metadata""" + """Convert format of history_dataset_association""" self.home() self.visit_url( "%s/root/edit?id=%s" % ( self.url, hda_id ) ) self.check_page_for_string( 'This will inspect the dataset and attempt' ) @@ -339,7 +340,7 @@ class TwillTestCase( unittest.TestCase ): self.check_page_for_string( 'The file conversion of Convert BED to GFF on data' ) self.home() def change_datatype( self, hda_id, datatype ): - """Auto-detect history_dataset_association metadata""" + """Change format of history_dataset_association""" self.home() self.visit_url( "%s/root/edit?id=%s" % ( self.url, hda_id ) ) self.check_page_for_string( 'This will change the datatype of the existing dataset but' ) @@ -347,6 +348,29 @@ class TwillTestCase( unittest.TestCase ): tc.submit( 'change' ) self.check_page_for_string( 'Edit Attributes' ) self.home() + def copy_history_item( self, source_dataset_ids='', target_history_ids=[], all_target_history_ids=[], deleted_history_ids=[] ): + """Copy 1 or more history_dataset_associations to 1 or more histories""" + self.home() + self.visit_url( "%s/dataset/copy_datasets?source_dataset_ids=%s" % ( self.url, source_dataset_ids ) ) + self.check_page_for_string( 'Source History Items' ) + # Make sure all of users active histories are displayed + for id in all_target_history_ids: + self.check_page_for_string( id ) + # Make sure only active histories are displayed + for id in deleted_history_ids: + try: + self.check_page_for_string( id ) + raise AssertionError, "deleted history id %d displayed in list of target histories" % id + except: + pass + # Check each history to which we want to copy the item + for id in target_history_ids: + tc.fv( '1', 'target_history_ids', id ) + tc.submit( 'do_copy' ) + no_source_ids = len( source_dataset_ids.split( ',' ) ) + check_str = '%d datasets copied to %d histories.' % ( no_source_ids, len( target_history_ids ) ) + self.check_page_for_string( check_str ) + self.home() def get_dataset_ids_in_history( self ): """Returns the ids of datasets in a history""" data_list = self.get_history() diff --git a/test/functional/test_history_functions.py b/test/functional/test_history_functions.py index 79fea741ae9..7cd82d52f94 100644 --- a/test/functional/test_history_functions.py +++ b/test/functional/test_history_functions.py @@ -1,3 +1,4 @@ +import urllib import galaxy.model from galaxy.model.orm import * from base.twilltestcase import * @@ -55,7 +56,7 @@ class TestHistory( TwillTestCase ): history1 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() assert history1 is not None, "Problem retrieving history1 from database" self.upload_file( '1.bed', dbkey='hg18' ) - self.new_history( name='history2' ) + self.new_history( name=urllib.quote( 'history2' ) ) global history2 history2 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() assert history2 is not None, "Problem retrieving history2 from database" @@ -96,7 +97,7 @@ class TestHistory( TwillTestCase ): assert history3 is not None, "Problem retrieving history3 from database" if history3.deleted: raise AssertionError, "History id %d deleted when it should not be" % latest_history.id - self.rename_history( str( history3.id ), history3.name, new_name='history3' ) + self.rename_history( str( history3.id ), history3.name, new_name=urllib.quote( 'history 3' ) ) def test_020_history_list( self ): """Testing viewing previously stored histories""" self.view_stored_active_histories() @@ -131,7 +132,7 @@ class TestHistory( TwillTestCase ): global history4 history4 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() assert history4 is not None, "Problem retrieving history4 from database" - self.rename_history( str( history4.id ), history4.name, new_name='history4' ) + self.rename_history( str( history4.id ), history4.name, new_name=urllib.quote( 'history 4' ) ) history4.refresh() self.upload_file( '2.bed', dbkey='hg18' ) id = '%s,%s' % ( str( history3.id ), str( history4.id ) ) @@ -195,7 +196,7 @@ class TestHistory( TwillTestCase ): global history5 history5 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() assert history5 is not None, "Problem retrieving history5 from database" - self.rename_history( str( history5.id ), history5.name, new_name='history5' ) + self.rename_history( str( history5.id ), history5.name, new_name=urllib.quote( 'history5' ) ) history5.refresh() # Due to the limitations of twill ( not functional with the permissions forms ), we're forced # to do this manually. At this point, we just want to restrict the access permission on history5 @@ -377,7 +378,7 @@ class TestHistory( TwillTestCase ): action='no_share' ) def test_055_history_show_and_hide_deleted_datasets( self ): """Testing displaying deleted history items""" - self.new_history( name='temp_history1' ) + self.new_history( name=urllib.quote( 'show hide deleted datasets' ) ) self.upload_file('1.bed', dbkey='hg18') latest_hda = galaxy.model.HistoryDatasetAssociation.query() \ .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ).first() @@ -393,7 +394,7 @@ class TestHistory( TwillTestCase ): self.check_page_for_string( 'Your history is empty' ) def test_060_deleting_and_undeleting_history_items( self ): """Testing deleting and un-deleting history items""" - self.new_history( name='temp_history2' ) + self.new_history( name=urllib.quote( 'delete undelete history items' ) ) # Add a new history item self.upload_file( '1.bed', dbkey='hg15' ) self.home() @@ -416,8 +417,54 @@ class TestHistory( TwillTestCase ): self.visit_url( "%s/history/?show_deleted=False" % self.url ) self.check_page_for_string( '1.bed' ) self.check_page_for_string( 'hg15' ) - def test_065_reset_data_for_later_test_runs( self ): + def test_065_copying_history_items_between_histories( self ): + """Testing copying history items between histories""" + self.new_history( name=urllib.quote( 'copy history items' ) ) + global history6 + history6 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() + assert history6 is not None, "Problem retrieving history6 from database" + self.upload_file( '1.bed', dbkey='hg18' ) + hda1 = galaxy.model.HistoryDatasetAssociation.query() \ + .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ).first() + assert hda1 is not None, "Problem retrieving hda1 from database" + # We'll just test copying 1 hda + source_dataset_ids=str( hda1.id ) + # The valid list of target histories is only the user's active histories + all_target_history_ids = [ str( hda.id ) for hda in admin_user.active_histories ] + # Since history1 and history2 have been deleted, they should not be displayed in the list of target histories + # on the copy_view.mako form + deleted_history_ids = [ str( history1.id ), str( history2.id ) ] + # Test copying to the current history + target_history_ids=[ str( history6.id ) ] + self.copy_history_item( source_dataset_ids=source_dataset_ids, + target_history_ids=target_history_ids, + all_target_history_ids=all_target_history_ids, + deleted_history_ids=deleted_history_ids ) + history6.refresh() + if len( history6.datasets ) != 2: + raise AssertionError, "Copying hda1 to the current history failed" + # Test copying 1 hda to another history + self.new_history( name=urllib.quote( 'copy history items - 2' ) ) + global history7 + history7 = galaxy.model.History.query().order_by( desc( galaxy.model.History.table.c.create_time ) ).first() + assert history7 is not None, "Problem retrieving history7 from database" + # Switch back to our history from which we want to copy + self.switch_history( id=str( history6.id ), name=history6.name ) + target_history_ids=[ str( history7.id ) ] + all_target_history_ids = [ str( hda.id ) for hda in admin_user.active_histories ] + # Test copying to the a history that is not the current history + target_history_ids=[ str( history7.id ) ] + self.copy_history_item( source_dataset_ids=source_dataset_ids, + target_history_ids=target_history_ids, + all_target_history_ids=all_target_history_ids, + deleted_history_ids=deleted_history_ids ) + # Switch to the history to which we copied + self.switch_history( id=str( history7.id ), name=history7.name ) + self.check_history_for_string( hda1.name ) + def test_070_reset_data_for_later_test_runs( self ): """Reseting data to enable later test runs to pass""" self.delete_history( id=str( history3.id ) ) self.delete_history( id=str( history4.id ) ) self.delete_history( id=str( history5.id ) ) + self.delete_history( id=str( history6.id ) ) + self.delete_history( id=str( history7.id ) )