details: http://www.bx.psu.edu/hg/galaxy/rev/04fa6cbeb28c
changeset: 3395:04fa6cbeb28c
user: Greg Von Kuster <greg(a)bx.psu.edu>
date: Mon Feb 15 16:56:02 2010 -0500
description:
Sort the datasets by name when browsing a library from the Data Libraries view. Add a cleanup method to the functional test script for forms and requests - functional tests for libraries should now pass.
diffstat:
lib/galaxy/model/__init__.py | 20 ++++++++++++++++++--
lib/galaxy/web/controllers/library_admin.py | 11 +++++++----
lib/galaxy/web/controllers/library_common.py | 8 +++++---
test/functional/test_forms_and_requests.py | 17 +++++++++++++++++
test/functional/test_security_and_libraries.py | 5 +++--
5 files changed, 50 insertions(+), 11 deletions(-)
diffs (120 lines):
diff -r eeff3f4f9b81 -r 04fa6cbeb28c lib/galaxy/model/__init__.py
--- a/lib/galaxy/model/__init__.py Mon Feb 15 12:49:23 2010 -0500
+++ b/lib/galaxy/model/__init__.py Mon Feb 15 16:56:02 2010 -0500
@@ -5,7 +5,7 @@
the relationship cardinalities are obvious (e.g. prefer Dataset to Data)
"""
-import os.path, os, errno, sys, codecs
+import os.path, os, errno, sys, codecs, operator
import galaxy.datatypes
from galaxy.util.bunch import Bunch
from galaxy import util
@@ -848,8 +848,24 @@
return []
@property
def active_library_datasets( self ):
+ def sort_by_attr( seq, attr ):
+ """
+ Sort the sequence of objects by object's attribute
+ Arguments:
+ seq - the list or any sequence (including immutable one) of objects to sort.
+ attr - the name of attribute to sort by
+ """
+ # Use the "Schwartzian transform"
+ # Create the auxiliary list of tuples where every i-th tuple has form
+ # (seq[i].attr, i, seq[i]) and sort it. The second item of tuple is needed not
+ # only to provide stable sorting, but mainly to eliminate comparison of objects
+ # (which can be expensive or prohibited) in case of equal attribute values.
+ intermed = map( None, map( getattr, seq, ( attr, ) * len( seq ) ), xrange( len( seq ) ), seq )
+ intermed.sort()
+ return map( operator.getitem, intermed, ( -1, ) * len( intermed ) )
# This needs to be a list
- return [ ld for ld in self.datasets if not ld.library_dataset_dataset_association.deleted ]
+ active_library_datasets = [ ld for ld in self.datasets if not ld.library_dataset_dataset_association.deleted ]
+ return sort_by_attr( [ ld for ld in active_library_datasets ], 'name' )
@property
def activatable_library_datasets( self ):
# This needs to be a list
diff -r eeff3f4f9b81 -r 04fa6cbeb28c lib/galaxy/web/controllers/library_admin.py
--- a/lib/galaxy/web/controllers/library_admin.py Mon Feb 15 12:49:23 2010 -0500
+++ b/lib/galaxy/web/controllers/library_admin.py Mon Feb 15 16:56:02 2010 -0500
@@ -98,10 +98,13 @@
msg = util.restore_text( params.get( 'msg', '' ) )
messagetype = params.get( 'messagetype', 'done' )
if params.get( 'create_library_button', False ):
- library = trans.app.model.Library( name = util.restore_text( params.name ),
- description = util.restore_text( params.description ),
- synopsis = util.restore_text( params.synopsis ) )
- root_folder = trans.app.model.LibraryFolder( name = util.restore_text( params.name ), description = "" )
+ name = util.restore_text( params.get( 'name', 'No name' ) )
+ description = util.restore_text( params.get( 'description', '' ) )
+ synopsis = util.restore_text( params.get( 'synopsis', '' ) )
+ if synopsis in [ 'None', None ]:
+ synopsis = ''
+ library = trans.app.model.Library( name=name, description=description, synopsis=synopsis )
+ root_folder = trans.app.model.LibraryFolder( name=name, description='' )
library.root_folder = root_folder
trans.sa_session.add_all( ( library, root_folder ) )
trans.sa_session.flush()
diff -r eeff3f4f9b81 -r 04fa6cbeb28c lib/galaxy/web/controllers/library_common.py
--- a/lib/galaxy/web/controllers/library_common.py Mon Feb 15 12:49:23 2010 -0500
+++ b/lib/galaxy/web/controllers/library_common.py Mon Feb 15 16:56:02 2010 -0500
@@ -137,13 +137,15 @@
show_deleted = util.string_as_bool( params.get( 'show_deleted', False ) )
if params.get( 'rename_library_button', False ):
old_name = library.name
- new_name = util.restore_text( params.name )
- new_description = util.restore_text( params.description )
- new_synopsis = util.restore_text( params.synopsis )
+ new_name = util.restore_text( params.get( 'name', 'No name' ) )
if not new_name:
msg = 'Enter a valid name'
messagetype='error'
else:
+ new_description = util.restore_text( params.get( 'description', '' ) )
+ new_synopsis = util.restore_text( params.get( 'synopsis', '' ) )
+ if new_synopsis in [ None, 'None' ]:
+ new_synopsis = ''
library.name = new_name
library.description = new_description
library.synopsis = new_synopsis
diff -r eeff3f4f9b81 -r 04fa6cbeb28c test/functional/test_forms_and_requests.py
--- a/test/functional/test_forms_and_requests.py Mon Feb 15 12:49:23 2010 -0500
+++ b/test/functional/test_forms_and_requests.py Mon Feb 15 16:56:02 2010 -0500
@@ -312,3 +312,20 @@
# check if the request's state is now set to 'submitted'
assert request_two.state is not request_two.states.REJECTED, "The state of the request '%s' should be set to '%s'" \
% ( request_two.name, request_two.states.REJECTED )
+ def test_050_reset_data_for_later_test_runs( self ):
+ """Reseting data to enable later test runs to pass"""
+ # TODO: RC: add whatever is missing from this method that should be marked
+ # deleted or purged so that later test runs will correctly test features if the
+ # database has not be purged.
+ #
+ # Logged in as admin_user
+ ##################
+ # Eliminate all non-private roles
+ ##################
+ for role in [ role_one ]:
+ self.mark_role_deleted( self.security.encode_id( role.id ), role.name )
+ self.purge_role( self.security.encode_id( role.id ), role.name )
+ # Manually delete the role from the database
+ sa_session.refresh( role )
+ sa_session.delete( role )
+ sa_session.flush()
diff -r eeff3f4f9b81 -r 04fa6cbeb28c test/functional/test_security_and_libraries.py
--- a/test/functional/test_security_and_libraries.py Mon Feb 15 12:49:23 2010 -0500
+++ b/test/functional/test_security_and_libraries.py Mon Feb 15 16:56:02 2010 -0500
@@ -113,8 +113,9 @@
.first()
# Make sure DatasetPermissions is correct - default is 'manage permissions'
if len( latest_dataset.actions ) > 1:
- raise AssertionError( '%d DatasetPermissions were created for dataset id %d when it was created ( should have been 1 )' \
- % ( len( latest_dataset.actions ), latest_dataset.id ) )
+ actions = [ a.action for a in latest_dataset.actions ]
+ raise AssertionError( '%d DatasetPermissions (%s) were created for dataset id %d when it was created ( should have been 1 )' \
+ % ( len( latest_dataset.actions ), str( actions ), latest_dataset.id ) )
dp = sa_session.query( galaxy.model.DatasetPermissions ) \
.filter( galaxy.model.DatasetPermissions.table.c.dataset_id==latest_dataset.id ) \
.first()