[hg] galaxy 2426: Add missing functional tests for history featu...
details: http://www.bx.psu.edu/hg/galaxy/rev/e50551db6e60 changeset: 2426:e50551db6e60 user: Greg Von Kuster <greg@bx.psu.edu> date: Fri May 29 16:36:43 2009 -0400 description: Add missing functional tests for history features. 4 file(s) affected in this change: lib/galaxy/web/controllers/root.py templates/root/history_as_xml.mako test/base/twilltestcase.py test/functional/test_history_functions.py diffs (264 lines): diff -r c8a4a4ea0f2c -r e50551db6e60 lib/galaxy/web/controllers/root.py --- a/lib/galaxy/web/controllers/root.py Fri May 29 13:19:42 2009 -0400 +++ b/lib/galaxy/web/controllers/root.py Fri May 29 16:36:43 2009 -0400 @@ -59,7 +59,7 @@ return trans.fill_template( '/no_access.mako', message = 'Please log in to access Galaxy histories.' ) if as_xml: trans.response.set_content_type('text/xml') - return trans.fill_template_mako( "root/history_as_xml.mako", history=history ) + return trans.fill_template_mako( "root/history_as_xml.mako", history=history, show_deleted=util.string_as_bool( show_deleted ) ) else: template = "root/history.mako" return trans.fill_template( "root/history.mako", history = history, show_deleted = util.string_as_bool( show_deleted ) ) diff -r c8a4a4ea0f2c -r e50551db6e60 templates/root/history_as_xml.mako --- a/templates/root/history_as_xml.mako Fri May 29 13:19:42 2009 -0400 +++ b/templates/root/history_as_xml.mako Fri May 29 16:36:43 2009 -0400 @@ -1,8 +1,16 @@ <?xml version="1.0"?> <history> - %for data in history.active_datasets: - <data id="${data.id}" hid="${data.hid}" name="${data.name}" state="${data.state}" dbkey="${data.dbkey}"> - ${_(data.blurb)} - </data> - %endfor + %if show_deleted: + %for data in history.activatable_datasets: + <data id="${data.id}" hid="${data.hid}" name="${data.name}" state="${data.state}" dbkey="${data.dbkey}"> + ${_(data.blurb)} + </data> + %endfor + %else: + %for data in history.active_datasets: + <data id="${data.id}" hid="${data.hid}" name="${data.name}" state="${data.state}" dbkey="${data.dbkey}"> + ${_(data.blurb)} + </data> + %endfor + %endif </history> diff -r c8a4a4ea0f2c -r e50551db6e60 test/base/twilltestcase.py --- a/test/base/twilltestcase.py Fri May 29 13:19:42 2009 -0400 +++ b/test/base/twilltestcase.py Fri May 29 16:36:43 2009 -0400 @@ -98,6 +98,7 @@ # Functions associated with histories def check_history_for_errors( self ): """Raises an exception if there are errors in a history""" + self.home() self.visit_page( "history" ) page = self.last_page() if page.find( 'error' ) > -1: @@ -105,6 +106,7 @@ def check_history_for_string( self, patt ): """Looks for 'string' in history page""" + self.home() self.visit_page( "history" ) for subpatt in patt.split(): tc.find(subpatt) @@ -130,16 +132,16 @@ data_list = [ elem for elem in tree.findall("data") ] return data_list - def get_history( self ): + def get_history( self, show_deleted=False ): """Returns a history""" - tree = self.history_as_xml_tree() + tree = self.history_as_xml_tree( show_deleted=show_deleted ) data_list = [ elem for elem in tree.findall("data") ] return data_list - def history_as_xml_tree( self ): + def history_as_xml_tree( self, show_deleted=False ): """Returns a parsed xml object of a history""" self.home() - self.visit_page( 'history?as_xml=True' ) + self.visit_page( 'history?as_xml=True&show_deleted=%s' % show_deleted ) xml = self.last_page() tree = ElementTree.fromstring(xml) return tree @@ -201,6 +203,7 @@ name = elem.get( 'name' ) self.assertTrue( name ) self.visit_url( "%s/history/share?id=%s&email=%s&history_share_btn=Submit" % ( self.url, id, email ) ) + self.check_page_for_string( 'History (%s) has been shared with: %s' % ( name, email ) ) return id, name, email def share_history_containing_private_datasets( self, history_id, email='test@bx.psu.edu' ): """Attempt to share a history containing private datasets with a different user""" @@ -237,8 +240,10 @@ self.assertEqual(len(elems), 1) self.visit_page( "history/list?operation=switch&id=%s" % elems[0].get('id') ) - def view_stored_histories( self ): + def view_stored_histories( self, check_str='' ): self.visit_page( "history/list" ) + if check_str: + self.check_page_for_string( check_str ) # Functions associated with datasets (history items) and meta data def get_job_stderr( self, id ): @@ -264,16 +269,36 @@ self.visit_page( "edit?hid=%d" % hid ) for subpatt in patt.split(): tc.find(subpatt) - - def delete_history_item( self, hid ): + def delete_history_item( self, hid, check_str='' ): """Deletes an item from a history""" + try: + hid = int( hid ) + except: + raise AssertionError, "Invalid hid '%s' - must be int" % hid hid = str(hid) data_list = self.get_history() self.assertTrue( data_list ) - elems = [ elem for elem in data_list if elem.get('hid') == hid ] - self.assertEqual(len(elems), 1) - self.visit_page( "delete?id=%s" % elems[0].get('id') ) - + elems = [ elem for elem in data_list if elem.get( 'hid' ) == hid ] + self.assertEqual( len( elems ), 1 ) + self.home() + self.visit_page( "delete?id=%s" % elems[0].get( 'id' ) ) + if check_str: + self.check_page_for_string( check_str ) + def undelete_history_item( self, hid, show_deleted=False, check_str='' ): + """Un-deletes a deleted item in a history""" + try: + hid = int( hid ) + except: + raise AssertionError, "Invalid hid '%s' - must be int" % hid + hid = str( hid ) + data_list = self.get_history( show_deleted=show_deleted ) + self.assertTrue( data_list ) + elems = [ elem for elem in data_list if elem.get( 'hid' ) == hid ] + self.assertEqual( len( elems ), 1 ) + self.home() + self.visit_url( "%s/dataset/undelete?id=%s" % ( self.url, elems[0].get( 'id' ) ) ) + if check_str: + self.check_page_for_string( check_str ) def edit_metadata( self, hid=None, form_no=0, **kwd ): """ Edits the metadata associated with a history item.""" diff -r c8a4a4ea0f2c -r e50551db6e60 test/functional/test_history_functions.py --- a/test/functional/test_history_functions.py Fri May 29 13:19:42 2009 -0400 +++ b/test/functional/test_history_functions.py Fri May 29 16:36:43 2009 -0400 @@ -1,4 +1,6 @@ -from base.twilltestcase import TwillTestCase +import galaxy.model +from galaxy.model.orm import * +from base.twilltestcase import * class TestHistory( TwillTestCase ): @@ -20,15 +22,28 @@ def test_10_history_options_when_logged_in( self ): """Testing history options when logged in""" self.history_options() - self.check_page_for_string( 'Rename</a> current history') - self.check_page_for_string( 'List</a> previously stored histories') - self.check_page_for_string( 'Share</a> current history') - self.check_page_for_string( 'Delete</a> current history') - def test_10_history_rename( self ): + self.check_page_for_string( 'Rename</a> current history' ) + self.check_page_for_string( 'List</a> previously stored histories' ) + self.check_page_for_string( 'Construct workflow</a> from the current history' ) + self.check_page_for_string( 'Share</a> current history' ) + # Tests for changing default history permissions are done in test_security_and_libraries.py + self.check_page_for_string( 'Change default permissions</a> for the current history' ) + self.check_page_for_string( 'Show deleted</a> datasets in history' ) + self.check_page_for_string( 'Delete</a> current history' ) + # Need to add a history item in order to create a new empty history + try: + self.check_page_for_string( 'Create</a> a new empty history' ) + raise AssertionError, "Incorrectly able to create a new empty history when the current history is empty." + except: + pass + self.upload_file( '1.bed', dbkey='hg18' ) + self.history_options() + self.check_page_for_string( 'Create</a> a new empty history' ) + def test_15_history_rename( self ): """Testing renaming a history""" id, old_name, new_name = self.rename_history() self.check_page_for_string( 'History: %s renamed to: %s' %(old_name, new_name) ) - def test_15_history_view( self ): + def test_20_history_list( self ): """Testing viewing previously stored histories""" self.view_stored_histories() self.check_page_for_string( 'Stored histories' ) @@ -36,24 +51,15 @@ self.check_page_for_string( 'operation=Rename&id' ) self.check_page_for_string( 'operation=Switch&id' ) self.check_page_for_string( 'operation=Delete&id' ) - def test_20_delete_history_item( self ): - """Testing deleting history item""" - self.upload_file('1.bed', dbkey='hg15') - self.check_history_for_string('hg15 bed') - self.assertEqual ( len(self.get_history()), 1) - self.delete_history_item(1) - self.check_history_for_string("Your history is empty") - self.assertEqual ( len(self.get_history()), 0) - def test_25_share_history( self ): + def test_25_history_share( self ): """Testing sharing a history with another user""" self.upload_file('1.bed', dbkey='hg18') id, name, email = self.share_history() - self.last_page() - self.check_page_for_string( 'History (%s) has been shared with: %s' %(name, email) ) self.logout() - self.login( email='test2@bx.psu.edu' ) - self.view_stored_histories() - self.check_page_for_string( 'Unnamed history from test@bx.psu.edu' ) + self.login( email=email ) + self.home() + check_str = 'Unnamed history from test@bx.psu.edu' + self.view_stored_histories( check_str=check_str ) histories = self.get_histories() for history in histories: if history.get( 'name' ) == 'Unnamed history from test@bx.psu.edu': @@ -63,6 +69,47 @@ self.delete_history( id ) self.logout() self.login( email='test@bx.psu.edu' ) + def test_30_history_show_and_hide_deleted_datasets( self ): + """Testing displaying deleted history items""" + self.new_history() + self.upload_file('1.bed', dbkey='hg18') + latest_hda = galaxy.model.HistoryDatasetAssociation.query() \ + .order_by( desc( galaxy.model.HistoryDatasetAssociation.table.c.create_time ) ).first() + self.home() + self.visit_url( "%s/root/delete?show_deleted_on_refresh=False&id=%s" % ( self.url, str( latest_hda.id ) ) ) + self.check_history_for_string( 'Your history is empty' ) + self.home() + self.visit_url( "%s/history/?show_deleted=True" % self.url ) + self.check_page_for_string( 'This dataset has been deleted.' ) + self.check_page_for_string( '1.bed' ) + self.home() + self.visit_url( "%s/history/?show_deleted=False" % self.url ) + self.check_page_for_string( 'Your history is empty' ) + def test_35_deleting_and_undeleting_history_items( self ): + """Testing deleting and un-deleting history items""" + self.new_history() + # Add a new history item + self.upload_file( '1.bed', dbkey='hg15' ) + self.home() + self.visit_url( "%s/history/?show_deleted=False" % self.url ) + self.check_page_for_string( '1.bed' ) + self.check_page_for_string( 'hg15' ) + self.assertEqual ( len( self.get_history() ), 1 ) + # Delete the history item + self.delete_history_item( 1, check_str="Your history is empty" ) + self.assertEqual ( len( self.get_history() ), 0 ) + # Try deleting an invalid hid + try: + self.delete_history_item( 'XXX' ) + raise AssertionError, "Inproperly able to delete hid 'XXX' which is not an integer" + except: + pass + # Undelete the history item + self.undelete_history_item( 1, show_deleted=True ) + self.home() + 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_9999_clean_up( self ): self.delete_history() self.logout()
participants (1)
-
Greg Von Kuster