Example #1
0
    def test_ensure_task_assignment_to_project(self):
        from pybossa import data_access

        project = ProjectFactory.create(info={})
        task = TaskFactory.create(info={})
        with patch.object(data_access, 'data_access_levels',
                          self.patch_data_access_levels):
            self.patch_data_access_levels[
                'valid_project_levels_for_task_level'] = {
                    'A': ['A']
                }
            self.patch_data_access_levels[
                'valid_task_levels_for_project_level'] = {
                    'A': ['A']
                }
            with assert_raises(Exception):
                data_access.ensure_task_assignment_to_project(task, project)
            project.info['data_access'] = ['A']
            with assert_raises(Exception):
                data_access.ensure_task_assignment_to_project(task, project)
            project.info['data_access'] = []
            task.info['data_access'] = ['A']
            with assert_raises(Exception):
                data_access.ensure_task_assignment_to_project(task, project)
            project.info['data_access'] = ['A', 'B']
            task.info['data_access'] = ['A']
            with assert_raises(Exception):
                data_access.ensure_task_assignment_to_project(task, project)
            project.info['ext_config'] = {
                'data_access': {
                    'tracking_id': '123'
                }
            }
            data_access.ensure_task_assignment_to_project(task, project)
Example #2
0
 def _validate_can_be(self, action, element):
     from flask import current_app
     from pybossa.core import project_repo
     if not isinstance(element, Task) and not isinstance(element, TaskRun):
         name = element.__class__.__name__
         msg = '%s cannot be %s by %s' % (name, action, self.__class__.__name__)
         raise WrongObjectError(msg)
     if isinstance(element, Task) and (action in [self.SAVE_ACTION, self.UPDATE_ACTION]):
         project = project_repo.get(element.project_id)
         ensure_task_assignment_to_project(element, project)
Example #3
0
 def test_ensure_task_assignment_to_project(self):
     project = ProjectFactory.create(info={})
     task = TaskFactory.create(info={})
     patched_levels = self.patched_levels(
         valid_project_levels_for_task_level={'A': ['A']},
         valid_task_levels_for_project_level={'A': ['A']}
     )
     with patch.dict(data_access.data_access_levels, patched_levels):
         with assert_raises(Exception):
             data_access.ensure_task_assignment_to_project(task, project)
         project.info['data_access'] = ['A']
         with assert_raises(Exception):
             data_access.ensure_task_assignment_to_project(task, project)
         project.info['data_access'] = []
         task.info['data_access'] = ['A']
         with assert_raises(Exception):
             data_access.ensure_task_assignment_to_project(task, project)
         project.info['data_access'] = ['A', 'B']
         task.info['data_access'] = ['A']
         with assert_raises(Exception):
             data_access.ensure_task_assignment_to_project(task, project)
         project.info['ext_config'] = {'data_access': {'tracking_id': '123'}}
         data_access.ensure_task_assignment_to_project(task, project)