diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py
index d361c08aa39..ef0ccecb703 100644
--- a/test/base/twilltestcase.py
+++ b/test/base/twilltestcase.py
@@ -626,56 +626,51 @@ class TwillTestCase( unittest.TestCase ):
tc.submit( "reset_user_password_button" )
self.check_page_for_string( "Password reset" )
self.home()
- def mark_user_deleted( self, user_id=4 ):
+ def mark_user_deleted( self, user_id=4, email='' ):
"""Mark a user as deleted"""
self.home()
self.visit_url( "%s/admin/mark_user_deleted?user_id=%s" % ( self.url, str( user_id ) ) )
- self.check_page_for_string( "The user has been marked as deleted." )
+ check_str = "User '%s' has been marked as deleted." % email
+ self.check_page_for_string( check_str )
self.home()
- def undelete_user( self, user_id ):
+ def undelete_user( self, user_id=4, email='' ):
"""Undelete a user"""
self.home()
self.visit_url( "%s/admin/undelete_user?user_id=%s" % ( self.url, user_id ) )
- self.check_page_for_string( 'The user has been marked as not deleted' )
+ check_str = "User '%s' has been marked as not deleted" % email
+ self.check_page_for_string( check_str )
self.home()
- def purge_user( self, user_id ):
+ def purge_user( self, user_id, email ):
"""Purge a user account"""
self.home()
self.visit_url( "%s/admin/purge_user?user_id=%s" % ( self.url, user_id ) )
- self.check_page_for_string( 'The user has been marked as purged.' )
+ check_str = "User '%s' has been marked as purged." % email
+ self.check_page_for_string( check_str )
self.home()
- def user_roles_edit( self, user_id, role_ids=[] ):
- """Change roles associated with an existing user"""
+ def associate_roles_and_groups_with_user( self, user_id, email, role_ids=[], group_ids=[] ):
self.home()
- self.visit_url( "%s/admin/user_roles_edit?user_id=%s" % ( self.url, user_id ) )
- self.check_page_for_string( 'Select to associate role with' )
- for role_id in role_ids:
- tc.fv( "1", "roles", role_id )
- tc.submit( "user_roles_edit_button" )
- self.check_page_for_string( 'User updated with a total of' )
+ url = "%s/admin/user?user_id=%s&user_roles_groups_edit_button=Save" % ( self.url, user_id )
+ if role_ids:
+ url += "&in_roles=%s" % ','.join( role_ids )
+ if group_ids:
+ url += "&in_groups=%s" % ','.join( group_ids )
+ self.visit_url( url )
+ check_str = "User '%s' has been updated with %d associated roles and %d associated groups" % ( email, len( role_ids ), len( group_ids ) )
+ self.check_page_for_string( check_str )
self.home()
# Tests associated with roles
- def create_role( self, name='Role One', description="This is Role One", user_ids=[], group_ids=[], private_role='' ):
+ def create_role( self, name='Role One', description="This is Role One", in_user_ids=[], in_group_ids=[], private_role='' ):
"""Create a new role"""
+ url = "%s/admin/create_role?create_role_button=Save&name=%s&description=%s" % ( self.url, name.replace( ' ', '+' ), description.replace( ' ', '+' ) )
+ if in_user_ids:
+ url += "&in_users=%s" % ','.join( in_user_ids )
+ if in_group_ids:
+ url += "&in_groups=%s" % ','.join( in_group_ids )
self.home()
- self.visit_url( "%s/admin/create_role" % self.url )
- self.check_page_for_string( "Create Role" )
- tc.fv( "1", "name", name )
- tc.fv( "1", "description", description )
- for user_id in user_ids:
- tc.fv( "1", "users", user_id )
- for group_id in group_ids:
- tc.fv( "1", "groups", group_id )
- tc.submit( "create_role_button" )
- check_str = "The new role has been created with %s associated users and %s associated groups" % ( str( len( user_ids ) ), str( len( group_ids ) ) )
- try:
- self.check_page_for_string( check_str )
- previously_created = False
- except:
- # The role may have been created on a previous test run
- self.check_page_for_string( "A role with that name already exists" )
- previously_created = True
+ self.visit_url( url )
+ check_str = "Role '%s' has been created with %d associated users and %d associated groups" % ( name, len( in_user_ids ), len( in_group_ids ) )
+ self.check_page_for_string( check_str )
if private_role:
# Make sure no private roles are displayed
try:
@@ -686,10 +681,9 @@ class TwillTestCase( unittest.TestCase ):
# Reaching here is the behavior we want since no private roles should be displayed
pass
self.home()
- self.visit_page( "admin/roles" )
- self.check_page_for_string( description )
+ self.visit_url( "%s/admin/roles" % self.url )
+ self.check_page_for_string( name )
self.home()
- return previously_created
def rename_role( self, role_id, name='Role One Renamed', description='This is Role One Re-described' ):
"""Rename a role"""
self.home()
@@ -699,82 +693,56 @@ class TwillTestCase( unittest.TestCase ):
tc.fv( "1", "description", description )
tc.submit( "rename_role_button" )
self.home()
- def mark_role_deleted( self, role_id ):
+ def mark_role_deleted( self, role_id, role_name ):
"""Mark a role as deleted"""
self.home()
self.visit_url( "%s/admin/mark_role_deleted?role_id=%s" % ( self.url, role_id ) )
- self.check_page_for_string( 'The role has been marked as deleted' )
+ check_str = "Role '%s' has been marked as deleted" % role_name
+ self.check_page_for_string( check_str )
self.home()
- def undelete_role( self, role_id ):
+ def undelete_role( self, role_id, role_name ):
"""Undelete an existing role"""
self.home()
self.visit_url( "%s/admin/undelete_role?role_id=%s" % ( self.url, role_id ) )
- self.check_page_for_string( 'The role has been marked as not deleted' )
+ check_str = "Role '%s' has been marked as not deleted" % role_name
+ self.check_page_for_string( check_str )
self.home()
- def purge_role( self, role_id ):
+ def purge_role( self, role_id, role_name ):
"""Purge an existing role"""
self.home()
self.visit_url( "%s/admin/purge_role?role_id=%s" % ( self.url, role_id ) )
- check_str = "The following have been purged from the database for the role: "
+ check_str = "The following have been purged from the database for role '%s': " % role_name
check_str += "DefaultUserPermissions, DefaultHistoryPermissions, UserRoleAssociations, GroupRoleAssociations, ActionDatasetRoleAssociations."
self.check_page_for_string( check_str )
self.home()
- def associate_groups_with_role( self, role_id, group_names=[] ):
- """Add groups to an existing role"""
- # NOTE: To get this to work with twill, all select lists must contain at least 1 option value
- # before tc.submit or twill throws an exception, which is: ParseError: OPTION outside of SELECT
+ def associate_users_and_groups_with_role( self, role_id, role_name, user_ids=[], group_ids=[] ):
self.home()
- self.visit_url( "%s/admin/role?role_id=%s" % ( self.url, role_id ) )
- self.check_page_for_string( 'Groups associated with' )
- # All group_ids passed in MUST be in the out_groups form field
- for group_name in group_names:
- tc.fv( "1", "out_groups", group_name ) # note the buttons...
- tc.submit( "groups_add_button" )
- tc.submit( "role_members_edit_button" )
+ url = "%s/admin/role?role_id=%s&role_members_edit_button=Save" % ( self.url, role_id )
+ if user_ids:
+ url += "&in_users=%s" % ','.join( user_ids )
+ if group_ids:
+ url += "&in_groups=%s" % ','.join( group_ids )
+ self.visit_url( url )
+ check_str = "Role '%s' has been updated with %d associated users and %d associated groups" % ( role_name, len( user_ids ), len( group_ids ) )
+ self.check_page_for_string( check_str )
self.home()
- def associate_users_with_role( self, role_id, user_emails=[] ):
- """Add a users to an existing role"""
- # NOTE: To get this to work with twill, all select lists must contain at least 1 option value
- # before tc.submit or twill throws an exception, which is: ParseError: OPTION outside of SELECT
- self.home()
- self.visit_url( "%s/admin/role?role_id=%s" % ( self.url, role_id ) )
- self.check_page_for_string( 'Users associated with' )
- for user_email in user_emails:
- tc.fv( "1", "out_users", user_email )
- tc.submit( "users_add_button" )
- tc.submit( "role_members_edit_button" )
- self.home()
-
+
# Tests associated with groups
- def create_group( self, name='Group One', user_ids=[], role_ids=[] ):
- """Create a new group with members and associated role"""
+ def create_group( self, name='Group One', in_user_ids=[], in_role_ids=[] ):
+ """Create a new group"""
+ url = "%s/admin/create_group?create_group_button=Save&name=%s" % ( self.url, name.replace( ' ', '+' ) )
+ if in_user_ids:
+ url += "&in_users=%s" % ','.join( in_user_ids )
+ if in_role_ids:
+ url += "&in_roles=%s" % ','.join( in_role_ids )
self.home()
- self.visit_url( "%s/admin/create_group" % self.url )
- self.check_page_for_string( "Create Group" )
- # Make sure no private roles are displayed
- try:
- self.check_page_for_string( 'Private Role for' )
- raise AssertionError( 'Private role displayed on Create Group page' )
- except AssertionError:
- # Reaching here is the behavior we want since no private roles should be displayed
- pass
- tc.fv( "1", "name", name )
- for user_id in user_ids:
- tc.fv( "1", "members", user_id )
- for role_id in role_ids:
- tc.fv( "1", "roles", role_id )
- tc.submit( "create_group_button" )
- try:
- self.check_page_for_string( "The new group has been created" )
- previously_created = False
- except:
- self.check_page_for_string( "A group with that name already exists" )
- previously_created = True
+ self.visit_url( url )
+ check_str = "Group '%s' has been created with %d associated users and %d associated roles" % ( name, len( in_user_ids ), len( in_role_ids ) )
+ self.check_page_for_string( check_str )
self.home()
- self.visit_page( "admin/groups" )
+ self.visit_url( "%s/admin/groups" % self.url )
self.check_page_for_string( name )
self.home()
- return previously_created
def rename_group( self, group_id, name='Group One Renamed' ):
"""Rename a group"""
self.home()
@@ -783,63 +751,60 @@ class TwillTestCase( unittest.TestCase ):
tc.fv( "1", "name", name )
tc.submit( "rename_group_button" )
self.home()
- def group_members_edit( self, group_id, user_ids=[] ):
- """Add members to an existing group"""
+ def associate_users_and_roles_with_group( self, group_id, group_name, user_ids=[], role_ids=[] ):
self.home()
- self.visit_url( "%s/admin/group_members_edit?group_id=%s" % ( self.url, group_id ) )
- self.check_page_for_string( 'Select to add user to' )
- for user_id in user_ids:
- tc.fv( "1", "members", user_id )
- tc.submit( "group_members_edit_button" )
- self.check_page_for_string( 'Group membership has been updated' )
+ url = "%s/admin/group?group_id=%s&group_roles_users_edit_button=Save" % ( self.url, group_id )
+ if user_ids:
+ url += "&in_users=%s" % ','.join( user_ids )
+ if role_ids:
+ url += "&in_roles=%s" % ','.join( role_ids )
+ self.visit_url( url )
+ check_str = "Group '%s' has been updated with %d associated roles and %d associated users" % ( group_name, len( role_ids ), len( user_ids ) )
+ self.check_page_for_string( check_str )
self.home()
- def group_roles_edit( self, group_id, role_ids=[] ):
- """Change roles associated with an existing group"""
- self.home()
- self.visit_url( "%s/admin/group_roles_edit?group_id=%s" % ( self.url, group_id ) )
- self.check_page_for_string( 'Select to associate role with' )
- for role_id in role_ids:
- tc.fv( "1", "roles", role_id )
- tc.submit( "group_roles_edit_button" )
- self.check_page_for_string( 'Group updated with a total of' )
- self.home()
- def mark_group_deleted( self, group_id ):
+ def mark_group_deleted( self, group_id, group_name ):
"""Mark a group as deleted"""
self.home()
self.visit_url( "%s/admin/mark_group_deleted?group_id=%s" % ( self.url, group_id ) )
- self.check_page_for_string( 'The group has been marked as deleted' )
+ check_str = "Group '%s' has been marked as deleted" % group_name
+ self.check_page_for_string( check_str )
self.home()
- def undelete_group( self, group_id ):
+ def undelete_group( self, group_id, group_name ):
"""Undelete an existing group"""
self.home()
self.visit_url( "%s/admin/undelete_group?group_id=%s" % ( self.url, group_id ) )
- self.check_page_for_string( 'The group has been marked as not deleted' )
+ check_str = "Group '%s' has been marked as not deleted" % group_name
+ self.check_page_for_string( check_str )
self.home()
- def purge_group( self, group_id ):
+ def purge_group( self, group_id, group_name ):
"""Purge an existing group"""
self.home()
self.visit_url( "%s/admin/purge_group?group_id=%s" % ( self.url, group_id ) )
- self.check_page_for_string( "The following have been purged from the database for the group: UserGroupAssociations, GroupRoleAssociations." )
+ check_str = "The following have been purged from the database for group '%s': UserGroupAssociations, GroupRoleAssociations." % group_name
+ self.check_page_for_string( check_str )
self.home()
# Utility methods to test removal of associations
- def remove_role_from_group( self, role_id, group_id ):
+ def remove_role_from_group( self, role_id, role_name, group_id, group_name ):
"""Remove a role from a group"""
self.home()
self.visit_url( "%s/admin/remove_role_from_group?role_id=%s&group_id=%s" % ( self.url, role_id, group_id ) )
- self.check_page_for_string( 'Role removed from group' )
+ check_str = "Role '%s' removed from group '%s'" % ( role_name, group_name )
+ self.check_page_for_string( check_str )
self.home()
- def remove_user_from_group( self, user_id, group_id ):
+ def remove_user_from_group( self, user_id, email, group_id, group_name ):
"""Remove a user from a group"""
self.home()
self.visit_url( "%s/admin/remove_user_from_group?user_id=%s&group_id=%s" % ( self.url, user_id, group_id ) )
- self.check_page_for_string( 'User removed from group' )
+ check_str = "User '%s' removed from group '%s'" % ( email, group_name )
+ self.check_page_for_string( check_str )
self.home()
- def remove_user_from_role( self, user_id, role_id ):
+ def remove_user_from_role( self, user_id, email, role_id, role_name ):
"""Remove a user from a role"""
self.home()
self.visit_url( "%s/admin/remove_user_from_role?user_id=%s&role_id=%s" % ( self.url, user_id, role_id ) )
- self.check_page_for_string( 'User removed from role' )
+ check_str = "User '%s' removed from role '%s'" % ( email, role_name )
+ self.check_page_for_string( check_str )
self.home()
# Library stuff
@@ -921,25 +886,28 @@ class TwillTestCase( unittest.TestCase ):
library_dir = "%s" % self.file_dir
tc.fv( "1", "server_dir", "library" )
for role_tuple in roles_tuple:
- tc.fv( "1", "roles", role_tuple[1] ) # role_tuple[1] is the role description
+ tc.fv( "1", "roles", role_tuple[1] ) # role_tuple[1] is the role name
tc.submit( "new_dataset_button" )
self.check_page_for_string( '3 new datasets added to the library' )
self.home()
- def mark_library_deleted( self, library_id ):
+ def mark_library_deleted( self, library_id, library_name ):
"""Mark a library as deleted"""
self.home()
self.visit_url( "%s/admin/library?id=%s&delete=True" % ( self.url, library_id ) )
- self.check_page_for_string( 'The library and all of its contents have been marked deleted' )
+ check_str = "Library '%s' and all of its contents have been marked deleted" % library_name
+ self.check_page_for_string( check_str )
self.home()
- def undelete_library( self, library_id ):
+ def undelete_library( self, library_id, library_name ):
"""Mark a library as not deleted"""
self.home()
self.visit_url( "%s/admin/undelete_library?id=%s" % ( self.url, library_id ) )
- self.check_page_for_string( 'The library and all of its contents have been marked not deleted' )
+ check_str = "Library '%s' and all of its contents have been marked not deleted" % library_name
+ self.check_page_for_string( check_str )
self.home()
- def purge_library( self, library_id ):
+ def purge_library( self, library_id, library_name ):
"""Purge a library"""
self.home()
self.visit_url( "%s/admin/purge_library?id=%s" % ( self.url, library_id ) )
- self.check_page_for_string( 'The library and all of its contents have been purged' )
+ check_str = "Library '%s' and all of its contents have been purged" % library_name
+ self.check_page_for_string( check_str )
self.home()
diff --git a/test/functional/test_security_and_libraries.py b/test/functional/test_security_and_libraries.py
index e66a2248515..693769ad24f 100644
--- a/test/functional/test_security_and_libraries.py
+++ b/test/functional/test_security_and_libraries.py
@@ -17,7 +17,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.check_page_for_string( not_logged_in_security_msg )
self.visit_url( "%s/admin/create_role" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
- self.visit_url( "%s/admin/new_role" % self.url )
+ self.visit_url( "%s/admin/create_role" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
self.visit_url( "%s/admin/role" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
@@ -25,7 +25,6 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.check_page_for_string( not_logged_in_security_msg )
self.visit_url( "%s/admin/create_group" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
- self.visit_url( "%s/admin/group_members_edit?group_id=0" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
self.visit_url( "%s/admin/users" % self.url )
self.check_page_for_string( not_logged_in_security_msg )
@@ -281,30 +280,24 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.reset_password_as_admin( user_id=regular_user3.id, password='testuser' )
def test_035_mark_user_deleted( self ):
"""Testing marking a user account as deleted"""
- self.mark_user_deleted( user_id=regular_user3.id )
+ self.mark_user_deleted( user_id=regular_user3.id, email=regular_user3.email )
# Deleting a user should not delete any associations
regular_user3.refresh()
if not regular_user3.active_histories:
raise AssertionError( 'HistoryDatasetAssociations for regular_user3 were incorrectly deleted when the user was marked deleted' )
def test_040_undelete_user( self ):
"""Testing undeleting a user account"""
- self.undelete_user( user_id=regular_user3.id )
+ self.undelete_user( user_id=regular_user3.id, email=regular_user3.email )
def test_045_create_role( self ):
"""Testing creating new role with 3 members, then renaming it"""
name = 'Role One'
- description = "This is Role One's description"
+ description = "This is Role Ones description"
user_ids=[ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
- previously_created = self.create_role( name=name, description=description, user_ids=user_ids, private_role=admin_user.email )
+ self.create_role( name=name, description=description, in_user_ids=user_ids, in_group_ids=[], private_role=admin_user.email )
# Get the role object for later tests
global role_one
role_one = galaxy.model.Role.filter( galaxy.model.Role.table.c.name==name ).first()
assert role_one is not None, 'Problem retrieving role named "Role One" from the database'
- if previously_created:
- # Since the role was created in a previous test run, we need to associate the required users with it
- role_ids = [ str( role_one.id ) ]
- for user_id in user_ids:
- self.user_roles_edit( user_id, role_ids=role_ids )
- role_one.refresh()
# Make sure UserRoleAssociations are correct
if len( role_one.users ) != len( user_ids ):
raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created ( should have been %d )' \
@@ -312,13 +305,13 @@ class TestSecurityAndLibraries( TwillTestCase ):
# Each of the following users should now have 3 role associations, their private role, role_one and sharing_role
for user in [ admin_user, regular_user1 ]:
user.refresh()
- if not previously_created and len( user.roles ) != 3:
+ if len( user.roles ) != 3:
raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 3 )' \
% ( len( user.roles ), user.email ) )
# Each of the following users should now have 2 role associations, their private role and role_one
for user in [ regular_user3 ]:
user.refresh()
- if not previously_created and len( user.roles ) != 2:
+ if len( user.roles ) != 2:
raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 2 )' \
% ( len( user.roles ), user.email ) )
# Rename the role
@@ -336,15 +329,11 @@ class TestSecurityAndLibraries( TwillTestCase ):
name = "Group One's Name"
user_ids=[ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
role_ids=[ str( role_one.id ) ]
- previously_created = self.create_group( name=name, user_ids=user_ids, role_ids=role_ids )
+ self.create_group( name=name, in_user_ids=user_ids, in_role_ids=role_ids )
# Get the group object for later tests
global group_one
group_one = galaxy.model.Group.filter( galaxy.model.Group.table.c.name==name ).first()
assert group_one is not None, 'Problem retrieving group named "Group One" from the database'
- if previously_created:
- # group_one was created during a previous test run, so create associations
- self.group_members_edit( str( group_one.id ), user_ids=user_ids )
- self.group_roles_edit( str( group_one.id ), role_ids=role_ids )
# Make sure UserGroupAssociations are correct
if len( group_one.users ) != len( user_ids ):
raise AssertionError( '%d UserGroupAssociations were created for group id %d when it was created ( should have been %d )' \
@@ -369,7 +358,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
def test_055_add_members_and_role_to_group( self ):
"""Testing editing user membership and role associations of an existing group"""
name = 'Group Two'
- previously_created = self.create_group( name=name, user_ids=[], role_ids=[] )
+ self.create_group( name=name, in_user_ids=[], in_role_ids=[] )
# Get the group object for later tests
global group_two
group_two = galaxy.model.Group.filter( galaxy.model.Group.table.c.name==name ).first()
@@ -383,58 +372,25 @@ class TestSecurityAndLibraries( TwillTestCase ):
% ( len( group_two.roles ), group_two.id ) )
group_two_id = str( group_two.id )
user_ids = [ str( regular_user1.id ) ]
- # Add users to group_two based on user_ids
- self.group_members_edit( group_two_id, user_ids=user_ids )
- self.home()
- self.visit_url( "%s/admin/group_members_edit?group_id=%s" % ( self.url, group_two_id ) )
- # Make sure UserGroupAssociations are correct
- check_str = '%s currently has %d members' % ( name, len( user_ids ) )
- self.check_page_for_string( check_str )
role_ids = [ str( role_one.id ) ]
- # Associate roles with group_two based on roles_ids
- self.group_roles_edit( group_two_id, role_ids=role_ids )
- self.home()
- self.visit_url( "%s/admin/group_roles_edit?group_id=%s" % ( self.url, group_two_id ) )
- # Make sure GroupRoleAssociation are correct
- check_str = '%s is currently associated with %d roles' % ( name, len( role_ids ) )
- self.check_page_for_string( check_str )
- # Create another group -needed for the following test
- name = 'Group Three'
- previously_created = self.create_group( name=name, user_ids=[], role_ids=[] )
- # Get the group object for later tests
- global group_three
- group_three = galaxy.model.Group.filter( galaxy.model.Group.table.c.name==name ).first()
- assert group_three is not None, 'Problem retrieving group named "Group Three" from the database'
- group_three_id = str( group_three.id )
+ self.associate_users_and_roles_with_group( group_two.id, group_two.name, user_ids=user_ids, role_ids=role_ids )
def test_060_create_role_with_user_and_group_associations( self ):
"""Testing creating a role with user and group associations"""
# NOTE: To get this to work with twill, all select lists on the ~/admin/role page must contain at least
# 1 option value or twill throws an exception, which is: ParseError: OPTION outside of SELECT
- # Due to this bug in twill, we create the role, associating it with at least 1 user and 1 group. We
- # also must ensure that each of the form fields will contain at least 1 value prior to submitting the form,
- # so we had to create group_three in the previous test
+ # Due to this bug in twill, we create the role, we bypass the page and visit the URL in the
+ # associate_users_and_groups_with_role() method.
name = 'Role Two'
description = 'This is Role Two'
user_ids=[ str( admin_user.id ) ]
group_ids=[ str( group_two.id ) ]
private_role=admin_user.email
- # STEP 1: create the role
- previously_created = self.create_role( name=name,
- description=description,
- user_ids=user_ids,
- group_ids=group_ids,
- private_role=private_role )
+ # Create the role
+ self.create_role( name=name, description=description, in_user_ids=user_ids, in_group_ids=group_ids, private_role=private_role )
# Get the role object for later tests
global role_two
role_two = galaxy.model.Role.filter( galaxy.model.Role.table.c.name==name ).first()
assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
- if previously_created:
- # role_two was created during a previous test run, so create associations
- user_id = user_ids[0]
- role_ids = [ str( role_two.id) ]
- self.user_roles_edit( user_id, role_ids=role_ids )
- group_id = group_ids[0]
- self.group_roles_edit( group_id, role_ids=role_ids )
# Make sure UserRoleAssociations are correct
if len( role_two.users ) != len( user_ids ):
raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created with %d members' \
@@ -452,12 +408,6 @@ class TestSecurityAndLibraries( TwillTestCase ):
group_two.refresh()
if len( group_two.roles ) != 2:
raise AssertionError( '%d GroupRoleAssociations are associated with group id %d ( should be 2 )' % ( len( group_two.roles ), group_two.id ) )
- # STEP 2: associate the role with a group not yet associated
- # TODO: Twill throws an exception on this...
- #group_names = [ group_one.name ]
- #self.associate_groups_with_role( str( role_two.id ), group_names=group_names )
- #self.visit_page( 'admin/roles' )
- #self.check_page_for_string( group_one.name )
def test_065_change_user_role_associations( self ):
"""Testing changing roles associated with a user"""
# Create a new role with no associations
@@ -466,18 +416,21 @@ class TestSecurityAndLibraries( TwillTestCase ):
user_ids=[]
group_ids=[]
private_role=admin_user.email
- previously_created = self.create_role( name=name,
- description=description,
- user_ids=user_ids,
- group_ids=group_ids,
- private_role=private_role )
+ self.create_role( name=name, description=description, in_user_ids=user_ids, in_group_ids=group_ids, private_role=private_role )
# Get the role object for later tests
global role_three
role_three = galaxy.model.Role.filter( galaxy.model.Role.table.c.name==name ).first()
assert role_three is not None, 'Problem retrieving role named "Role Three" from the database'
# Associate the role with a user
- role_ids = [ str( role_three.id ) ]
- self.user_roles_edit( str( admin_user.id ), role_ids=role_ids )
+ admin_user.refresh()
+ role_ids = []
+ for ura in admin_user.non_private_roles:
+ role_ids.append( str( ura.role_id ) )
+ role_ids.append( str( role_three.id ) )
+ group_ids = []
+ for uga in admin_user.groups:
+ group_ids.append( str( uga.group_id ) )
+ self.associate_roles_and_groups_with_user( str( admin_user.id ), str( admin_user.email ), role_ids=role_ids, group_ids=group_ids )
admin_user.refresh()
# admin_user should now be associated with 5 roles: private, role_one, role_two, role_three and sharing_role
if len( admin_user.roles ) != 5:
@@ -742,7 +695,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
str( adra.action ) )
def test_115_add_datasets_from_library_dir( self ):
"""Testing adding 3 datasets from a library directory to a folder"""
- roles_tuple = [ ( str( role_one.id ), role_one.description ) ]
+ roles_tuple = [ ( str( role_one.id ), role_one.name ) ]
self.add_datasets_from_library_dir( str( folder_one.id ), roles_tuple=roles_tuple )
def test_120_change_permissions_on_datasets_imported_from_library( self ):
"""Testing changing the permissions on library datasets imported into a history"""
@@ -833,7 +786,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.home()
self.visit_url( '%s/admin/groups' % self.url )
self.check_page_for_string( group_two.name )
- self.mark_group_deleted( str( group_two.id ) )
+ self.mark_group_deleted( str( group_two.id ), group_two.name )
group_two.refresh()
if not group_two.deleted:
raise AssertionError( '%s was not correctly marked as deleted.' % group_two.name )
@@ -844,7 +797,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
raise AssertionError( '%s incorrectly lost all role associations when it was marked as deleted.' % group_two.name )
def test_130_undelete_group( self ):
"""Testing undeleting a deleted group"""
- self.undelete_group( str( group_two.id ) )
+ self.undelete_group( str( group_two.id ), group_two.name )
group_two.refresh()
if group_two.deleted:
raise AssertionError( '%s was not correctly marked as not deleted.' % group_two.name )
@@ -853,7 +806,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.home()
self.visit_url( '%s/admin/roles' % self.url )
self.check_page_for_string( role_two.name )
- self.mark_role_deleted( str( role_two.id ) )
+ self.mark_role_deleted( str( role_two.id ), role_two.name )
role_two.refresh()
if not role_two.deleted:
raise AssertionError( '%s was not correctly marked as deleted.' % role_two.name )
@@ -864,10 +817,10 @@ class TestSecurityAndLibraries( TwillTestCase ):
raise AssertionError( '%s incorrectly lost all group associations when it was marked as deleted.' % role_two.name )
def test_140_undelete_role( self ):
"""Testing undeleting a deleted role"""
- self.undelete_role( str( role_two.id ) )
+ self.undelete_role( str( role_two.id ), role_two.name )
def test_145_mark_library_deleted( self ):
"""Testing marking a library as deleted"""
- self.mark_library_deleted( str( library_one.id ) )
+ self.mark_library_deleted( str( library_one.id ), library_one.name )
# Make sure the library was deleted
library_one.refresh()
if not library_one.deleted:
@@ -893,7 +846,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
check_folder( library_one.root_folder )
def test_150_undelete_library( self ):
"""Testing marking a library as not deleted"""
- self.undelete_library( str( library_one.id ) )
+ self.undelete_library( str( library_one.id ), library_one.name )
# Make sure the library is undeleted
library_one.refresh()
if library_one.deleted:
@@ -917,7 +870,7 @@ class TestSecurityAndLibraries( TwillTestCase ):
raise AssertionError( 'The dataset with id "%s" has not been marked as undeleted.' % lfda.dataset.id )
check_folder( library_one.root_folder )
# Mark library as deleted again so we can test purging it
- self.mark_library_deleted( str( library_one.id ) )
+ self.mark_library_deleted( str( library_one.id ), library_one.name )
# Make sure the library is deleted again
library_one.refresh()
if not library_one.deleted:
@@ -925,8 +878,8 @@ class TestSecurityAndLibraries( TwillTestCase ):
( str( library_one.id ), library_one.name ) )
def test_155_purge_user( self ):
"""Testing purging a user account"""
- self.mark_user_deleted( user_id=regular_user3.id )
- self.purge_user( user_id=regular_user3.id )
+ self.mark_user_deleted( user_id=regular_user3.id, email=regular_user3.email )
+ self.purge_user( str( regular_user3.id ), regular_user3.email )
regular_user3.refresh()
if not regular_user3.purged:
raise AssertionError( 'User %s was not marked as purged.' % regular_user3.email )
@@ -979,8 +932,8 @@ class TestSecurityAndLibraries( TwillTestCase ):
def test_165_purge_group( self ):
"""Testing purging a group"""
group_id = str( group_two.id )
- self.mark_group_deleted( group_id )
- self.purge_group( group_id )
+ self.mark_group_deleted( group_id, group_two.name )
+ self.purge_group( group_id, group_two.name )
# Make sure there are no UserGroupAssociations
uga = galaxy.model.UserGroupAssociation.filter( galaxy.model.UserGroupAssociation.table.c.group_id == group_id ).all()
if uga:
@@ -990,12 +943,12 @@ class TestSecurityAndLibraries( TwillTestCase ):
if gra:
raise AssertionError( "Purging the group did not delete the GroupRoleAssociations for group_id '%s'" % group_id )
# Undelete the group for later test runs
- self.undelete_group( group_id )
+ self.undelete_group( group_id, group_two.name )
def test_170_purge_role( self ):
"""Testing purging a role"""
role_id = str( role_two.id )
- self.mark_role_deleted( role_id )
- self.purge_role( role_id )
+ self.mark_role_deleted( role_id, role_two.name )
+ self.purge_role( role_id, role_two.name )
# Make sure there are no UserRoleAssociations
uras = galaxy.model.UserRoleAssociation.filter( galaxy.model.UserRoleAssociation.table.c.role_id == role_id ).all()
if uras:
@@ -1022,10 +975,10 @@ class TestSecurityAndLibraries( TwillTestCase ):
# TODO: If we decide to implement the GUI feature for un-purging a role, replace this with a method call
role_two.purged = False
role_two.flush()
- self.undelete_role( str( role_two.id ) )
+ self.undelete_role( str( role_two.id ), role_two.name )
def test_180_purge_library( self ):
"""Testing purging a library"""
- self.purge_library( str( library_one.id ) )
+ self.purge_library( str( library_one.id ), library_one.name )
# Make sure the library was purged
library_one.refresh()
if not library_one.purged:
@@ -1053,22 +1006,34 @@ class TestSecurityAndLibraries( TwillTestCase ):
def test_185_reset_data_for_later_test_runs( self ):
"""Reseting data to enable later test runs to pass"""
##################
- # Reset admin_user
+ # Eliminate all non-private roles
##################
- # Eliminate all role associations except private
- self.remove_user_from_role( str( admin_user.id ), str( role_one.id ) )
- self.remove_user_from_role( str( admin_user.id ), str( role_three.id ) )
- self.remove_user_from_role( str( admin_user.id ), str( sharing_role.id ) )
- admin_user.refresh()
- if len( admin_user.roles) != 1:
- raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( admin_user.roles ), admin_user.email ) )
- # Eliminate all group associations
- self.remove_user_from_group( str( admin_user.id ), str( group_one.id ) )
- admin_user.refresh()
- if admin_user.groups:
- raise AssertionError( '%d UserGroupAssociations are associated with %s ( should be 0 )' % ( len( admin_user.groups ), admin_user.email ) )
+ for role in [ role_one, role_two, role_three, sharing_role ]:
+ self.mark_role_deleted( str( role.id ), role.name )
+ self.purge_role( str( role.id ), role.name )
+ # Manually delete the role from the database
+ role.refresh()
+ role.delete()
+ role.flush()
+ ##################
+ # Eliminate all groups
+ ##################
+ for group in [ group_one, group_two ]:
+ self.mark_group_deleted( str( group.id ), group.name )
+ self.purge_group( str( group.id ), group.name )
+ # Manually delete the group from the database
+ group.refresh()
+ group.delete()
+ group.flush()
+ ##################
+ # Make sure all users are associated only with their private roles
+ ##################
+ for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
+ user.refresh()
+ if len( user.roles) != 1:
+ raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )
#####################
- # Reset regular_user1
+ # Reset DefaultHistoryPermissions for regular_user1
#####################
self.logout()
self.login( email='test1@bx.psu.edu' )
@@ -1079,28 +1044,3 @@ class TestSecurityAndLibraries( TwillTestCase ):
self.user_set_default_permissions( permissions_in=permissions_in, permissions_out=permissions_out, role_id=role_id )
self.logout()
self.login( email='test@bx.psu.edu' )
- # Eliminate all role associations except private
- self.remove_user_from_role( str( regular_user1.id ), str( role_one.id ) )
- self.remove_user_from_role( str( regular_user1.id ), str( sharing_role.id ) )
- regular_user1.refresh()
- if len( regular_user1.roles) != 1:
- raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( regular_user1.roles ), regular_user1.email ) )
- # Eliminate all group associations
- self.remove_user_from_group( str( regular_user1.id ), str( group_one.id ) )
- regular_user1.refresh()
- if regular_user1.groups:
- raise AssertionError( '%d UserGroupAssociations are associated with %s ( should be 0 )' % ( len( regular_user1.groups ), regular_user1.email ) )
- # Delete the record for sharing_role from the role table so that it can be created correctly in later test runs
- self.mark_role_deleted( str( sharing_role.id ) )
- self.purge_role( str( sharing_role.id ) )
- sharing_role.refresh()
- sharing_role.delete()
- sharing_role.flush()
- #################
- # Reset group_one
- #################
- # Eliminate all role associations
- self.remove_role_from_group( str( role_one.id ), str( group_one.id ) )
- group_one.refresh()
- if group_one.roles:
- raise AssertionError( '%d GroupRoleAssociations are associated with group %s ( should be 0 )' % ( len( group_one.roles ), group_one.name ) )