Exemplo n.º 1
0
 def test_no_matching_external(self) -> None:
     matcher = Mock(return_value=False)
     external = f.external()
     predicate = HasExternal(matcher)
     task = f.task(external=external)
     self.assertFalse(predicate(task, self.client))
     matcher.assert_called_once_with(external)
Exemplo n.º 2
0
 def test_no_workflow_mapping(self) -> None:
     external = f.external(data={})
     task = f.task(external=external)
     stage, context = self.manager.get_current_stage(task)
     expected_context = _ExternalDataWorkflowGetStageContext(
         external=external, workflows={})
     self.assertIsNone(stage)
     self.assertEqual(expected_context, context)
Exemplo n.º 3
0
 def test_matching_stage(self) -> None:
     workflow_data = {"External workflow": "A"}
     external = f.external(data={"workflows": workflow_data})
     task = f.task(external=external)
     stage, context = self.manager.get_current_stage(task)
     expected_context = _ExternalDataWorkflowGetStageContext(
         external=external, workflows=workflow_data)
     self.assertIs(stage, stages[0])
     self.assertEqual(expected_context, context)
Exemplo n.º 4
0
 def expect_context_without_stage(self,
                                  workflow_data: Mapping[str, str]) -> None:
     external = f.external(data={"workflows": workflow_data})
     task = f.task(external=external)
     stage, context = self.manager.get_current_stage(task)
     expected_context = _ExternalDataWorkflowGetStageContext(
         external=external, workflows=workflow_data)
     self.assertIsNone(stage)
     self.assertEqual(expected_context, context)
Exemplo n.º 5
0
 def test_set_external(self) -> None:
     external = f.external("1", {"a": "b"})
     self.inner_mock.tasks.update.return_value = None
     self.client.set_external(self.task, external)
     self.inner_mock.tasks.update.assert_called_once_with(
         self.task.gid, {"external": {
             "gid": "1",
             "data": '{"a": "b"}'
         }})
Exemplo n.º 6
0
 def test_can_set_stage(self) -> None:
     workflow_data = {"External workflow": "A"}
     external = f.external(data={"workflows": workflow_data})
     client = create_autospec(Client)
     get_context = _ExternalDataWorkflowGetStageContext(
         external, workflow_data)
     set_context = self.manager.can_set_stage(stages[0], client,
                                              get_context)
     expected_context = _ExternalDataWorkflowSetStageContext(
         external, workflow_data, "A")
     self.assertEqual(expected_context, set_context)
Exemplo n.º 7
0
 def expect_set(self, original_workflow_data: Mapping[str, str]) -> None:
     external = f.external(data={"workflows": original_workflow_data})
     task = f.task(external=external)
     client = create_autospec(Client)
     context = _ExternalDataWorkflowSetStageContext(external,
                                                    original_workflow_data,
                                                    "new stage name")
     client.set_external.return_value = None
     self.manager.set_stage(task, client, context)
     client.set_external.assert_called_once_with(
         task,
         External(
             context.external.gid,
             {
                 "workflows": {
                     "External workflow": "new stage name",
                     "other workflow": "other stage name",
                 }
             },
         ),
     )
Exemplo n.º 8
0
 def test(self) -> None:
     external = f.external()
     client = create_autospec(Client)
     action = SetExternal(external)
     action(task, client)
     client.set_external.assert_called_once_with(task, external)
Exemplo n.º 9
0
 def test_has_external(self) -> None:
     predicate = HasExternal()
     task = f.task(external=f.external())
     self.assertTrue(predicate(task, self.client))