From b8652ecc4e213c7126e90e679ee05aa422e58be0 Mon Sep 17 00:00:00 2001 From: Ramkrishna Chakrabarty Date: Wed, 17 Nov 2010 11:33:54 -0500 Subject: [PATCH] - added the change data library sample operation functional test. - renaming dataset now checks for incorrect filename characters - fixed bugs --- lib/galaxy/web/controllers/forms.py | 6 ++--- lib/galaxy/web/controllers/requests_admin.py | 14 ++++++++++- lib/galaxy/web/controllers/requests_common.py | 2 +- .../galaxy_messaging/server/setup_rabbitmq.py | 2 +- templates/admin/requests/rename_datasets.mako | 8 +++++++ test/base/twilltestcase.py | 17 ++++++++++++++ test/functional/test_sample_tracking.py | 23 ++++++++++++++++--- 7 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/web/controllers/forms.py b/lib/galaxy/web/controllers/forms.py index 359b95edb08..452c64c8115 100644 --- a/lib/galaxy/web/controllers/forms.py +++ b/lib/galaxy/web/controllers/forms.py @@ -635,8 +635,8 @@ class Forms( BaseController ): if form_type == trans.model.FormDefinition.types.SAMPLE: for ft in trans.model.Sample.supported_field_types: if ft.__name__ == field[ 'type' ]: - self.fieldtype.add_option( ft.__name__, ft__name__, selected=True ) - if ft == 'SelectField': + self.fieldtype.add_option( ft.__name__, ft.__name__, selected=True ) + if ft.__name__ == 'SelectField': self.selectbox_ui( field ) else: self.fieldtype.add_option( ft.__name__, ft.__name__ ) @@ -644,7 +644,7 @@ class Forms( BaseController ): for ft in trans.model.FormDefinition.supported_field_types: if ft.__name__ == field[ 'type' ]: self.fieldtype.add_option( ft.__name__, ft.__name__, selected=True ) - if ft == 'SelectField': + if ft.__name__ == 'SelectField': self.selectbox_ui( field ) else: self.fieldtype.add_option( ft.__name__, ft.__name__ ) diff --git a/lib/galaxy/web/controllers/requests_admin.py b/lib/galaxy/web/controllers/requests_admin.py index 5a8ff869890..2ab3781310d 100644 --- a/lib/galaxy/web/controllers/requests_admin.py +++ b/lib/galaxy/web/controllers/requests_admin.py @@ -361,17 +361,29 @@ class RequestsAdmin( BaseController, UsesFormDefinitionWidgets ): sample_dataset = trans.sa_session.query( trans.app.model.SampleDataset ).get( trans.security.decode_id( sample_dataset_id ) ) sample_datasets.append( sample_dataset ) if params.get( 'rename_datasets_button', False ): + incorrect_dataset_names = [] for sample_dataset in sample_datasets: encoded_id = trans.security.encode_id( sample_dataset.id ) selected_option = util.restore_text( params.get( 'rename_datasets_for_sample_%s' % encoded_id, '' ) ) new_name = util.restore_text( params.get( 'new_name_%s' % encoded_id, '' ) ) + if not new_name: + incorrect_dataset_names.append( sample_dataset.name ) + continue + new_name = util.sanitize_for_filename( new_name ) if selected_option == 'none': sample_dataset.name = new_name else: sample_dataset.name = '%s_%s' % ( selected_option, new_name ) trans.sa_session.add( sample_dataset ) trans.sa_session.flush() - message = 'Changes saved successfully.' + if len( sample_datasets ) == len( incorrect_dataset_names ): + status = 'error' + message = 'All datasets renamed incorrectly.' + elif len( incorrect_dataset_names ): + status = 'done' + message = 'Changes saved successfully. The following datasets were renamed incorrectly: %s.' % str( incorrect_dataset_names ) + else: + message = 'Changes saved successfully.' return trans.fill_template( '/admin/requests/rename_datasets.mako', sample=sample, id_list=id_list, diff --git a/lib/galaxy/web/controllers/requests_common.py b/lib/galaxy/web/controllers/requests_common.py index df8a375aeae..98525981c44 100644 --- a/lib/galaxy/web/controllers/requests_common.py +++ b/lib/galaxy/web/controllers/requests_common.py @@ -1079,7 +1079,7 @@ class RequestsCommon( BaseController, UsesFormDefinitionWidgets ): cntrller=cntrller, action='update_request_state', request_id=trans.security.encode_id( request.id ) ) ) - elif sample_operation == trans.model.sample.bulk_operations.SELECT_LIBRARY: + elif sample_operation == trans.model.Sample.bulk_operations.SELECT_LIBRARY: # TODO: fix the code so that the sample_operation_select_field does not use # sample_0_library_id as it's name. it should use something like sample_operation_library_id # and sample_operation_folder_id because the name sample_0_library_id should belong to the diff --git a/scripts/galaxy_messaging/server/setup_rabbitmq.py b/scripts/galaxy_messaging/server/setup_rabbitmq.py index 9d670ead673..e65ac69233a 100644 --- a/scripts/galaxy_messaging/server/setup_rabbitmq.py +++ b/scripts/galaxy_messaging/server/setup_rabbitmq.py @@ -24,7 +24,7 @@ def main( config_file ): cmd_list = [ 'add_user %s %s' % ( username, password ), - 'add_vhost %s' % config.get( 'galaxy_amqp', 'virtual_host' ), + 'add_vhost %s' % virtual_host, 'set_permissions -p %s %s ".*" ".*" ".*"' % ( virtual_host, username ) ] diff --git a/templates/admin/requests/rename_datasets.mako b/templates/admin/requests/rename_datasets.mako index 4604a297b5f..74f557d9835 100644 --- a/templates/admin/requests/rename_datasets.mako +++ b/templates/admin/requests/rename_datasets.mako @@ -16,6 +16,7 @@
+ @@ -43,9 +44,16 @@

+
+
+ A dataset name should only contain the alphanumeric characters or underscore(_). + If a dataset name contains any other character, it would be replaced by an underscore(_). +
+
+
diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index 5837e4251ce..c9f6ad88e3c 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -1638,6 +1638,23 @@ class TwillTestCase( unittest.TestCase ): tc.submit( "save_samples_button" ) for check_str in strings_displayed_after_submit: self.check_page_for_string( check_str ) + def change_sample_target_data_library( self, cntrller, request_id, sample_ids, new_library_id, new_folder_id, comment='', strings_displayed=[], strings_displayed_after_submit=[] ): + url = "%s/requests_common/edit_samples?cntrller=%s&id=%s&editing_samples=True" % ( self.url, cntrller, request_id ) + self.visit_url( url ) + for check_str in strings_displayed: + self.check_page_for_string( check_str ) + for sample_id in sample_ids: + tc.fv( "1", "select_sample_%i" % sample_id, True ) + tc.fv( "1", "sample_operation", 'Select data library and folder' ) + self.refresh_form( "sample_operation", 'Select data library and folder' ) + self.check_page_for_string( "Select data library:" ) + tc.fv( "1", "sample_0_library_id", new_library_id ) + self.refresh_form( "sample_0_library_id", new_library_id ) + self.check_page_for_string( "Select folder:" ) + tc.fv( "1", "sample_0_folder_id", new_folder_id ) + tc.submit( "save_samples_button" ) + for check_str in strings_displayed_after_submit: + self.check_page_for_string( check_str ) def add_user_address( self, user_id, address_dict ): self.home() self.visit_url( "%s/user/new_address?admin_view=False&user_id=%i" % ( self.url, user_id ) ) diff --git a/test/functional/test_sample_tracking.py b/test/functional/test_sample_tracking.py index da88522a0d6..7fb68b1b495 100644 --- a/test/functional/test_sample_tracking.py +++ b/test/functional/test_sample_tracking.py @@ -430,8 +430,8 @@ class TestFormsAndRequests( TwillTestCase ): """Testing editing the sample information of new request1""" # logged in as regular_user1 # target data library - change it to library1 - target_library_info = dict(library=self.security.encode_id(library1.id), - folder=self.security.encode_id(library1_folder1.id) ) + target_library_info = dict(library=self.security.encode_id( library1.id ), + folder=self.security.encode_id( library1_folder1.id ) ) new_sample_value_tuples = \ [ ( 'Sample1_renamed', target_library_info, [ 'option2', 'sample1 field2 value edited', 'sample1 field3 value edited' ] ), ( 'Sample2_renamed', target_library_info, [ 'option1', 'sample2 field2 value edited', 'sample2 field3 value edited' ] ), @@ -494,6 +494,23 @@ class TestFormsAndRequests( TwillTestCase ): strings_displayed_count=strings_displayed_count, strings_not_displayed=[ request1.states.COMPLETE, request1.states.REJECTED ] ) + # change the target data library back to library2 using sample operation user interface + self.change_sample_target_data_library( cntrller='requests', + request_id=self.security.encode_id( request1.id ), + sample_ids=[ sample.id for sample in request1.samples ], + new_library_id=self.security.encode_id( library2.id ), + new_folder_id=self.security.encode_id( library2_folder1.id ), + strings_displayed=[ 'Edit Current Samples of Sequencing Request "%s"' % request1.name ], + strings_displayed_after_submit=[ 'Changes made to the samples have been saved.' ] ) + # check the changed target data library & folder on the request page + strings_displayed_count = [] + strings_displayed_count.append( ( library2.name, len( request1.samples ) ) ) + strings_displayed_count.append( ( library2_folder1.name, len( request1.samples ) ) ) + self.view_request( cntrller='requests', + request_id=self.security.encode_id( request1.id ), + strings_displayed=[], + strings_displayed_count=strings_displayed_count ) + # # ====== Sequencing request test methods - Admin perspective ================ # @@ -537,7 +554,7 @@ class TestFormsAndRequests( TwillTestCase ): request1.type.states[4].desc ] # check history of each sample for sample in request1.samples: - strings_displayed = [ 'Events for Sample "%s"' % sample.name, + strings_displayed = [ 'History of sample "%s"' % sample.name, 'Sequencing request submitted and sample state set to %s' % request1.type.states[0].name, request1.type.states[0].name, request1.type.states[1].name ]