def setUp(self, **kwargs): AbstractFlamencoTest.setUp(self, **kwargs) self.mngr = self.app.pillar_extensions['flamenco'].task_manager self.proj_id, self.project = self.ensure_project_exists() self.sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(self.project))
def test_delete_repo_happy(self, mock_delete_repo): from svnman import EXTENSION_NAME from pillar.api.projects.utils import put_project self.enter_app_context() self.login_api_as(24 * 'a', roles={'admin'}) self.project['extension_props'] = { EXTENSION_NAME: { 'repo_id': 'existing-repo-id', 'users': { '5551234': { 'set_pw': True, 'username': '******' } }, } } self.sdk_project = pillarsdk.Project( pillar.tests.mongo_to_sdk(self.project)) put_project(self.project) self.svnman.delete_repo(self.sdk_project, 'existing-repo-id') mock_delete_repo.assert_called_with('existing-repo-id') db_proj = self.fetch_project_from_db(self.proj_id) self.assertEqual({EXTENSION_NAME: {}}, db_proj['extension_props'])
def test_is_svnman_project(self): svn = self.svnman sdk_project = None def conv(): nonlocal sdk_project sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(project)) # Default just-created project project = copy.deepcopy(self.project) conv() self.assertFalse(svn.is_svnman_project(sdk_project)) project['extension_props'] = None conv() self.assertFalse(svn.is_svnman_project(sdk_project)) # With empty svnman extensions. We don't make any distinction between # 'set up for SVNman' or 'has an actual repository'; the former → false, # the latter → true. project['extension_props'] = {'svnman': {}} conv() self.assertFalse(svn.is_svnman_project(sdk_project)) project['extension_props'] = { 'svnman': { 'repo_id': 'something-random' } } conv() self.assertTrue(svn.is_svnman_project(sdk_project)) self.assertFalse(svn.is_svnman_project(pillarsdk.Project()))
def setUp(self, **kwargs): super().setUp(**kwargs) from svnman.remote import API self.remote: API = self.svnman.remote self.proj_id, self.project = self.ensure_project_exists( project_overrides={ 'picture_header': None, 'picture_square': None, }) self.sdk_project = pillarsdk.Project( pillar.tests.mongo_to_sdk(self.project))
def test_setup_through_web(self): self.do_setup_for_flamenco() # Test that the project is set up for Flamenco and has a Manager assigned. # The Manager should have been created too. new_proj = self.get(f'/api/projects/{self.project_id}', auth_token='admin-token').json self.assertTrue(self.flamenco.is_flamenco_project(pillarsdk.Project(new_proj))) man_man = self.flamenco.manager_manager with self.app.test_request_context(): project_managers = man_man.managers_for_project(self.project_id) self.assertEqual(1, len(project_managers)) manager_id = project_managers[0] self.assertManagerAssigned(manager_id)
def setUp(self, **kwargs): super().setUp(**kwargs) overrides = {'_id': bson.ObjectId(24 * 'b'), 'url': 'fresh-project', 'picture_header': None, 'picture_square': None} self.create_project_with_admin(24 * 'a', {'subscriber', 'flamenco-user'}, project_overrides=overrides) self.create_valid_auth_token(24 * 'a', 'admin-token') self.project_id, self.proj = AbstractPillarTest.ensure_project_exists(self, overrides) self.sdk_proj = pillarsdk.Project(self.proj) self.assertFalse(self.flamenco.is_flamenco_project(self.sdk_proj))
def setUp(self, **kwargs): super().setUp(**kwargs) from flamenco.tasks import TaskManager from flamenco.jobs import JobManager self.tmngr: TaskManager = self.flamenco.task_manager self.jmngr: JobManager = self.flamenco.job_manager self.proj_id, self.project = self.ensure_project_exists() self.sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(self.project)) # Set these in a subclass. self.task_ids = [] self.job_id = None
def project_url(project_id: str, project: pillarsdk.Project = None) -> pillarsdk.Project: """Returns the project, raising a ValueError if it can't be found. Uses a direct MongoDB query to allow calls by any user. Only returns a partial project with the _id and url properties set. """ if project is not None: return project proj_coll = current_app.db('projects') proj = proj_coll.find_one({'_id': bson.ObjectId(project_id)}, {'url': 1}) if proj is None: log.error( 'project_url(%s): project does not exist, cannot find its URL', project_id) raise wz_exceptions.NotFound() return pillarsdk.Project(proj)
def test_setup_autoassign_manager(self): man_man = self.flamenco.manager_manager with self.app.test_request_context(): from pillar.api.utils.authentication import force_cli_user force_cli_user() _, mngr_doc, _ = man_man.create_new_manager('pre-existing manager', '', bson.ObjectId(24 * 'a')) self.do_setup_for_flamenco() # Test that the project is set up for Flamenco and has a Manager assigned. new_proj = self.get(f'/api/projects/{self.project_id}', auth_token='admin-token').json self.assertTrue(self.flamenco.is_flamenco_project(pillarsdk.Project(new_proj))) with self.app.test_request_context(): project_managers = man_man.managers_for_project(self.project_id) expected_manager_id = mngr_doc['_id'] self.assertEqual([expected_manager_id], project_managers) self.assertManagerAssigned(expected_manager_id)
def test_delete_repo_wrong_id(self, mock_delete_repo): from svnman import EXTENSION_NAME from pillar.api.projects.utils import put_project self.enter_app_context() self.login_api_as(24 * 'a', roles={'admin'}) self.project['extension_props'] = { EXTENSION_NAME: { 'repo_id': 'existing-repo-id' } } self.sdk_project = pillarsdk.Project( pillar.tests.mongo_to_sdk(self.project)) put_project(self.project) with self.assertRaises(ValueError): self.svnman.delete_repo(self.sdk_project, 'other-repo-id') mock_delete_repo.assert_not_called() db_proj = self.fetch_project_from_db(self.proj_id) self.assertEqual({EXTENSION_NAME: { 'repo_id': 'existing-repo-id' }}, db_proj['extension_props'])
def conv(): nonlocal sdk_project sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(project))