def test_get_detailed_description(self): """ Verify that the detailed description text is valid """ # description functions are optional task = TaskFactory() self.assertEqual(task.get_detailed_description(), '') no_kwargs = { 'path': ('orchestra.tests.helpers.' 'fixtures.get_detailed_description') } task_no_kwargs = TaskFactory(step=StepFactory( slug='stepslug', detailed_description_function=no_kwargs)) self.assertEqual(task_no_kwargs.get_detailed_description(), 'No text given stepslug') with_kwargs = { 'path': ('orchestra.tests.helpers.' 'fixtures.get_detailed_description'), 'kwargs': { 'text': 'task 2 text', } } task_with_kwargs = TaskFactory(step=StepFactory( slug='stepslug', detailed_description_function=with_kwargs)) self.assertEqual(task_with_kwargs.get_detailed_description(), 'task 2 text stepslug') extra_kwargs = {'text': 'extra text'} self.assertEqual( task_with_kwargs.get_detailed_description( extra_kwargs=extra_kwargs), 'extra text stepslug')
def test_malformed_creation_policy(self): project = self.projects['creation_policy'] workflow_version = project.workflow_version first_step = self.workflow_steps[ workflow_version.slug]['creation_policy_step_0'] # Create an invalid machine step with an assignment policy malformed_step = StepFactory( workflow_version=workflow_version, slug='machine_step', is_human=False, creation_policy={}, ) malformed_step.creation_depends_on.add(first_step) # Create first task in project create_subsequent_tasks(project) self.assertEqual(project.tasks.count(), 1) # Assign initial task to worker 0 and mark as complete initial_task = assign_task(self.workers[4].id, project.tasks.first().id) initial_task.status = Task.Status.COMPLETE initial_task.save() # Cannot have an invalid blob for the creation_policy with self.assertRaises(CreationPolicyError): create_subsequent_tasks(project)
def setUp(self): super().setUp() self.request_client = APIClient(enforce_csrf_checks=True) self.request_client.force_authenticate(user=SignedUser()) self.workflow_version = WorkflowVersionFactory() self.step = StepFactory(slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory(workflow_version=self.workflow_version)
def test_malformed_assignment_policy(self): project = self.projects['assignment_policy'] workflow_version = project.workflow_version first_step = self.workflow_steps[workflow_version.slug]['step_0'] # Create an invalid machine step with an assignment policy malformed_step = StepFactory( workflow_version=workflow_version, slug='machine_step', is_human=False, assignment_policy={ 'policy_function': { 'entry_level': { 'path': ('orchestra.assignment_policies.' 'previously_completed_steps'), 'kwargs': { 'related_steps': ['step_0'] }, } } }, creation_policy=get_default_creation_policy(), ) malformed_step.creation_depends_on.add(first_step) # Create first task in project create_subsequent_tasks(project) self.assertEqual(project.tasks.count(), 1) # Assign initial task to worker 0 and mark as complete initial_task = assign_task(self.workers[4].id, project.tasks.first().id) initial_task.status = Task.Status.COMPLETE initial_task.save() # Cannot preassign machine task with self.assertRaises(AssignmentPolicyError): create_subsequent_tasks(project) # Reset project project.tasks.all().delete() # Machine should not be member of assignment policy first_step.assignment_policy = { 'policy_function': { 'entry_level': { 'path': ('orchestra.assignment_policies.' 'previously_completed_steps'), 'kwargs': { 'related_steps': ['machine_step'] }, }, } } first_step.save() with self.assertRaises(AssignmentPolicyError): create_subsequent_tasks(project)
def setUp(self): super().setUp() setup_models(self) self.workflow_version = WorkflowVersionFactory() self.step = StepFactory( slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory( workflow_version=self.workflow_version)
def test_get_todos(self, mock_request): # This converts `requests.get` into DRF's `APIClient.get` # To make it testable def get(url, *args, **kwargs): return_value = self.request_client.get(url, format='json') return_value.text = json.dumps(return_value.data) return return_value mock_request.get = get step_1 = StepFactory(slug='step_1') step_2 = StepFactory(slug='step_2') project2 = ProjectFactory() # 2 todos have the same project todo1 = TodoFactory(step=step_1, project=self.project) todo2 = TodoFactory(step=step_1, project=self.project) # 1 todo has another project todo3 = TodoFactory(step=step_2, project=project2) todo4 = TodoFactory(step=step_1, project=project2) # Get todo1 and todo2 res = get_todos(self.project.id, step_1.slug) self.assertEqual(len(res), 2) expected_ids = [todo1.id, todo2.id] for r in res: self.assertIn(r['id'], expected_ids) # Get todo3 res = get_todos(project2.id, step_2.slug) self.assertEqual(len(res), 1) self.assertEqual(res[0]['id'], todo3.id) # Filter by project_id res = get_todos(project_id=project2.id) self.assertEqual(len(res), 2) expected_ids = [todo3.id, todo4.id] for r in res: self.assertIn(r['id'], expected_ids) # Test project_id is required msg = 'project_id is required' with self.assertRaisesMessage(OrchestraError, msg): get_todos(None)
def _task_factory(status, path): description_no_kwargs = {'path': path} return TaskFactory( status=status, step=StepFactory( slug='stepslug', description='the step', detailed_description_function=description_no_kwargs), project__workflow_version__workflow__description=( 'the workflow'), project__short_description='the coolest project')
def setUp(self): super().setUp() self.request_client = APIClient(enforce_csrf_checks=True) self.request_client.force_authenticate(user=SignedUser()) setup_models(self) self.workflow_version = WorkflowVersionFactory() self.step = StepFactory(slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory(workflow_version=self.workflow_version) self.list_url = reverse('orchestra:api:todo-api-list') self.todo = TodoFactory(project=self.project) self.todo_with_step = TodoFactory(project=self.project, step=self.step)
def setUp(self): super().setUp() self.request_client = APIClient(enforce_csrf_checks=True) self.request_client.force_authenticate(user=SignedUser()) self.todolist_template_slug = 'test_todolist_template_slug' self.todolist_template_name = 'test_todolist_template_name' self.todolist_template_description = \ 'test_todolist_template_description' self.workflow_version = WorkflowVersionFactory() self.step = StepFactory(slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory(workflow_version=self.workflow_version)
def setUp(self): super().setUp() project = ProjectFactory() step = StepFactory() self.old_title = 'Old title' self.new_title = 'New title' self.old_details = 'Old details' self.new_details = 'New details' self.old_todo = TodoFactory(title=self.old_title, details=self.old_details, completed=False, project=project, step=step) self.new_todo = TodoFactory(title=self.new_title, details=self.new_details, completed=True, project=project, step=step) self.sender = UserFactory()
def setUp(self): super().setUp() setup_models(self) self.worker = Worker.objects.get(user__username='******') self.request_client.login(username=self.worker.user.username, password='******') self.list_create_url = reverse('orchestra:todos:todos-list') self.list_details_url_name = 'orchestra:todos:todos-detail' self.workflow_version = WorkflowVersionFactory() self.step = StepFactory(slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory(workflow_version=self.workflow_version) tasks = Task.objects.filter(assignments__worker=self.worker) task = tasks[0] task.project = self.project task.step = self.step task.save() self.todo_title = 'Let us do this' self.deadline = parse('2018-01-16T07:03:00+00:00')
def setUp(self): super().setUp() setup_models(self) self.worker = Worker.objects.get(user__username='******') self.request_client.login(username=self.worker.user.username, password='******') self.todolist_template_list_url = reverse( 'orchestra:todos:todolist_templates') self.todolist_template_detail_url_name = \ 'orchestra:todos:todolist_template' self.todolist_template_slug = 'test_todolist_template_slug' self.todolist_template_name = 'test_todolist_template_name' self.todolist_template_description = \ 'test_todolist_template_description' self.workflow_version = WorkflowVersionFactory() self.step = StepFactory(slug='step-slug', workflow_version=self.workflow_version) self.project = ProjectFactory(workflow_version=self.workflow_version) self.project2 = ProjectFactory() tasks = Task.objects.filter(assignments__worker=self.worker) self.task = tasks[0] self.task.project = self.project self.task.step = self.step self.task.save()
def setUp(self): super().setUp() setup_models(self) self.worker = Worker.objects.get(user__username='******') self.request_client.login(username=self.worker.user.username, password='******') self.list_create_url = reverse('orchestra:todos:todo_qas') self.worker_task_recent_todo_qas_url = reverse( 'orchestra:todos:worker_task_recent_todo_qas') self.list_details_url_name = 'orchestra:todos:todo_qa' self.project0 = ProjectFactory() self.project1 = ProjectFactory() self.step = StepFactory(slug='some-slug') tasks = Task.objects.filter(assignments__worker=self.worker) self.task_0 = tasks[0] self.task_0.project = self.project0 self.task_0.step = self.step self.task_0.save() self.task_1 = tasks[1] self.task_1.project = self.project1 self.task_1.step = self.step self.task_1.save() self.todo = TodoFactory(project=self.project0, step=self.step) self.comment = 'Test comment'
def test_todo_qas_create_permissions(self): # Can't make requests for projects in which you're uninvolved. project = ProjectFactory() step = StepFactory() todo = TodoFactory(project=project, step=step) self._verify_todo_qa_creation(todo, False)
def test_todos_list_create_permissions(self): # Can't make requests for projects in which you're uninvolved. project = ProjectFactory() step = StepFactory() self._verify_todos_list(project.id, [], False) self._verify_todo_creation(False, project.id, step)