Beispiel #1
0
 def test_040_add_members_and_role_to_group(self):
     """Testing editing user membership and role associations of an existing group"""
     # Logged in as admin_user
     name = 'Group Two'
     self.create_group(name=name, in_user_ids=[], in_role_ids=[])
     # Get the group object for later tests
     global group_two
     group_two = get_group_by_name(name)
     assert group_two is not None, 'Problem retrieving group named "Group Two" from the database'
     # group_two should have no associations
     if group_two.users:
         raise AssertionError(
             '%d UserGroupAssociations were created for group id %d when it was created ( should have been 0 )'
             % (len(group_two.users), group_two.id))
     if group_two.roles:
         raise AssertionError(
             '%d GroupRoleAssociations were created for group id %d when it was created ( should have been 0 )'
             % (len(group_two.roles), group_two.id))
     user_ids = [str(regular_user1.id)]
     role_ids = [str(role_one.id)]
     self.associate_users_and_roles_with_group(self.security.encode_id(
         group_two.id),
                                               group_two.name,
                                               user_ids=user_ids,
                                               role_ids=role_ids)
 def test_030_create_role(self):
     """Testing creating new role with 3 members ( and a new group named the same ), then renaming the role"""
     # Logged in as admin_user
     name = 'Role One'
     description = "This is Role Ones description"
     in_user_ids = [
         str(admin_user.id),
         str(regular_user1.id),
         str(regular_user3.id)
     ]
     in_group_ids = []
     # Add 1 to the number of associated groups since we are creating a new one with the same name as the role
     num_gras = len(in_group_ids) + 1
     self.create_role(
         name=name,
         description=description,
         in_user_ids=in_user_ids,
         in_group_ids=in_group_ids,
         create_group_for_role='yes',
         private_role=admin_user.email,
         strings_displayed=[
             "Role '%s' has been created with %d associated users and %d associated groups."
             % (name, len(in_user_ids), num_gras),
             "One of the groups associated with this role is the newly created group with the same name."
         ])
     # Get the role object for later tests
     global role_one
     role_one = database_contexts.galaxy_context.query(
         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'
     # Make sure UserRoleAssociations are correct
     if len(role_one.users) != len(in_user_ids):
         raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created ( should have been %d )' \
                               % ( len( role_one.users ), role_one.id, len( in_user_ids ) ) )
     # Each of the following users should now have 2 role associations, their private role and role_one
     for user in [admin_user, regular_user1, regular_user3]:
         refresh(user)
         if len(user.roles) != 2:
             raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 2 )' \
                                   % ( len( user.roles ), user.email ) )
     # Make sure the group was created
     self.visit_url('%s/admin/groups' % self.url)
     self.check_page_for_string(name)
     global group_zero
     group_zero = get_group_by_name(name)
     # Rename the role
     rename = "Role One's been Renamed"
     new_description = "This is Role One's Re-described"
     self.rename_role(self.security.encode_id(role_one.id),
                      name=rename,
                      description=new_description)
     self.visit_url('%s/admin/roles' % self.url)
     self.check_page_for_string(rename)
     self.check_page_for_string(new_description)
     # Reset the role back to the original name and description
     self.rename_role(self.security.encode_id(role_one.id),
                      name=name,
                      description=description)
Beispiel #3
0
 def test_035_create_group(self):
     """Testing creating new group with 3 members and 2 associated roles, then renaming it"""
     # Logged in as admin_user
     name = "Group One's Name"
     in_user_ids = [
         str(admin_user.id),
         str(regular_user1.id),
         str(regular_user3.id)
     ]
     in_role_ids = [str(role_one.id)]
     # The number of GroupRoleAssociations should be 2, role_one and the newly created role named 'Group One's Name'
     num_gras = len(in_role_ids) + 1
     self.create_group(
         name=name,
         in_user_ids=in_user_ids,
         in_role_ids=in_role_ids,
         create_role_for_group=True,
         strings_displayed=[
             "Group '%s' has been created with %d associated users and %d associated roles."
             % (name, len(in_user_ids), num_gras),
             "One of the roles associated with this group is the newly created role with the same name."
         ])
     # Get the group object for later tests
     global group_one
     group_one = get_group_by_name(name)
     assert group_one is not None, 'Problem retrieving group named "Group One" from the database'
     # Make sure UserGroupAssociations are correct
     if len(group_one.users) != len(in_user_ids):
         raise AssertionError(
             '%d UserGroupAssociations were created for group id %d when it was created ( should have been %d )'
             % (len(group_one.users), group_one.id, len(in_user_ids)))
     # Each user should now have 1 group association, group_one
     for user in [admin_user, regular_user1, regular_user3]:
         refresh(user)
         if len(user.groups) != 1:
             raise AssertionError(
                 '%d UserGroupAssociations are associated with user %s ( should be 1 )'
                 % (len(user.groups), user.email))
     # Make sure GroupRoleAssociations are correct
     if len(group_one.roles) != num_gras:
         raise AssertionError(
             '%d GroupRoleAssociations were created for group id %d when it was created ( should have been %d )'
             % (len(group_one.roles), group_one.id, num_gras))
     # Rename the group
     rename = "Group One's been Renamed"
     self.rename_group(
         self.security.encode_id(group_one.id),
         name=rename,
     )
     self.visit_url('%s/admin/groups' % self.url)
     self.check_page_for_string(rename)
     # Reset the group back to the original name
     self.rename_group(self.security.encode_id(group_one.id), name=name)
 def test_030_create_role( self ):
     """Testing creating new role with 3 members ( and a new group named the same ), then renaming the role"""
     # Logged in as admin_user
     name = 'Role One'
     description = "This is Role Ones description"
     in_user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
     in_group_ids = []
     # Add 1 to the number of associated groups since we are creating a new one with the same name as the role
     num_gras = len( in_group_ids ) + 1
     self.create_role( name=name,
                       description=description,
                       in_user_ids=in_user_ids,
                       in_group_ids=in_group_ids,
                       create_group_for_role='yes',
                       private_role=admin_user.email,
                       strings_displayed=[ "Role '%s' has been created with %d associated users and %d associated groups." % ( name, len( in_user_ids ), num_gras ),
                                           "One of the groups associated with this role is the newly created group with the same name." ] )
     # Get the role object for later tests
     global role_one
     role_one = database_contexts.galaxy_context.query( 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'
     # Make sure UserRoleAssociations are correct
     if len( role_one.users ) != len( in_user_ids ):
         raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created ( should have been %d )'
                               % ( len( role_one.users ), role_one.id, len( in_user_ids ) ) )
     # Each of the following users should now have 2 role associations, their private role and role_one
     for user in [ admin_user, regular_user1, regular_user3 ]:
         refresh( user )
         if len( user.roles ) != 2:
             raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 2 )'
                                   % ( len( user.roles ), user.email ) )
     # Make sure the group was created
     self.visit_url( '%s/admin/groups' % self.url )
     self.check_page_for_string( name )
     global group_zero
     group_zero = get_group_by_name( name )
     # Rename the role
     rename = "Role One's been Renamed"
     new_description = "This is Role One's Re-described"
     self.rename_role( self.security.encode_id( role_one.id ), name=rename, description=new_description )
     self.visit_url( '%s/admin/roles' % self.url )
     self.check_page_for_string( rename )
     self.check_page_for_string( new_description )
     # Reset the role back to the original name and description
     self.rename_role( self.security.encode_id( role_one.id ), name=name, description=description )
 def test_040_add_members_and_role_to_group( self ):
     """Testing editing user membership and role associations of an existing group"""
     # Logged in as admin_user
     name = 'Group Two'
     self.create_group( name=name, in_user_ids=[], in_role_ids=[] )
     # Get the group object for later tests
     global group_two
     group_two = get_group_by_name( name )
     assert group_two is not None, 'Problem retrieving group named "Group Two" from the database'
     # group_two should have no associations
     if group_two.users:
         raise AssertionError( '%d UserGroupAssociations were created for group id %d when it was created ( should have been 0 )'
                           % ( len( group_two.users ), group_two.id ) )
     if group_two.roles:
         raise AssertionError( '%d GroupRoleAssociations were created for group id %d when it was created ( should have been 0 )'
                           % ( len( group_two.roles ), group_two.id ) )
     user_ids = [ str( regular_user1.id )  ]
     role_ids = [ str( role_one.id ) ]
     self.associate_users_and_roles_with_group( self.security.encode_id( group_two.id ),
                                                group_two.name,
                                                user_ids=user_ids,
                                                role_ids=role_ids )
 def test_035_create_group( self ):
     """Testing creating new group with 3 members and 2 associated roles, then renaming it"""
     # Logged in as admin_user
     name = "Group One's Name"
     in_user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
     in_role_ids = [ str( role_one.id ) ]
     # The number of GroupRoleAssociations should be 2, role_one and the newly created role named 'Group One's Name'
     num_gras = len( in_role_ids ) + 1
     self.create_group( name=name,
                        in_user_ids=in_user_ids,
                        in_role_ids=in_role_ids,
                        create_role_for_group='yes',
                        strings_displayed=[ "Group '%s' has been created with %d associated users and %d associated roles." % ( name, len( in_user_ids ), num_gras ),
                                            "One of the roles associated with this group is the newly created role with the same name." ] )
     # Get the group object for later tests
     global group_one
     group_one = get_group_by_name( name )
     assert group_one is not None, 'Problem retrieving group named "Group One" from the database'
     # Make sure UserGroupAssociations are correct
     if len( group_one.users ) != len( in_user_ids ):
         raise AssertionError( '%d UserGroupAssociations were created for group id %d when it was created ( should have been %d )' \
                               % ( len( group_one.users ), group_one.id, len( in_user_ids ) ) )
     # Each user should now have 1 group association, group_one
     for user in [ admin_user, regular_user1, regular_user3 ]:
         refresh( user )
         if len( user.groups ) != 1:
             raise AssertionError( '%d UserGroupAssociations are associated with user %s ( should be 1 )' % ( len( user.groups ), user.email ) )
     # Make sure GroupRoleAssociations are correct
     if len( group_one.roles ) != num_gras:
         raise AssertionError( '%d GroupRoleAssociations were created for group id %d when it was created ( should have been %d )' \
                               % ( len( group_one.roles ), group_one.id, num_gras ) )
     # Rename the group
     rename = "Group One's been Renamed"
     self.rename_group( self.security.encode_id( group_one.id ), name=rename, )
     self.home()
     self.visit_url( '%s/admin/groups' % self.url )
     self.check_page_for_string( rename )
     # Reset the group back to the original name
     self.rename_group( self.security.encode_id( group_one.id ), name=name )
 def test_005_create_required_groups_and_roles( self ):
     """Testing creating all required groups and roles for this script"""
     # Logged in as admin_user
     # Create Role1: admin_user, regular_user1, regular_user3
     name = 'Role1'
     description = "Role1 description"
     self.create_role( name=name,
                       description=description,
                       in_user_ids=[ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ],
                       in_group_ids=[],
                       create_group_for_role='no',
                       private_role=admin_user.email )
     global role1
     role1 = get_role_by_name( name )
     # Create Group1: regular_user1, admin_user, regular_user3
     name = 'Group1'
     self.create_group( name=name, in_user_ids=[ str( regular_user1.id ) ], in_role_ids=[ str( role1.id ) ] )
     global group1
     group1 = get_group_by_name( name )
     assert group1 is not None, 'Problem retrieving group named "Group1" from the database'
     # 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, we bypass the page and visit the URL in the
     # associate_users_and_groups_with_role() method.
     #
     # create Role2: admin_user, regular_user1, regular_user3
     name = 'Role2'
     description = 'Role2 description'
     private_role = admin_user.email
     self.create_role( name=name,
                       description=description,
                       in_user_ids=[ str( admin_user.id ) ],
                       in_group_ids=[ str( group1.id ) ],
                       private_role=private_role )
     global role2
     role2 = get_role_by_name( name )
     assert role2 is not None, 'Problem retrieving role named "Role2" from the database'