Ejemplo n.º 1
0
    def test_does_not_create_workflow_if_already_exists_in_db(self):
        """
        If the collected data already contains a given workflow, then it should be SELECTed, not INSERTed
        """
        existing_workflow = WorkflowFactory(is_default=False)
        component = Workflows(Mock())

        component.workflow(
            "wf1",
            {
                "name": existing_workflow.name,
                "is_default": True,
                "identifier": 'blabla',
                "requires_compliance_number": True,
                "compliance_number_backend": 'blabla',
                "steps": [],
            },
            {},
        )

        workflow = Workflow.objects.get(
        )  # no additional workflow should have been created
        # No fields should have been updated
        self.assertEqual(workflow.name, existing_workflow.name)
        self.assertFalse(workflow.is_default)
        self.assertEqual(workflow.identifier, existing_workflow.identifier)
        self.assertFalse(workflow.requires_compliance_number)
Ejemplo n.º 2
0
 def test_parse(self):
     component = Workflows(Mock())
     with patch.object(component, "roles") as roles, patch.object(
             component, "workflows") as workflows:
         component.parse()
     roles.assert_called_once_with()
     workflows.assert_called_once_with(roles.return_value)
Ejemplo n.º 3
0
    def test_does_not_create_steps_if_workflow_already_exists_in_db(self):
        role = RoleFactory()
        existing_workflow = WorkflowFactory(is_default=False)
        component = Workflows(Mock())

        component.workflow(
            "wf1",
            {
                "name": existing_workflow.name,
                "is_default": True,
                "identifier": 'blabla',
                "requires_compliance_number": True,
                "compliance_number_backend": 'blabla',
                "steps": [{
                    "role": "role1",
                    "is_required": True,
                    "order": 1
                }],
            },
            {"role1": role},
        )

        # No additional workflow should have been created
        workflow = Workflow.objects.get()
        # No steps should have been added
        self.assertEqual(workflow.steps.count(), 0)
Ejemplo n.º 4
0
 def test_workflow(self):
     user = UserFactory()
     role = Role.objects.create(name="Role 1", user=user)
     component = Workflows(Mock())
     component.workflow(
         "wf1",
         {
             "name": "Workflow 1",
             "is_default": True,
             "steps": [{
                 "role": "role1",
                 "is_required": True,
                 "order": 1
             }],
         },
         {"role1": role},
     )
     self.assertIn("wf1", component.data)
     self.assertEqual(component.data["wf1"].name, "Workflow 1")
     self.assertEqual(component.data["wf1"].is_default, True)
     self.assertEqual(component.data["wf1"].steps.count(), 1)
     step = component.data["wf1"].steps.first()
     self.assertEqual(step.role, role)
     self.assertEqual(step.is_required, True)
     self.assertEqual(step.order, 1)
Ejemplo n.º 5
0
 def test_role_group(self):
     group = GroupFactory()
     bootstrap = Mock(groups={"group1": group})
     component = Workflows(bootstrap)
     result = component.role({"group": "group1", "name": "Test role"})
     self.assertEqual(result.name, "Test role")
     self.assertEqual(result.group, group)
Ejemplo n.º 6
0
 def test_role_user(self):
     user = UserFactory()
     bootstrap = Mock(users={"user1": user})
     component = Workflows(bootstrap)
     result = component.role({"user": "******", "name": "Test role"})
     self.assertEqual(result.name, "Test role")
     self.assertEqual(result.user, user)
Ejemplo n.º 7
0
 def test_roles(self):
     role1 = Mock()
     role2 = Mock()
     role3 = Mock()
     roles = {"role1": role1, "role2": role2, "role3": role3}
     bootstrap = Mock(data=Mock(return_value=roles))
     component = Workflows(bootstrap)
     with patch.object(component, "role",
                       side_effect=roles.values()) as role:
         result = component.roles()
     role.assert_has_calls(
         [call(role1), call(role2), call(role3)], any_order=True)
     self.assertEqual(result, {
         "role1": role1,
         "role2": role2,
         "role3": role3
     })
Ejemplo n.º 8
0
    def test_assigns_existing_workflow_to_data(self):
        existing_workflow = WorkflowFactory(is_default=False)
        component = Workflows(Mock())

        component.workflow(
            "wf1",
            {
                "name": existing_workflow.name,
                "is_default": True,
                "identifier": 'blabla',
                "requires_compliance_number": True,
                "compliance_number_backend": 'blabla',
                "steps": [],
            },
            {},
        )

        self.assertDictEqual(component.data, {'wf1': existing_workflow})
Ejemplo n.º 9
0
 def test_workflows(self):
     roles = Mock()
     component = Workflows(Mock())
     component.raw_data = {
         "wf1": {
             "name": "Workflow 1"
         },
         "wf2": {
             "name": "Workflow 2"
         },
     }
     with patch.object(component, "workflow") as workflow:
         component.workflows(roles)
     workflow.assert_has_calls(
         [
             call("wf1", {"name": "Workflow 1"}, roles),
             call("wf2", {"name": "Workflow 2"}, roles),
         ],
         any_order=True,
     )