PageRenderTime 105ms CodeModel.GetById 32ms app.highlight 65ms RepoModel.GetById 2ms app.codeStats 0ms

/test/functional/test_admin_features.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 502 lines | 456 code | 9 blank | 37 comment | 51 complexity | e22cbc3b5a23484feb112bc99540d6cd MD5 | raw file
  1from base.twilltestcase import TwillTestCase
  2from functional import database_contexts
  3import galaxy.model
  4from base.test_db_util import (
  5    get_user,
  6    get_private_role,
  7    get_all_histories_for_user,
  8    get_latest_history_for_user,
  9    get_default_history_permissions_by_history,
 10    get_latest_dataset,
 11    refresh,
 12    flush,
 13    get_group_by_name,
 14    get_role_by_name,
 15    get_user_group_associations_by_group,
 16    get_default_history_permissions_by_role,
 17    get_default_user_permissions_by_role,
 18    get_user_role_associations_by_role,
 19    get_group_role_associations_by_group,
 20    get_dataset_permissions_by_role,
 21    get_group_role_associations_by_role,
 22)
 23
 24
 25# Globals setup by these tests.
 26regular_user1 = regular_user2 = regular_user3 = admin_user = None
 27role_one = role_two = role_three = None
 28group_zero = group_one = group_two = None
 29
 30
 31class TestDataSecurity( TwillTestCase ):
 32    def test_000_initiate_users( self ):
 33        """Ensuring all required user accounts exist"""
 34        self.logout()
 35        self.login( email='test1@bx.psu.edu', username='regular-user1' )
 36        global regular_user1
 37        regular_user1 = get_user( 'test1@bx.psu.edu' )
 38        assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database'
 39        self.logout()
 40        self.login( email='test2@bx.psu.edu', username='regular-user2' )
 41        global regular_user2
 42        regular_user2 = get_user( 'test2@bx.psu.edu' )
 43        assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database'
 44        self.logout()
 45        self.login( email='test@bx.psu.edu', username='admin-user' )
 46        global admin_user
 47        admin_user = get_user( 'test@bx.psu.edu' )
 48        assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database'
 49
 50    def test_005_create_new_user_account_as_admin( self ):
 51        """Testing creating a new user account as admin"""
 52        # Logged in as admin_user
 53        email = 'test3@bx.psu.edu'
 54        password = 'testuser'
 55        # Test setting the user name to one that is already taken.  Note that the account must not exist in order
 56        # for this test to work as desired, so the email we're passing is important...
 57        previously_created, username_taken, invalid_username = self.create_new_account_as_admin( email='diff@you.com',
 58                                                                                                 password=password,
 59                                                                                                 username='admin-user',
 60                                                                                                 redirect='' )
 61        if not username_taken:
 62            error_msg = "The public name (%s) is already being used by another user, but no error was displayed" % 'admin-user'
 63            raise AssertionError( error_msg )
 64
 65        # Test setting the user name to an invalid one.  Note that the account must not exist in order
 66        # for this test to work as desired, so the email we're passing is important...
 67        previously_created, username_taken, invalid_username = self.create_new_account_as_admin( email='diff@you.com',
 68                                                                                                 password=password,
 69                                                                                                 username='h',
 70                                                                                                 redirect='' )
 71        if not invalid_username:
 72            raise AssertionError( "The public name (%s) is is invalid, but no error was displayed" % 'diff@you.com' )
 73        previously_created, username_taken, invalid_username = self.create_new_account_as_admin( email=email,
 74                                                                                                 password=password,
 75                                                                                                 username='regular-user3',
 76                                                                                                 redirect='' )
 77        # Get the user object for later tests
 78        global regular_user3
 79        regular_user3 = get_user( email )
 80        assert regular_user3 is not None, 'Problem retrieving user with email "%s" from the database' % email
 81        global regular_user3_private_role
 82        regular_user3_private_role = get_private_role( regular_user3 )
 83        # Make sure DefaultUserPermissions were created
 84        if not regular_user3.default_permissions:
 85            raise AssertionError( 'No DefaultUserPermissions were created for user %s when the admin created the account' % email )
 86        # Make sure a private role was created for the user
 87        if not regular_user3.roles:
 88            raise AssertionError( 'No UserRoleAssociations were created for user %s when the admin created the account' % email )
 89        if not previously_created and len( regular_user3.roles ) != 1:
 90            raise AssertionError( '%d UserRoleAssociations were created for user %s when the admin created the account ( should have been 1 )' \
 91                                  % ( len( regular_user3.roles ), regular_user3.email ) )
 92        for ura in regular_user3.roles:
 93            role = database_contexts.galaxy_context.query( galaxy.model.Role ).get( ura.role_id )
 94            if not previously_created and role.type != 'private':
 95                raise AssertionError( 'Role created for user %s when the admin created the account is not private, type is' \
 96                                      % str( role.type ) )
 97        if not previously_created:
 98            # Make sure a history was not created ( previous test runs may have left deleted histories )
 99            histories = get_all_histories_for_user( regular_user3 )
100            if histories:
101                raise AssertionError( 'Histories were incorrectly created for user %s when the admin created the account' % email )
102            # Make sure the user was not associated with any groups
103            if regular_user3.groups:
104                raise AssertionError( 'Groups were incorrectly associated with user %s when the admin created the account' % email )
105
106    def test_010_reset_password_as_admin( self ):
107        """Testing reseting a user password as admin"""
108        self.reset_password_as_admin( user_id=self.security.encode_id( regular_user3.id ), password='testreset' )
109
110    def test_015_login_after_password_reset( self ):
111        """Testing logging in after an admin reset a password - tests DefaultHistoryPermissions for accounts created by an admin"""
112        # logged in as admin_user
113        self.logout()
114        self.login( email=regular_user3.email, password='testreset' )
115        # Make sure a History and HistoryDefaultPermissions exist for the user
116        latest_history = get_latest_history_for_user( regular_user3 )
117        if not latest_history.user_id == regular_user3.id:
118            raise AssertionError( 'A history was not created for user %s when he logged in' % regular_user3.email )
119        if not latest_history.default_permissions:
120            raise AssertionError( 'No DefaultHistoryPermissions were created for history id %d when it was created' % latest_history.id )
121        dhps = get_default_history_permissions_by_history( latest_history )
122        if len( dhps ) > 1:
123            raise AssertionError( 'More than 1 DefaultHistoryPermissions were created for history id %d when it was created' % latest_history.id )
124        dhp = dhps[0]
125        if not dhp.action == galaxy.model.Dataset.permitted_actions.DATASET_MANAGE_PERMISSIONS.action:
126            raise AssertionError( 'The DefaultHistoryPermission.action for history id %d is "%s", but it should be "manage permissions"' \
127                                  % ( latest_history.id, dhp.action ) )
128        # Upload a file to create a HistoryDatasetAssociation
129        self.upload_file( '1.bed' )
130        latest_dataset = get_latest_dataset()
131        for dp in latest_dataset.actions:
132            # Should only have 1 DatasetPermissions
133            if dp.action != galaxy.model.Dataset.permitted_actions.DATASET_MANAGE_PERMISSIONS.action:
134                raise AssertionError( 'The DatasetPermissions for dataset id %d is %s ( should have been %s )' \
135                                      % ( latest_dataset.id,
136                                          latest_dataset.actions.action,
137                                          galaxy.model.Dataset.permitted_actions.DATASET_MANAGE_PERMISSIONS.action ) )
138        self.logout()
139        # Reset the password to the default for later tests
140        self.login( email='test@bx.psu.edu' )
141        self.reset_password_as_admin( user_id=self.security.encode_id( regular_user3.id ), password='testuser' )
142
143    def test_020_mark_user_deleted( self ):
144        """Testing marking a user account as deleted"""
145        # Logged in as admin_user
146        self.mark_user_deleted( user_id=self.security.encode_id( regular_user3.id ), email=regular_user3.email )
147        if not regular_user3.active_histories:
148            raise AssertionError( 'HistoryDatasetAssociations for regular_user3 were incorrectly deleted when the user was marked deleted' )
149
150    def test_025_undelete_user( self ):
151        """Testing undeleting a user account"""
152        # Logged in as admin_user
153        self.undelete_user( user_id=self.security.encode_id( regular_user3.id ), email=regular_user3.email )
154
155    def test_030_create_role( self ):
156        """Testing creating new role with 3 members ( and a new group named the same ), then renaming the role"""
157        # Logged in as admin_user
158        name = 'Role One'
159        description = "This is Role Ones description"
160        in_user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
161        in_group_ids = []
162        # Add 1 to the number of associated groups since we are creating a new one with the same name as the role
163        num_gras = len( in_group_ids ) + 1
164        self.create_role( name=name,
165                          description=description,
166                          in_user_ids=in_user_ids,
167                          in_group_ids=in_group_ids,
168                          create_group_for_role='yes',
169                          private_role=admin_user.email,
170                          strings_displayed=[ "Role '%s' has been created with %d associated users and %d associated groups." % ( name, len( in_user_ids ), num_gras ),
171                                              "One of the groups associated with this role is the newly created group with the same name." ] )
172        # Get the role object for later tests
173        global role_one
174        role_one = database_contexts.galaxy_context.query( galaxy.model.Role ).filter( galaxy.model.Role.table.c.name == name ).first()
175        assert role_one is not None, 'Problem retrieving role named "Role One" from the database'
176        # Make sure UserRoleAssociations are correct
177        if len( role_one.users ) != len( in_user_ids ):
178            raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created ( should have been %d )' \
179                                  % ( len( role_one.users ), role_one.id, len( in_user_ids ) ) )
180        # Each of the following users should now have 2 role associations, their private role and role_one
181        for user in [ admin_user, regular_user1, regular_user3 ]:
182            refresh( user )
183            if len( user.roles ) != 2:
184                raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 2 )' \
185                                      % ( len( user.roles ), user.email ) )
186        # Make sure the group was created
187        self.visit_url( '%s/admin/groups' % self.url )
188        self.check_page_for_string( name )
189        global group_zero
190        group_zero = get_group_by_name( name )
191        # Rename the role
192        rename = "Role One's been Renamed"
193        new_description = "This is Role One's Re-described"
194        self.rename_role( self.security.encode_id( role_one.id ), name=rename, description=new_description )
195        self.visit_url( '%s/admin/roles' % self.url )
196        self.check_page_for_string( rename )
197        self.check_page_for_string( new_description )
198        # Reset the role back to the original name and description
199        self.rename_role( self.security.encode_id( role_one.id ), name=name, description=description )
200
201    def test_035_create_group( self ):
202        """Testing creating new group with 3 members and 2 associated roles, then renaming it"""
203        # Logged in as admin_user
204        name = "Group One's Name"
205        in_user_ids = [ str( admin_user.id ), str( regular_user1.id ), str( regular_user3.id ) ]
206        in_role_ids = [ str( role_one.id ) ]
207        # The number of GroupRoleAssociations should be 2, role_one and the newly created role named 'Group One's Name'
208        num_gras = len( in_role_ids ) + 1
209        self.create_group( name=name,
210                           in_user_ids=in_user_ids,
211                           in_role_ids=in_role_ids,
212                           create_role_for_group='yes',
213                           strings_displayed=[ "Group '%s' has been created with %d associated users and %d associated roles." % ( name, len( in_user_ids ), num_gras ),
214                                               "One of the roles associated with this group is the newly created role with the same name." ] )
215        # Get the group object for later tests
216        global group_one
217        group_one = get_group_by_name( name )
218        assert group_one is not None, 'Problem retrieving group named "Group One" from the database'
219        # Make sure UserGroupAssociations are correct
220        if len( group_one.users ) != len( in_user_ids ):
221            raise AssertionError( '%d UserGroupAssociations were created for group id %d when it was created ( should have been %d )' \
222                                  % ( len( group_one.users ), group_one.id, len( in_user_ids ) ) )
223        # Each user should now have 1 group association, group_one
224        for user in [ admin_user, regular_user1, regular_user3 ]:
225            refresh( user )
226            if len( user.groups ) != 1:
227                raise AssertionError( '%d UserGroupAssociations are associated with user %s ( should be 1 )' % ( len( user.groups ), user.email ) )
228        # Make sure GroupRoleAssociations are correct
229        if len( group_one.roles ) != num_gras:
230            raise AssertionError( '%d GroupRoleAssociations were created for group id %d when it was created ( should have been %d )' \
231                                  % ( len( group_one.roles ), group_one.id, num_gras ) )
232        # Rename the group
233        rename = "Group One's been Renamed"
234        self.rename_group( self.security.encode_id( group_one.id ), name=rename, )
235        self.home()
236        self.visit_url( '%s/admin/groups' % self.url )
237        self.check_page_for_string( rename )
238        # Reset the group back to the original name
239        self.rename_group( self.security.encode_id( group_one.id ), name=name )
240
241    def test_040_add_members_and_role_to_group( self ):
242        """Testing editing user membership and role associations of an existing group"""
243        # Logged in as admin_user
244        name = 'Group Two'
245        self.create_group( name=name, in_user_ids=[], in_role_ids=[] )
246        # Get the group object for later tests
247        global group_two
248        group_two = get_group_by_name( name )
249        assert group_two is not None, 'Problem retrieving group named "Group Two" from the database'
250        # group_two should have no associations
251        if group_two.users:
252            raise AssertionError( '%d UserGroupAssociations were created for group id %d when it was created ( should have been 0 )' \
253                              % ( len( group_two.users ), group_two.id ) )
254        if group_two.roles:
255            raise AssertionError( '%d GroupRoleAssociations were created for group id %d when it was created ( should have been 0 )' \
256                              % ( len( group_two.roles ), group_two.id ) )
257        user_ids = [ str( regular_user1.id )  ]
258        role_ids = [ str( role_one.id ) ]
259        self.associate_users_and_roles_with_group( self.security.encode_id( group_two.id ),
260                                                   group_two.name,
261                                                   user_ids=user_ids,
262                                                   role_ids=role_ids )
263
264    def test_045_create_role_with_user_and_group_associations( self ):
265        """Testing creating a role with user and group associations"""
266        # Logged in as admin_user
267        # NOTE: To get this to work with twill, all select lists on the ~/admin/role page must contain at least
268        # 1 option value or twill throws an exception, which is: ParseError: OPTION outside of SELECT
269        # Due to this bug in twill, we create the role, we bypass the page and visit the URL in the
270        # associate_users_and_groups_with_role() method.
271        name = 'Role Two'
272        description = 'This is Role Two'
273        user_ids = [ str( admin_user.id ) ]
274        group_ids = [ str( group_two.id ) ]
275        private_role = admin_user.email
276        # Create the role
277        self.create_role( name=name,
278                          description=description,
279                          in_user_ids=user_ids,
280                          in_group_ids=group_ids,
281                          private_role=private_role )
282        # Get the role object for later tests
283        global role_two
284        role_two = get_role_by_name( name )
285        assert role_two is not None, 'Problem retrieving role named "Role Two" from the database'
286        # Make sure UserRoleAssociations are correct
287        if len( role_two.users ) != len( user_ids ):
288            raise AssertionError( '%d UserRoleAssociations were created for role id %d when it was created with %d members' \
289                                  % ( len( role_two.users ), role_two.id, len( user_ids ) ) )
290        # admin_user should now have 3 role associations, private role, role_one, role_two
291        refresh( admin_user )
292        if len( admin_user.roles ) != 3:
293            raise AssertionError( '%d UserRoleAssociations are associated with user %s ( should be 3 )' % ( len( admin_user.roles ), admin_user.email ) )
294        # Make sure GroupRoleAssociations are correct
295        refresh( role_two )
296        if len( role_two.groups ) != len( group_ids ):
297            raise AssertionError( '%d GroupRoleAssociations were created for role id %d when it was created ( should have been %d )' \
298                                  % ( len( role_two.groups ), role_two.id, len( group_ids ) ) )
299        # group_two should now be associated with 2 roles: role_one, role_two
300        refresh( group_two )
301        if len( group_two.roles ) != 2:
302            raise AssertionError( '%d GroupRoleAssociations are associated with group id %d ( should be 2 )' % ( len( group_two.roles ), group_two.id ) )
303
304    def test_050_change_user_role_associations( self ):
305        """Testing changing roles associated with a user"""
306        # Logged in as admin_user
307        # Create a new role with no associations
308        name = 'Role Three'
309        description = 'This is Role Three'
310        user_ids = []
311        group_ids = []
312        private_role = admin_user.email
313        self.create_role( name=name,
314                          description=description,
315                          in_user_ids=user_ids,
316                          in_group_ids=group_ids,
317                          private_role=private_role )
318        # Get the role object for later tests
319        global role_three
320        role_three = get_role_by_name( name )
321        assert role_three is not None, 'Problem retrieving role named "Role Three" from the database'
322        # Associate the role with a user
323        refresh( admin_user )
324        role_ids = []
325        for ura in admin_user.non_private_roles:
326            role_ids.append( str( ura.role_id ) )
327        role_ids.append( str( role_three.id ) )
328        group_ids = []
329        for uga in admin_user.groups:
330            group_ids.append( str( uga.group_id ) )
331        strings_displayed = [ "User '%s' has been updated with %d associated roles and %d associated groups" % \
332                            ( admin_user.email, len( role_ids ), len( group_ids ) ) ]
333        self.manage_roles_and_groups_for_user( self.security.encode_id( admin_user.id ),
334                                               in_role_ids=role_ids,
335                                               in_group_ids=group_ids,
336                                               strings_displayed=strings_displayed )
337        refresh( admin_user )
338        # admin_user should now be associated with 4 roles: private, role_one, role_two, role_three
339        if len( admin_user.roles ) != 4:
340            raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 4 )' % \
341                                  ( len( admin_user.roles ), admin_user.email ) )
342
343    def test_055_mark_group_deleted( self ):
344        """Testing marking a group as deleted"""
345        # Logged in as admin_user
346        self.browse_groups( strings_displayed=[ group_two.name ] )
347        self.mark_group_deleted( self.security.encode_id( group_two.id ), group_two.name )
348        refresh( group_two )
349        if not group_two.deleted:
350            raise AssertionError( '%s was not correctly marked as deleted.' % group_two.name )
351        # Deleting a group should not delete any associations
352        if not group_two.members:
353            raise AssertionError( '%s incorrectly lost all members when it was marked as deleted.' % group_two.name )
354        if not group_two.roles:
355            raise AssertionError( '%s incorrectly lost all role associations when it was marked as deleted.' % group_two.name )
356
357    def test_060_undelete_group( self ):
358        """Testing undeleting a deleted group"""
359        # Logged in as admin_user
360        self.undelete_group( self.security.encode_id( group_two.id ), group_two.name )
361        refresh( group_two )
362        if group_two.deleted:
363            raise AssertionError( '%s was not correctly marked as not deleted.' % group_two.name )
364
365    def test_065_mark_role_deleted( self ):
366        """Testing marking a role as deleted"""
367        # Logged in as admin_user
368        self.home()
369        self.browse_roles( strings_displayed=[ role_two.name ] )
370        self.mark_role_deleted( self.security.encode_id( role_two.id ), role_two.name )
371        refresh( role_two )
372        if not role_two.deleted:
373            raise AssertionError( '%s was not correctly marked as deleted.' % role_two.name )
374        # Deleting a role should not delete any associations
375        if not role_two.users:
376            raise AssertionError( '%s incorrectly lost all user associations when it was marked as deleted.' % role_two.name )
377        if not role_two.groups:
378            raise AssertionError( '%s incorrectly lost all group associations when it was marked as deleted.' % role_two.name )
379
380    def test_070_undelete_role( self ):
381        """Testing undeleting a deleted role"""
382        # Logged in as admin_user
383        self.undelete_role( self.security.encode_id( role_two.id ), role_two.name )
384
385    def test_075_purge_user( self ):
386        """Testing purging a user account"""
387        # Logged in as admin_user
388        self.mark_user_deleted( user_id=self.security.encode_id( regular_user3.id ), email=regular_user3.email )
389        refresh( regular_user3 )
390        self.purge_user( self.security.encode_id( regular_user3.id ), regular_user3.email )
391        refresh( regular_user3 )
392        if not regular_user3.purged:
393            raise AssertionError( 'User %s was not marked as purged.' % regular_user3.email )
394        # Make sure DefaultUserPermissions deleted EXCEPT FOR THE PRIVATE ROLE
395        if len( regular_user3.default_permissions ) != 1:
396            raise AssertionError( 'DefaultUserPermissions for user %s were not deleted.' % regular_user3.email )
397        for dup in regular_user3.default_permissions:
398            role = database_contexts.galaxy_context.query( galaxy.model.Role ).get( dup.role_id )
399            if role.type != 'private':
400                raise AssertionError( 'DefaultUserPermissions for user %s are not related with the private role.' % regular_user3.email )
401        # Make sure History deleted
402        for history in regular_user3.histories:
403            refresh( history )
404            if not history.deleted:
405                raise AssertionError( 'User %s has active history id %d after their account was marked as purged.' % ( regular_user3.email, history.id ) )
406            # NOTE: Not all hdas / datasets will be deleted at the time a history is deleted - the cleanup_datasets.py script
407            # is responsible for this.
408        # Make sure UserGroupAssociations deleted
409        if regular_user3.groups:
410            raise AssertionError( 'User %s has active group after their account was marked as purged.' % ( regular_user3.email ) )
411        # Make sure UserRoleAssociations deleted EXCEPT FOR THE PRIVATE ROLE
412        if len( regular_user3.roles ) != 1:
413            raise AssertionError( 'UserRoleAssociations for user %s were not deleted.' % regular_user3.email )
414        for ura in regular_user3.roles:
415            role = database_contexts.galaxy_context.query( galaxy.model.Role ).get( ura.role_id )
416            if role.type != 'private':
417                raise AssertionError( 'UserRoleAssociations for user %s are not related with the private role.' % regular_user3.email )
418
419    def test_080_manually_unpurge_user( self ):
420        """Testing manually un-purging a user account"""
421        # Logged in as admin_user
422        # Reset the user for later test runs.  The user's private Role and DefaultUserPermissions for that role
423        # should have been preserved, so all we need to do is reset purged and deleted.
424        # TODO: If we decide to implement the GUI feature for un-purging a user, replace this with a method call
425        regular_user3.purged = False
426        regular_user3.deleted = False
427        flush( regular_user3 )
428
429    def test_085_purge_group( self ):
430        """Testing purging a group"""
431        # Logged in as admin_user
432        self.mark_group_deleted( self.security.encode_id( group_two.id ), group_two.name )
433        self.purge_group( self.security.encode_id( group_two.id ), group_two.name )
434        # Make sure there are no UserGroupAssociations
435        if get_user_group_associations_by_group( group_two ):
436            raise AssertionError( "Purging the group did not delete the UserGroupAssociations for group_id '%s'" % group_two.id )
437        # Make sure there are no GroupRoleAssociations
438        if get_group_role_associations_by_group( group_two ):
439            raise AssertionError( "Purging the group did not delete the GroupRoleAssociations for group_id '%s'" % group_two.id )
440        # Undelete the group for later test runs
441        self.undelete_group( self.security.encode_id( group_two.id ), group_two.name )
442
443    def test_090_purge_role( self ):
444        """Testing purging a role"""
445        # Logged in as admin_user
446        self.mark_role_deleted( self.security.encode_id( role_two.id ), role_two.name )
447        self.purge_role( self.security.encode_id( role_two.id ), role_two.name )
448        # Make sure there are no UserRoleAssociations
449        if get_user_role_associations_by_role( role_two ):
450            raise AssertionError( "Purging the role did not delete the UserRoleAssociations for role_id '%s'" % role_two.id )
451        # Make sure there are no DefaultUserPermissions associated with the Role
452        if get_default_user_permissions_by_role( role_two ):
453            raise AssertionError( "Purging the role did not delete the DefaultUserPermissions for role_id '%s'" % role_two.id )
454        # Make sure there are no DefaultHistoryPermissions associated with the Role
455        if get_default_history_permissions_by_role( role_two ):
456            raise AssertionError( "Purging the role did not delete the DefaultHistoryPermissions for role_id '%s'" % role_two.id )
457        # Make sure there are no GroupRoleAssociations
458        if get_group_role_associations_by_role( role_two ):
459            raise AssertionError( "Purging the role did not delete the GroupRoleAssociations for role_id '%s'" % role_two.id )
460        # Make sure there are no DatasetPermissionss
461        if get_dataset_permissions_by_role( role_two ):
462            raise AssertionError( "Purging the role did not delete the DatasetPermissionss for role_id '%s'" % role_two.id )
463
464    def test_095_manually_unpurge_role( self ):
465        """Testing manually un-purging a role"""
466        # Logged in as admin_user
467        # Manually unpurge, then undelete the role for later test runs
468        # TODO: If we decide to implement the GUI feature for un-purging a role, replace this with a method call
469        role_two.purged = False
470        flush( role_two )
471        self.undelete_role( self.security.encode_id( role_two.id ), role_two.name )
472
473    def test_999_reset_data_for_later_test_runs( self ):
474        """Reseting data to enable later test runs to pass"""
475        # Logged in as admin_user
476        ##################
477        # Eliminate all non-private roles
478        ##################
479        for role in [ role_one, role_two, role_three ]:
480            self.mark_role_deleted( self.security.encode_id( role.id ), role.name )
481            self.purge_role( self.security.encode_id( role.id ), role.name )
482            # Manually delete the role from the database
483            refresh( role )
484            database_contexts.galaxy_context.delete( role )
485            database_contexts.galaxy_context.flush()
486        ##################
487        # Eliminate all groups
488        ##################
489        for group in [ group_zero, group_one, group_two ]:
490            self.mark_group_deleted( self.security.encode_id( group.id ), group.name )
491            self.purge_group( self.security.encode_id( group.id ), group.name )
492            # Manually delete the group from the database
493            refresh( group )
494            database_contexts.galaxy_context.delete( group )
495            database_contexts.galaxy_context.flush()
496        ##################
497        # Make sure all users are associated only with their private roles
498        ##################
499        for user in [ admin_user, regular_user1, regular_user2, regular_user3 ]:
500            refresh( user )
501            if len( user.roles) != 1:
502                raise AssertionError( '%d UserRoleAssociations are associated with %s ( should be 1 )' % ( len( user.roles ), user.email ) )