/test/functional/test_admin_features.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 502 lines · 429 code · 15 blank · 58 comment · 32 complexity · e22cbc3b5a23484feb112bc99540d6cd MD5 · raw file

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