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'
Exemplo n.º 2
0
 def test_045_create_role_with_user_and_group_associations(self):
     """Testing creating a role with user and group associations"""
     # Logged in as admin_user
     # 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.
     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
     # 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 = get_role_by_name(name)
     assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
     # 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'
             % (len(role_two.users), role_two.id, len(user_ids)))
     # admin_user should now have 3 role associations, private role, role_one, role_two
     refresh(admin_user)
     if len(admin_user.roles) != 3:
         raise AssertionError(
             '%d UserRoleAssociations are associated with user %s ( should be 3 )'
             % (len(admin_user.roles), admin_user.email))
     # Make sure GroupRoleAssociations are correct
     refresh(role_two)
     if len(role_two.groups) != len(group_ids):
         raise AssertionError(
             '%d GroupRoleAssociations were created for role id %d when it was created ( should have been %d )'
             % (len(role_two.groups), role_two.id, len(group_ids)))
     # group_two should now be associated with 2 roles: role_one, role_two
     refresh(group_two)
     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))
Exemplo n.º 3
0
 def test_050_change_user_role_associations(self):
     """Testing changing roles associated with a user"""
     # Logged in as admin_user
     # Create a new role with no associations
     name = 'Role Three'
     description = 'This is Role Three'
     user_ids = []
     group_ids = []
     private_role = admin_user.email
     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 = get_role_by_name(name)
     assert role_three is not None, 'Problem retrieving role named "Role Three" from the database'
     # Associate the role with a user
     refresh(admin_user)
     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))
     strings_displayed = [
         "User '%s' has been updated with %d associated roles and %d associated groups"
         % (admin_user.email, len(role_ids), len(group_ids))
     ]
     self.manage_roles_and_groups_for_user(
         self.security.encode_id(admin_user.id),
         in_role_ids=role_ids,
         in_group_ids=group_ids,
         strings_displayed=strings_displayed)
     refresh(admin_user)
     # admin_user should now be associated with 4 roles: private, role_one, role_two, role_three
     if len(admin_user.roles) != 4:
         raise AssertionError(
             '%d UserRoleAssociations are associated with %s ( should be 4 )'
             % (len(admin_user.roles), admin_user.email))
 def test_045_create_role_with_user_and_group_associations( self ):
     """Testing creating a role with user and group associations"""
     # Logged in as admin_user
     # 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.
     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
     # 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 = get_role_by_name( name )
     assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
     # 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'
                               % ( len( role_two.users ), role_two.id, len( user_ids ) ) )
     # admin_user should now have 3 role associations, private role, role_one, role_two
     refresh( admin_user )
     if len( admin_user.roles ) != 3:
         raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 3 )' % ( len( admin_user.roles ), admin_user.email ) )
     # Make sure GroupRoleAssociations are correct
     refresh( role_two )
     if len( role_two.groups ) != len( group_ids ):
         raise AssertionError( '%d GroupRoleAssociations were created for role id %d when it was created ( should have been %d )'
                               % ( len( role_two.groups ), role_two.id, len( group_ids ) ) )
     # group_two should now be associated with 2 roles: role_one, role_two
     refresh( group_two )
     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 ) )
 def test_050_change_user_role_associations( self ):
     """Testing changing roles associated with a user"""
     # Logged in as admin_user
     # Create a new role with no associations
     name = 'Role Three'
     description = 'This is Role Three'
     user_ids = []
     group_ids = []
     private_role = admin_user.email
     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 = get_role_by_name( name )
     assert role_three is not None, 'Problem retrieving role named "Role Three" from the database'
     # Associate the role with a user
     refresh( admin_user )
     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 ) )
     strings_displayed = [ "User '%s' has been updated with %d associated roles and %d associated groups" %
                         ( admin_user.email, len( role_ids ), len( group_ids ) ) ]
     self.manage_roles_and_groups_for_user( self.security.encode_id( admin_user.id ),
                                            in_role_ids=role_ids,
                                            in_group_ids=group_ids,
                                            strings_displayed=strings_displayed )
     refresh( admin_user )
     # admin_user should now be associated with 4 roles: private, role_one, role_two, role_three
     if len( admin_user.roles ) != 4:
         raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 4 )' %
                               ( len( admin_user.roles ), admin_user.email ) )