class TestStaticDefaultConfigurator(getConfiguredTestCase(fixture, config={ 'components': { 'cydra.project.configurators.StaticDefaultConfigurator': { 'config': { 'owner': 'test', 'permissions': { 'test': { '*': {'read': True} } } } }, 'cydra.permission.InternalPermissionProvider': True } }, create_users=[{'username': '******', 'full_name': 'Test Owner'}, {'username': '******', 'full_name': 'Tester Testesterus'}], create_projects={'test': 'owner'})): """Test that the internal permission provider properly takes owner permissions from config""" def test_owner_overridable(self): self.assertEqual(self.project_test.owner, self.user_test) self.assertNotEqual(self.project_test.owner, self.user_owner) def test_internal_permissions_overridable(self): self.assertTrue(self.project_test.get_permission(self.user_test, 'some_object', 'read'))
class TestProjectOps(getConfiguredTestCase(fixture)): """Tests for basic project functionality""" def test_create(self): user = self.cydra.get_user(userid='*') proj1 = self.cydra.create_project('project1', user) self.assertTrue(proj1, "Project creation failed") proj2 = self.cydra.get_project('project1') self.assertTrue(proj2, "Unable to get created project") self.assertEqual(proj1, proj2, "Project retrieved is not the same as the created project") self.assertEqual(proj2.owner, user, "User of created project is not correct") self.assertIsNone(self.cydra.create_project('project1', user), "Duplicate project creation possible") def test_delete(self): project1 = self.cydra.create_project('project1', self.cydra.get_user(userid='*')) project2 = self.cydra.create_project('project2', self.cydra.get_user(userid='*')) self.assertTrue(project1, "Project 1 creation failed") self.assertTrue(project2, "Project 2 creation failed") project1_2nd = self.cydra.get_project('project1') self.assertTrue(project1_2nd, "Unable to get created project") self.assertEqual(project1, project1_2nd, "Project retrieved is not the same as the created project") self.assertIsNotNone(self.cydra.get_project('project2'), "Project2 not found") project1.delete() self.assertIsNone(self.cydra.get_project('project1'), "Project was NOT deleted properly") self.assertIsNotNone(self.cydra.get_project('project2'), "Project2 was errornously deleted") def test_delete_with_repos(self): project = self.cydra.create_project('project', self.cydra.get_user(userid='*')) repopaths = [] for repotype in project.get_repository_types(): repo = repotype.create_repository(project, "project") self.assertTrue(repo, "Unable to create repo of type " + repotype.repository_type) repopaths.append(repo.path) self.assertGreater(len(repopaths), 0, "No repositories created") for path in repopaths: self.assertTrue(os.path.exists(path), "Repository path does not exist") project.delete() for path in repopaths: self.assertFalse(os.path.exists(path), "Repository path was not removed") if os.path.basename(os.path.dirname(path)) == "project": # for the repo types that create project subdirectories, # ensure they also cleanup that folder self.assertFalse(os.path.exists(os.path.dirname(path)), "Repository parent path for project was not removed")
class TestGenericPermissions( getConfiguredTestCase(fixture, create_users=[{ 'username': '******', 'full_name': 'Test Owner' }, { 'username': '******', 'full_name': 'Tester Testesterus' }], create_projects={'test': 'owner'})): """Generic tests for permissions, require user store""" def test_project_set_get_permission(self): self.project_test.set_permission(self.user_test, 'some_object', 'read', True) self.assertTrue( self.project_test.get_permission(self.user_test, 'some_object', 'read')) self.assertEqual( self.project_test.get_permissions(self.user_test, None), {'some_object': { 'read': True }}) self.assertEqual( self.project_test.get_permissions(self.user_test, 'some_object'), {'read': True}) def test_project_owner_has_admin(self): self.assertIn( 'admin', self.project_test.get_permissions(self.user_owner, '*')) self.assertTrue( self.project_test.get_permissions(self.user_owner, '*')['admin']) self.assertTrue( self.project_test.get_permission(self.user_owner, '*', 'admin')) def test_project_owner_admin_permission_cannot_be_overwritten(self): self.project_test.set_permission(self.user_owner, '*', 'admin', None) self.assertTrue( self.project_test.get_permission(self.user_owner, '*', 'admin')) self.project_test.set_permission(self.user_owner, '*', 'admin', False) self.assertTrue( self.project_test.get_permission(self.user_owner, '*', 'admin'))
class TestTrac(getConfiguredTestCase(fixture)): def test_create(self): tracenvs = TracEnvironments(self.cydra) self.assertTrue(tracenvs, "Unable to get TracEnvironments instance") guestuser = self.cydra.get_user(userid='*') project = self.cydra.datasource.create_project('tractest', guestuser) self.assertTrue(project, "Unable to create project") self.assertFalse(tracenvs.has_env(project), "Freshly created project should not have a trac env") self.assertTrue(tracenvs.create(project), "Unable to create trac env") self.assertTrue(tracenvs.has_env(project), "has_env should return true after env creation") def test_autodelete_on_project_deletion(self): tracenvs = TracEnvironments(self.cydra) guestuser = self.cydra.get_user(userid='*') project = self.cydra.datasource.create_project('tractest', guestuser) self.assertTrue(tracenvs.create(project), "Unable to create trac env") project.delete() self.assertFalse(tracenvs.has_env(project), "environment not properly removed on project deletion") def test_repository_registration(self): tracenvs = TracEnvironments(self.cydra) guestuser = self.cydra.get_user(userid='*') project = self.cydra.datasource.create_project('tractest', guestuser) self.assertTrue(tracenvs.create(project), "Unable to create trac env") gitrepo = project.get_repository_type('git').create_repository(project, "gitrepo") self.assertTrue(gitrepo, "Unable to create git repository") hgrepo = project.get_repository_type('hg').create_repository(project, "hgrepo") self.assertTrue(hgrepo, "Unable to create hg repository") self.assertTrue(tracenvs.register_repository(gitrepo), "Unable to register git repository") self.assertTrue(tracenvs.register_repository(hgrepo), "Unable to register hg repository") self.assertFalse(tracenvs.register_repository(gitrepo), "Duplicate registration for git repository possible") self.assertFalse(tracenvs.register_repository(hgrepo), "Duplicate registration for hg repository possible") self.assertTrue(tracenvs.is_repository_registered(gitrepo), "Is registered did not return true for gitrepo") self.assertTrue(tracenvs.is_repository_registered(hgrepo), "Is registered did not return true for hgrepo") gitrepo.delete() self.assertFalse(tracenvs.is_repository_registered(gitrepo), "Git repo still registered after repository deletion") self.assertTrue(tracenvs.is_repository_registered(hgrepo), "Is registered did not return true for hgrepo") project.delete() self.assertFalse(tracenvs.is_repository_registered(hgrepo), "Hg repo still registered after project deletion")
class TestArchiver(getConfiguredTestCase(fixture)): """Tests for archiver""" def test_archive_on_delete(self): project = self.cydra.datasource.create_project( 'test', self.cydra.get_user(userid='*')) self.assertTrue(project, "Project creation failed") # set some arbitrary conf values we can check for project.data['test'] = 'test' # create repos created_repos = [] for repotype in project.get_repository_types(): repo = repotype.create_repository(project, "test") self.assertTrue( repo, "Unable to create repo of type " + repotype.repository_type) created_repos.append(repotype.repository_type) project.delete() self.assertIsNone(self.cydra.get_project('test'), "Project was NOT deleted properly") # verify archive exists archive_path = os.path.join(self.cydra.config.get('archive_path'), "test") extracted_path = os.path.join(archive_path, "extracted") files = os.listdir(archive_path) self.assertTrue(len(files) == 1, "Unexpected number of archives") os.mkdir(extracted_path) ret = subprocess.call([ "tar", "-xf", os.path.join(archive_path, files[0]), "-C", extracted_path ]) self.assertTrue(ret == 0, "Extraction failed") self.assertTrue( os.path.exists(os.path.join(extracted_path, "project_data")), "Project data not in archive")
class TestInternalProviderOwnerPermissions( getConfiguredTestCase( fixture, config={ 'components': { 'cydra.permission.InternalPermissionProvider': { 'project_owner_permissions': { 'admin': True, 'manuallyconfigured': True } } } }, create_users=[{ 'username': '******', 'full_name': 'Test Owner' }, { 'username': '******', 'full_name': 'Tester Testesterus' }], create_projects={'test': 'owner'})): """Test that the internal permission provider properly takes owner permissions from config""" def test_project_owner_permissions(self): self.assertEqual( self.project_test.get_permissions(self.user_owner, None), {'*': { 'admin': True, 'manuallyconfigured': True }}) self.assertEqual( self.project_test.get_permissions(self.user_owner, '*'), { 'admin': True, 'manuallyconfigured': True }) self.assertEqual( self.project_test.get_permissions(self.user_owner, 'some_object'), { 'admin': True, 'manuallyconfigured': True }) def test_project_owner_permissions_cannot_be_overwritten(self): self.project_test.set_permission(self.user_owner, '*', 'admin', None) self.assertEqual( self.project_test.get_permissions(self.user_owner, None), {'*': { 'admin': True, 'manuallyconfigured': True }}) self.project_test.set_permission(self.user_owner, '*', 'admin', False) self.assertEqual( self.project_test.get_permissions(self.user_owner, None), {'*': { 'admin': True, 'manuallyconfigured': True }}) def test_project_owner_permissions_get_properly_merged(self): self.project_test.set_permission(self.user_owner, '*', 'foo', True) self.assertEqual( self.project_test.get_permissions(self.user_owner, None), { '*': { 'admin': True, 'manuallyconfigured': True, 'foo': True } }) self.assertEqual( self.project_test.get_permissions(self.user_owner, '*'), { 'admin': True, 'manuallyconfigured': True, 'foo': True })
class TestStaticPermissions( getConfiguredTestCase( fixture, config={ 'components': { 'cydra.permission.StaticPermissionProvider': { 'global_user_permissions': { '*': { 'projects': { 'create': True } }, 'test': { 'projects': { 'foobar': False } } }, 'global_group_permissions': {}, 'user_permissions': { 'test': { 'test': { '*': { 'read': True } } } }, 'group_permissions': {} } } }, create_users=[{ 'username': '******', 'full_name': 'Test Owner' }, { 'username': '******', 'full_name': 'Tester Testesterus' }], create_projects={'test': 'owner'})): """Test that the internal permission provider properly takes owner permissions from config""" def test_global_permissions(self): self.assertEqual(self.cydra.get_permissions(self.user_owner, None), {'projects': { 'create': True }}) self.assertEqual( self.cydra.get_permissions(self.user_owner, 'projects'), {'create': True}) self.assertTrue( self.cydra.get_permission(self.user_owner, 'projects', 'create')) self.assertTrue( self.cydra.get_permission(self.user_test, 'projects', 'create')) self.assertFalse( self.cydra.get_permission(self.user_test, 'projects', 'foobar')) # The following test should pass as well, however this has not yet been implemented! #self.assertEqual(self.cydra.get_permissions(self.user_test, None), {'projects': {'create': True, 'foobar': False}}) def test_global_guest_permissions(self): guest = self.cydra.get_user('*') self.assertEqual( self.cydra.get_permission(guest, 'projects', 'create'), None) self.assertEqual( self.cydra.get_permission(guest, 'projects', 'foobar'), None) self.assertEqual(self.cydra.get_permissions(guest, None), {}) self.assertEqual(self.cydra.get_permissions(guest, 'projects'), {}) def test_user_permissions(self): self.assertEqual( self.project_test.get_permissions(self.user_test, None), {'*': { 'read': True }}) self.assertEqual( self.project_test.get_permissions(self.user_test, 'foobar'), {'read': True}) self.assertTrue( self.project_test.get_permission(self.user_test, 'foobar', 'read'))