wbcore 2.2.3__py2.py3-none-any.whl → 2.2.5__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wbcore/contrib/color/admin.py +28 -0
- wbcore/contrib/color/apps.py +5 -0
- wbcore/contrib/color/enums.py +17 -0
- wbcore/contrib/color/factories.py +10 -0
- wbcore/contrib/color/fields.py +29 -0
- wbcore/contrib/color/forms.py +13 -0
- wbcore/contrib/color/models.py +62 -0
- wbcore/contrib/color/tests/conftest.py +10 -0
- wbcore/contrib/color/tests/test_color_models.py +61 -0
- wbcore/contrib/color/tests/test_fields.py +25 -0
- wbcore/contrib/documents/tests/conftest.py +30 -0
- wbcore/contrib/documents/tests/test_models.py +144 -0
- wbcore/contrib/example_app/tests/test_models/test_event.py +87 -0
- wbcore/contrib/example_app/tests/test_models/test_match.py +210 -0
- wbcore/contrib/example_app/tests/test_models/test_others.py +159 -0
- wbcore/contrib/example_app/tests/test_serializers/test_league_serializer.py +34 -0
- wbcore/contrib/example_app/tests/test_serializers/test_match_serializer.py +134 -0
- wbcore/contrib/example_app/tests/test_serializers/test_role_serializer.py +13 -0
- wbcore/contrib/example_app/tests/test_serializers/test_sport_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_stadium_serializer.py +14 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_result_serializer.py +30 -0
- wbcore/contrib/example_app/tests/test_serializers/test_team_serializer.py +70 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_event_viewset.py +162 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_league_viewset.py +84 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_match_viewset.py +65 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_person_viewset.py +166 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_role_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_sport_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_stadium_viewset.py +75 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_team_viewset.py +92 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_teamresult_viewset.py +58 -0
- wbcore/contrib/example_app/tests/test_viewsets/test_utils_viewsets.py +124 -0
- wbcore/contrib/guardian/apps.py +6 -0
- wbcore/contrib/guardian/configurations.py +3 -0
- wbcore/contrib/guardian/filters.py +21 -0
- wbcore/contrib/guardian/tasks.py +10 -0
- wbcore/contrib/guardian/urls.py +12 -0
- wbcore/contrib/guardian/utils.py +124 -0
- wbcore/contrib/notifications/viewsets/configs/notification_types.py +27 -0
- wbcore/contrib/notifications/viewsets/configs/notifications.py +85 -0
- wbcore/contrib/workflow/tests/test_models/step/test_decision_step.py +79 -0
- wbcore/contrib/workflow/tests/test_models/step/test_email_step.py +45 -0
- wbcore/contrib/workflow/tests/test_models/step/test_finish_step.py +105 -0
- wbcore/contrib/workflow/tests/test_models/step/test_join_step.py +127 -0
- wbcore/contrib/workflow/tests/test_models/step/test_script_step.py +24 -0
- wbcore/contrib/workflow/tests/test_models/step/test_split_step.py +49 -0
- wbcore/contrib/workflow/tests/test_models/step/test_step.py +621 -0
- wbcore/contrib/workflow/tests/test_models/step/test_user_step.py +225 -0
- wbcore/contrib/workflow/tests/test_models/test_condition.py +103 -0
- wbcore/contrib/workflow/tests/test_models/test_data.py +134 -0
- wbcore/contrib/workflow/tests/test_models/test_process.py +98 -0
- wbcore/contrib/workflow/tests/test_models/test_transition.py +128 -0
- wbcore/contrib/workflow/tests/test_models/test_workflow.py +358 -0
- wbcore/templates/forms.py +0 -0
- wbcore/test/e2e_helpers_methods/e2e_checks.py +121 -0
- wbcore/test/e2e_helpers_methods/e2e_helper_methods.py +395 -0
- wbcore/tests/test_permissions/test_backend.py +29 -0
- {wbcore-2.2.3.dist-info → wbcore-2.2.5.dist-info}/METADATA +1 -1
- {wbcore-2.2.3.dist-info → wbcore-2.2.5.dist-info}/RECORD +60 -16
- wbcore/contrib/agenda/release_notes/1_0_0.md +0 -13
- wbcore/contrib/authentication/release_notes/1_0_0.md +0 -13
- wbcore/contrib/currency/release_notes/1_0_0.md +0 -13
- wbcore/contrib/directory/release_notes/1_0_0.md +0 -13
- wbcore/contrib/directory/release_notes/1_0_1.md +0 -13
- wbcore/contrib/documents/release_notes/1_0_0.md +0 -13
- wbcore/contrib/geography/release_notes/1_0_0.md +0 -13
- wbcore/contrib/io/release_notes/1_0_0.md +0 -13
- wbcore/contrib/notifications/release_notes/1_0_0.md +0 -13
- wbcore/contrib/tags/release_notes/1_0_0.md +0 -13
- wbcore/docs/orderable.md +0 -29
- wbcore/docs/reparent.md +0 -13
- wbcore/templates/reversion/compare_detail.html +0 -19
- {wbcore-2.2.3.dist-info → wbcore-2.2.5.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from wbcore.contrib.directory.factories import PersonFactory
|
|
5
|
+
from wbcore.contrib.workflow.models import Condition
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.django_db
|
|
9
|
+
class TestDecisionStep:
|
|
10
|
+
def test_get_first_valid_transition(
|
|
11
|
+
self, process_step_factory, decision_step_factory, transition_factory, condition_factory
|
|
12
|
+
):
|
|
13
|
+
attached_instance = PersonFactory()
|
|
14
|
+
step = decision_step_factory()
|
|
15
|
+
process_step = process_step_factory(process__instance=attached_instance, step=step)
|
|
16
|
+
valid_transition1 = transition_factory(from_step=step)
|
|
17
|
+
valid_transition2 = transition_factory(from_step=step)
|
|
18
|
+
invalid_transition = transition_factory(from_step=step)
|
|
19
|
+
transition_factory()
|
|
20
|
+
condition_factory(
|
|
21
|
+
transition=invalid_transition,
|
|
22
|
+
attribute_name="first_name",
|
|
23
|
+
expected_value=attached_instance.first_name,
|
|
24
|
+
operator=Condition.Operator.EQ,
|
|
25
|
+
negate_operator=True,
|
|
26
|
+
)
|
|
27
|
+
assert step.get_first_valid_transition(process_step) in [valid_transition1, valid_transition2]
|
|
28
|
+
|
|
29
|
+
def test_get_first_valid_transition_no_transitions(
|
|
30
|
+
self, process_step_factory, decision_step_factory, transition_factory, condition_factory
|
|
31
|
+
):
|
|
32
|
+
attached_instance = PersonFactory()
|
|
33
|
+
step = decision_step_factory()
|
|
34
|
+
process_step = process_step_factory(process__instance=attached_instance, step=step)
|
|
35
|
+
invalid_transition = transition_factory(from_step=step)
|
|
36
|
+
transition_factory()
|
|
37
|
+
condition_factory(
|
|
38
|
+
transition=invalid_transition,
|
|
39
|
+
attribute_name="first_name",
|
|
40
|
+
expected_value=attached_instance.first_name,
|
|
41
|
+
operator=Condition.Operator.EQ,
|
|
42
|
+
negate_operator=True,
|
|
43
|
+
)
|
|
44
|
+
assert step.get_first_valid_transition(process_step) is None
|
|
45
|
+
|
|
46
|
+
@patch("wbcore.contrib.workflow.models.step.DecisionStep.get_first_valid_transition")
|
|
47
|
+
@patch("wbcore.contrib.workflow.models.step.Step.start_next_step")
|
|
48
|
+
def test_run(
|
|
49
|
+
self,
|
|
50
|
+
mock_next,
|
|
51
|
+
mock_transition,
|
|
52
|
+
process_step_factory,
|
|
53
|
+
transition_factory,
|
|
54
|
+
decision_step_factory,
|
|
55
|
+
):
|
|
56
|
+
transition = transition_factory()
|
|
57
|
+
mock_transition.return_value = transition
|
|
58
|
+
step = decision_step_factory()
|
|
59
|
+
process_step = process_step_factory(step=step)
|
|
60
|
+
step.run(process_step)
|
|
61
|
+
assert mock_next.call_args.args == (process_step, transition)
|
|
62
|
+
|
|
63
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
64
|
+
@patch("wbcore.contrib.workflow.models.step.activate_step.delay")
|
|
65
|
+
@patch("wbcore.contrib.workflow.models.step.DecisionStep.get_first_valid_transition")
|
|
66
|
+
def test_run_failed(
|
|
67
|
+
self,
|
|
68
|
+
mock_transition,
|
|
69
|
+
mock_activate,
|
|
70
|
+
mock_failed,
|
|
71
|
+
process_step_factory,
|
|
72
|
+
decision_step_factory,
|
|
73
|
+
):
|
|
74
|
+
mock_transition.return_value = None
|
|
75
|
+
step = decision_step_factory()
|
|
76
|
+
process_step = process_step_factory(step=step)
|
|
77
|
+
step.run(process_step)
|
|
78
|
+
assert mock_failed.call_args.args[0] == process_step
|
|
79
|
+
assert not mock_activate.called
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from django.template import TemplateSyntaxError
|
|
5
|
+
from wbcore.contrib.directory.factories import EmailContactFactory
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.django_db
|
|
9
|
+
class TestEmailStep:
|
|
10
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
11
|
+
@patch("django.core.mail.EmailMultiAlternatives.__init__")
|
|
12
|
+
@patch("django.core.mail.EmailMultiAlternatives.send")
|
|
13
|
+
@patch("django.core.mail.EmailMultiAlternatives.attach_alternative")
|
|
14
|
+
def test_run(self, mock_attach, mock_send, mock_init, mock_execute, process_step_factory, email_step_factory):
|
|
15
|
+
step = email_step_factory(to=[EmailContactFactory()], cc=[EmailContactFactory(), EmailContactFactory()])
|
|
16
|
+
process_step = process_step_factory(step=step)
|
|
17
|
+
mock_init.return_value = None
|
|
18
|
+
step.run(process_step)
|
|
19
|
+
assert mock_init.call_args.args[0] == step.subject
|
|
20
|
+
assert mock_init.call_args.kwargs == {
|
|
21
|
+
"to": list(step.to.values_list("address", flat=True)),
|
|
22
|
+
"cc": list(step.cc.values_list("address", flat=True)),
|
|
23
|
+
"bcc": [],
|
|
24
|
+
}
|
|
25
|
+
assert mock_attach.called
|
|
26
|
+
assert mock_send.called
|
|
27
|
+
assert mock_execute.call_args.args == (process_step,)
|
|
28
|
+
|
|
29
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
30
|
+
@patch("django.template.Template.render")
|
|
31
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
32
|
+
@patch("django.core.mail.EmailMultiAlternatives.send")
|
|
33
|
+
def test_run_failed(
|
|
34
|
+
self, mock_send, mock_execute, mock_render, mock_set_failed, process_step_factory, email_step_factory
|
|
35
|
+
):
|
|
36
|
+
step = email_step_factory(
|
|
37
|
+
to=[EmailContactFactory()],
|
|
38
|
+
cc=[EmailContactFactory(), EmailContactFactory()],
|
|
39
|
+
)
|
|
40
|
+
process_step = process_step_factory(step=step)
|
|
41
|
+
mock_render.side_effect = TemplateSyntaxError
|
|
42
|
+
step.run(process_step)
|
|
43
|
+
assert not mock_send.called
|
|
44
|
+
assert not mock_execute.called
|
|
45
|
+
assert mock_set_failed.call_args.args[0] == process_step
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from wbcore.contrib.directory.models import Person
|
|
5
|
+
from wbcore.contrib.workflow.models import Process, ProcessStep
|
|
6
|
+
from wbcore.contrib.workflow.sites import workflow_site
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.django_db
|
|
10
|
+
class TestFinishStep:
|
|
11
|
+
@pytest.mark.parametrize(
|
|
12
|
+
"finished_state",
|
|
13
|
+
[ProcessStep.StepState.FAILED, ProcessStep.StepState.CANCELED, ProcessStep.StepState.FINISHED],
|
|
14
|
+
)
|
|
15
|
+
@pytest.mark.parametrize("unfinished_state", [ProcessStep.StepState.ACTIVE, ProcessStep.StepState.WAITING])
|
|
16
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_finished")
|
|
17
|
+
def test_run(self, mock_finish, process_step_factory, finish_step_factory, unfinished_state, finished_state):
|
|
18
|
+
step = finish_step_factory()
|
|
19
|
+
process_step = process_step_factory(step=step)
|
|
20
|
+
process_step_factory(process=process_step.process, state=finished_state)
|
|
21
|
+
process_step_factory(step=step, state=unfinished_state)
|
|
22
|
+
step.run(process_step)
|
|
23
|
+
assert mock_finish.call_args.args == (process_step,)
|
|
24
|
+
|
|
25
|
+
@pytest.mark.parametrize("unfinished_state", [ProcessStep.StepState.ACTIVE, ProcessStep.StepState.WAITING])
|
|
26
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
27
|
+
def test_run_failed(self, mock_failed, process_step_factory, finish_step_factory, unfinished_state):
|
|
28
|
+
step = finish_step_factory()
|
|
29
|
+
process_step = process_step_factory(step=step)
|
|
30
|
+
process_step_factory(process=process_step.process, state=unfinished_state)
|
|
31
|
+
step.run(process_step)
|
|
32
|
+
assert mock_failed.call_args.args[0] == process_step
|
|
33
|
+
|
|
34
|
+
@pytest.mark.parametrize(
|
|
35
|
+
"unfinished_state",
|
|
36
|
+
[
|
|
37
|
+
ProcessStep.StepState.ACTIVE,
|
|
38
|
+
ProcessStep.StepState.WAITING,
|
|
39
|
+
ProcessStep.StepState.CANCELED,
|
|
40
|
+
ProcessStep.StepState.FAILED,
|
|
41
|
+
],
|
|
42
|
+
)
|
|
43
|
+
@patch("wbcore.contrib.workflow.models.step.Step.finish")
|
|
44
|
+
def test_finish_not_finished(self, mock_finish, unfinished_state, process_step_factory, finish_step_factory):
|
|
45
|
+
step = finish_step_factory(write_preserved_instance=True)
|
|
46
|
+
process_step = process_step_factory(
|
|
47
|
+
process__preserved_instance={"first_name": "Test"},
|
|
48
|
+
step=step,
|
|
49
|
+
process__finished=None,
|
|
50
|
+
state=unfinished_state,
|
|
51
|
+
process__state=Process.ProcessState.ACTIVE,
|
|
52
|
+
)
|
|
53
|
+
step.finish(process_step)
|
|
54
|
+
assert mock_finish.call_args.args == (process_step,)
|
|
55
|
+
assert process_step.process.finished is None
|
|
56
|
+
assert process_step.process.instance.first_name != "Test"
|
|
57
|
+
assert process_step.process.state == Process.ProcessState.ACTIVE
|
|
58
|
+
|
|
59
|
+
@patch("wbcore.contrib.workflow.models.step.Step.finish")
|
|
60
|
+
def test_finish_write_preserved_instance(self, mock_finish, process_step_factory, finish_step_factory):
|
|
61
|
+
step = finish_step_factory(write_preserved_instance=True, workflow__preserve_instance=True)
|
|
62
|
+
process_step = process_step_factory(
|
|
63
|
+
step=step,
|
|
64
|
+
process__finished=None,
|
|
65
|
+
state=ProcessStep.StepState.FINISHED,
|
|
66
|
+
process__workflow=step.workflow,
|
|
67
|
+
)
|
|
68
|
+
old_name = process_step.process.instance.first_name
|
|
69
|
+
workflow_site.registered_model_classes_serializer_map[
|
|
70
|
+
Person
|
|
71
|
+
] = "wbcore.contrib.directory.serializers.PersonModelSerializer"
|
|
72
|
+
step.finish(process_step)
|
|
73
|
+
assert mock_finish.call_args.args == (process_step,)
|
|
74
|
+
assert process_step.process.finished is not None
|
|
75
|
+
assert process_step.process.instance.first_name != old_name
|
|
76
|
+
assert process_step.process.instance.first_name == process_step.process.preserved_instance["first_name"]
|
|
77
|
+
assert process_step.process.state == Process.ProcessState.FINISHED
|
|
78
|
+
|
|
79
|
+
@patch("wbcore.contrib.workflow.models.step.Step.finish")
|
|
80
|
+
def test_finish_do_not_write(self, mock_finish, process_step_factory, finish_step_factory):
|
|
81
|
+
step = finish_step_factory(write_preserved_instance=False, workflow__preserve_instance=True)
|
|
82
|
+
process_step = process_step_factory(
|
|
83
|
+
step=step,
|
|
84
|
+
process__finished=None,
|
|
85
|
+
state=ProcessStep.StepState.FINISHED,
|
|
86
|
+
)
|
|
87
|
+
old_name = process_step.process.instance.first_name
|
|
88
|
+
step.finish(process_step)
|
|
89
|
+
assert mock_finish.call_args.args == (process_step,)
|
|
90
|
+
assert process_step.process.finished is not None
|
|
91
|
+
assert process_step.process.instance.first_name == old_name
|
|
92
|
+
assert process_step.process.state == Process.ProcessState.FINISHED
|
|
93
|
+
|
|
94
|
+
@patch("wbcore.contrib.workflow.models.step.Step.finish")
|
|
95
|
+
def test_finish_no_preserved_instance(self, mock_finish, process_step_factory, finish_step_factory):
|
|
96
|
+
step = finish_step_factory(write_preserved_instance=True, workflow__preserve_instance=True)
|
|
97
|
+
process_step = process_step_factory(
|
|
98
|
+
step=step, process__finished=None, state=ProcessStep.StepState.FINISHED, process__preserved_instance=None
|
|
99
|
+
)
|
|
100
|
+
old_name = process_step.process.instance.first_name
|
|
101
|
+
step.finish(process_step)
|
|
102
|
+
assert mock_finish.call_args.args == (process_step,)
|
|
103
|
+
assert process_step.process.finished is not None
|
|
104
|
+
assert process_step.process.instance.first_name == old_name
|
|
105
|
+
assert process_step.process.state == Process.ProcessState.FINISHED
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from wbcore.contrib.workflow.models import ProcessStep
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@pytest.mark.django_db
|
|
8
|
+
class TestJoinStep:
|
|
9
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_canceled")
|
|
10
|
+
def test_cancel_if_leading_to_self_transition_found(
|
|
11
|
+
self, mock_canceled, random_child_step_factory, join_step_factory, process_step_factory, transition_factory
|
|
12
|
+
):
|
|
13
|
+
self_step = join_step_factory()
|
|
14
|
+
step = random_child_step_factory()
|
|
15
|
+
process_step = process_step_factory(step=step)
|
|
16
|
+
transition1 = transition_factory(from_step=step)
|
|
17
|
+
transition_factory(from_step=step)
|
|
18
|
+
transition_factory(from_step=transition1.to_step, to_step=self_step)
|
|
19
|
+
transition_factory()
|
|
20
|
+
self_step.cancel_if_leading_to_self(step, process_step)
|
|
21
|
+
assert mock_canceled.call_args.args == (process_step,)
|
|
22
|
+
|
|
23
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_canceled")
|
|
24
|
+
def test_cancel_if_leading_to_self_no_transition_found(
|
|
25
|
+
self,
|
|
26
|
+
mock_canceled,
|
|
27
|
+
random_child_step_factory,
|
|
28
|
+
join_step_factory,
|
|
29
|
+
process_step_factory,
|
|
30
|
+
transition_factory,
|
|
31
|
+
):
|
|
32
|
+
self_step = join_step_factory()
|
|
33
|
+
step = random_child_step_factory()
|
|
34
|
+
process_step = process_step_factory(step=step)
|
|
35
|
+
transition1 = transition_factory(from_step=step)
|
|
36
|
+
transition_factory(from_step=step)
|
|
37
|
+
transition_factory(from_step=transition1.to_step)
|
|
38
|
+
transition_factory()
|
|
39
|
+
self_step.cancel_if_leading_to_self(step, process_step)
|
|
40
|
+
assert not mock_canceled.called
|
|
41
|
+
|
|
42
|
+
@patch("wbcore.contrib.workflow.models.step.JoinStep.cancel_if_leading_to_self")
|
|
43
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
44
|
+
def test_run_wait_for_all_transition_without_process_step(
|
|
45
|
+
self, mock_execute, mock_cancel, process_step_factory, join_step_factory, transition_factory
|
|
46
|
+
):
|
|
47
|
+
step = join_step_factory(wait_for_all=True)
|
|
48
|
+
transition_factory(to_step=step)
|
|
49
|
+
process_step = process_step_factory(step=step, state=ProcessStep.StepState.ACTIVE)
|
|
50
|
+
step.run(process_step)
|
|
51
|
+
assert process_step.state == ProcessStep.StepState.WAITING
|
|
52
|
+
assert not mock_execute.called
|
|
53
|
+
assert not mock_cancel.called
|
|
54
|
+
|
|
55
|
+
@patch("wbcore.contrib.workflow.models.step.JoinStep.cancel_if_leading_to_self")
|
|
56
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
57
|
+
def test_run_wait_for_all_transition_with_process_step(
|
|
58
|
+
self, mock_execute, mock_cancel, process_step_factory, join_step_factory, transition_factory
|
|
59
|
+
):
|
|
60
|
+
step = join_step_factory(wait_for_all=True)
|
|
61
|
+
transition = transition_factory(to_step=step)
|
|
62
|
+
process_step = process_step_factory(step=step, state=ProcessStep.StepState.ACTIVE)
|
|
63
|
+
process_step_factory(
|
|
64
|
+
step=transition.from_step, process=process_step.process, state=ProcessStep.StepState.ACTIVE
|
|
65
|
+
)
|
|
66
|
+
step.run(process_step)
|
|
67
|
+
assert process_step.state == ProcessStep.StepState.WAITING
|
|
68
|
+
assert not mock_execute.called
|
|
69
|
+
assert not mock_cancel.called
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize("state", [ProcessStep.StepState.FINISHED, ProcessStep.StepState.CANCELED])
|
|
72
|
+
@patch("wbcore.contrib.workflow.models.step.JoinStep.cancel_if_leading_to_self")
|
|
73
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
74
|
+
def test_run_wait_for_all_transition_with_finished_canceled_process_step(
|
|
75
|
+
self, mock_execute, mock_cancel, process_step_factory, join_step_factory, transition_factory, state
|
|
76
|
+
):
|
|
77
|
+
step = join_step_factory(wait_for_all=True)
|
|
78
|
+
transition = transition_factory(to_step=step)
|
|
79
|
+
transition_factory(from_step=step)
|
|
80
|
+
process_step = process_step_factory(step=step, state=ProcessStep.StepState.ACTIVE)
|
|
81
|
+
process_step_factory(step=transition.from_step, process=process_step.process, state=state)
|
|
82
|
+
step.run(process_step)
|
|
83
|
+
assert process_step.state == ProcessStep.StepState.WAITING
|
|
84
|
+
assert mock_execute.call_args.args == (process_step,)
|
|
85
|
+
assert not mock_cancel.called
|
|
86
|
+
|
|
87
|
+
@patch("wbcore.contrib.workflow.models.step.JoinStep.cancel_if_leading_to_self")
|
|
88
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
89
|
+
def test_run_wait_for_all_no_transition(
|
|
90
|
+
self, mock_execute, mock_cancel, process_step_factory, join_step_factory, transition_factory
|
|
91
|
+
):
|
|
92
|
+
step = join_step_factory(wait_for_all=True)
|
|
93
|
+
transition_factory(from_step=step)
|
|
94
|
+
process_step = process_step_factory(step=step, state=ProcessStep.StepState.ACTIVE)
|
|
95
|
+
step.run(process_step)
|
|
96
|
+
assert process_step.state == ProcessStep.StepState.WAITING
|
|
97
|
+
assert mock_execute.call_args.args == (process_step,)
|
|
98
|
+
assert not mock_cancel.called
|
|
99
|
+
|
|
100
|
+
@patch("wbcore.contrib.workflow.models.step.JoinStep.cancel_if_leading_to_self")
|
|
101
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
102
|
+
def test_run_do_not_wait(
|
|
103
|
+
self,
|
|
104
|
+
mock_execute,
|
|
105
|
+
mock_cancel,
|
|
106
|
+
process_step_factory,
|
|
107
|
+
join_step_factory,
|
|
108
|
+
):
|
|
109
|
+
step = join_step_factory(wait_for_all=False)
|
|
110
|
+
process_step = process_step_factory(step=step, state=ProcessStep.StepState.ACTIVE)
|
|
111
|
+
unfinished_process_step1 = process_step_factory(
|
|
112
|
+
process=process_step.process, state=ProcessStep.StepState.ACTIVE
|
|
113
|
+
)
|
|
114
|
+
unfinished_process_step2 = process_step_factory(
|
|
115
|
+
process=process_step.process, state=ProcessStep.StepState.WAITING
|
|
116
|
+
)
|
|
117
|
+
process_step_factory(state=ProcessStep.StepState.ACTIVE)
|
|
118
|
+
process_step_factory(process=process_step.process, state=ProcessStep.StepState.FINISHED)
|
|
119
|
+
process_step_factory(process=process_step.process, state=ProcessStep.StepState.CANCELED)
|
|
120
|
+
process_step_factory(process=process_step.process, state=ProcessStep.StepState.FAILED)
|
|
121
|
+
step.run(process_step)
|
|
122
|
+
assert process_step.state == ProcessStep.StepState.WAITING
|
|
123
|
+
assert mock_execute.call_args.args == (process_step,)
|
|
124
|
+
assert set(tuple(map(lambda y: str(y.pk), x.args)) for x in mock_cancel.call_args_list) == {
|
|
125
|
+
(str(unfinished_process_step1.step.pk), unfinished_process_step1.pk),
|
|
126
|
+
(str(unfinished_process_step2.step.pk), unfinished_process_step2.pk),
|
|
127
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.django_db
|
|
7
|
+
class TestScriptStep:
|
|
8
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
9
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
10
|
+
def test_run(self, mock_execute, mock_failed, script_step_factory, process_step_factory):
|
|
11
|
+
step = script_step_factory()
|
|
12
|
+
process_step = process_step_factory(step=step)
|
|
13
|
+
step.run(process_step)
|
|
14
|
+
assert not mock_failed.called
|
|
15
|
+
assert mock_execute.call_args.args == (process_step,)
|
|
16
|
+
|
|
17
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
18
|
+
@patch("wbcore.contrib.workflow.models.step.Step.execute_single_next_step")
|
|
19
|
+
def test_run_failed(self, mock_execute, mock_failed, script_step_factory, process_step_factory):
|
|
20
|
+
step = script_step_factory(script="Test")
|
|
21
|
+
process_step = process_step_factory(step=step)
|
|
22
|
+
step.run(process_step)
|
|
23
|
+
assert mock_failed.call_args.args[0] == process_step
|
|
24
|
+
assert not mock_execute.called
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.django_db
|
|
7
|
+
class TestSplitStep:
|
|
8
|
+
@patch("wbcore.contrib.workflow.models.step.activate_step.delay")
|
|
9
|
+
@patch("wbcore.contrib.workflow.models.step.Step.get_all_valid_outgoing_transitions")
|
|
10
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_finished")
|
|
11
|
+
def test_run(
|
|
12
|
+
self,
|
|
13
|
+
mock_finished,
|
|
14
|
+
mock_transitions,
|
|
15
|
+
mock_activate,
|
|
16
|
+
process_step_factory,
|
|
17
|
+
transition_factory,
|
|
18
|
+
split_step_factory,
|
|
19
|
+
):
|
|
20
|
+
transition1 = transition_factory()
|
|
21
|
+
transition2 = transition_factory()
|
|
22
|
+
transition_factory()
|
|
23
|
+
mock_transitions.return_value = [transition1, transition2]
|
|
24
|
+
step = split_step_factory()
|
|
25
|
+
process_step = process_step_factory(step=step)
|
|
26
|
+
step.run(process_step)
|
|
27
|
+
assert mock_finished.call_args.args == (process_step,)
|
|
28
|
+
assert mock_activate.call_args_list == [
|
|
29
|
+
((transition1.to_step.pk, process_step.process.pk),),
|
|
30
|
+
((transition2.to_step.pk, process_step.process.pk),),
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
@patch("wbcore.contrib.workflow.models.step.activate_step.delay")
|
|
34
|
+
@patch("wbcore.contrib.workflow.models.step.Step.get_all_valid_outgoing_transitions")
|
|
35
|
+
@patch("wbcore.contrib.workflow.models.step.Step.set_failed")
|
|
36
|
+
def test_run_failed(
|
|
37
|
+
self,
|
|
38
|
+
mock_failed,
|
|
39
|
+
mock_transitions,
|
|
40
|
+
mock_activate,
|
|
41
|
+
process_step_factory,
|
|
42
|
+
split_step_factory,
|
|
43
|
+
):
|
|
44
|
+
mock_transitions.return_value = []
|
|
45
|
+
step = split_step_factory()
|
|
46
|
+
process_step = process_step_factory(step=step)
|
|
47
|
+
step.run(process_step)
|
|
48
|
+
assert mock_failed.call_args.args[0] == process_step
|
|
49
|
+
assert not mock_activate.called
|