Skip to content

Commit 4ed389e

Browse files
committed
Add tests and improve integration
1 parent f5b6f9e commit 4ed389e

File tree

7 files changed

+36
-21
lines changed

7 files changed

+36
-21
lines changed

joeflow/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .conf import settings
2020
from .typing import HUMAN, MACHINE
2121
from .utils import NoDashDiGraph
22-
from .views import StartWorkflowMixin
22+
from .views import StartViewMixin
2323

2424
logger = logging.getLogger(__name__)
2525

@@ -140,7 +140,7 @@ def urls(cls):
140140
urls = []
141141
for name, node in cls.get_nodes():
142142
if isinstance(node, View):
143-
if isinstance(node, (BaseCreateView, StartWorkflowMixin)):
143+
if isinstance(node, (BaseCreateView, StartViewMixin)):
144144
route = f"{name}/"
145145
else:
146146
route = f"{name}/<int:pk>/"

joeflow/tasks/human.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from django.views import generic
44

5-
from joeflow.views import StartWorkflowMixin, TaskViewMixin
5+
from joeflow.views import StartViewMixin, TaskViewMixin
66

77
__all__ = (
88
"StartView",
99
"UpdateView",
1010
)
1111

1212

13-
class StartView(TaskViewMixin, StartWorkflowMixin, generic.CreateView):
13+
class StartView(StartViewMixin, generic.CreateView):
1414
"""
1515
Start a new workflow by a human with a view.
1616

joeflow/views.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ def get_template_names(self):
2929
return names
3030

3131

32-
class StartWorkflowMixin:
33-
"""
34-
View-mixin to create a start workflow.
35-
36-
Example:
37-
class MyStartWorkflowView(StartWorkflowMixin, TaskViewMixin, View):
38-
def post(self, request, *args, **kwargs):
39-
try:
40-
data = json.loads(request.body)
41-
workflow_id = self.start_workflow(data)
42-
except Exception as e:
43-
return HttpResponseBadRequest("Failed to start workflow")
44-
45-
return JsonResponse({'message': 'Workflow started successfully.', 'id': workflow_id}, status=201)
46-
"""
47-
48-
4932
class TaskViewMixin(WorkflowTemplateNameViewMixin, RevisionMixin):
5033
name = None
5134
path = ""
@@ -114,6 +97,25 @@ def create_task(self, workflow, prev_task):
11497
)
11598

11699

100+
class StartViewMixin(TaskViewMixin):
101+
"""
102+
View-mixin to create a start workflow.
103+
104+
Example:
105+
class MyStartWorkflowView(StartViewMixin, View):
106+
def post(self, request, *args, **kwargs):
107+
try:
108+
data = json.loads(request.body)
109+
workflow_id = self.start_workflow(data)
110+
except Exception as e:
111+
return HttpResponseBadRequest("Failed to start workflow")
112+
113+
return JsonResponse({'message': 'Workflow started successfully.', 'id': workflow_id}, status=201)
114+
"""
115+
116+
model = None
117+
118+
117119
class WorkflowDetailView(WorkflowTemplateNameViewMixin, generic.DetailView):
118120
pass
119121

tests/fixtures/simpleworkflow.dot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ digraph {
55
"save the princess" [color=black fontcolor=black style="filled, rounded"]
66
"start method" [color=black fontcolor=black style=filled]
77
"start view" [color=black fontcolor=black style="filled, rounded"]
8+
"custom start view" [color=black fontcolor=black style="filled, rounded"]
89
"save the princess" -> end [color=black]
910
"start method" -> "save the princess" [color=black]
1011
"start view" -> "save the princess" [color=black]
12+
"custom start view" -> "save the princess" [color=black]
1113
}

tests/fixtures/simpleworkflow_instance.dot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ digraph {
55
"save the princess" [color=black fontcolor=black href="/simple/save_the_princess/2/" peripheries=1 style="filled, rounded, bold"]
66
"start method" [color=black fontcolor=black peripheries=1 style=filled]
77
"start view" [color="#888888" fontcolor="#888888" style="filled, rounded"]
8+
"custom start view" [color="#888888" fontcolor="#888888" style="filled, rounded"]
89
"save the princess" -> end [color="#888888"]
910
"start method" -> "save the princess" [color=black]
1011
"start view" -> "save the princess" [color="#888888"]
12+
"custom start view" -> "save the princess" [color="#888888"]
1113
}

tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def test_urls(self):
207207
assert namespace == "simpleworkflow"
208208
names = {pattern.name for pattern in patterns}
209209
assert names == {
210+
"custom_start_view",
210211
"save_the_princess",
211212
"start_view",
212213
"override",

tests/testapp/workflows.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from datetime import timedelta
22

33
from django.core.mail import send_mail
4+
from django.views import generic
45

56
from joeflow import tasks
7+
from joeflow.views import StartViewMixin
68

79
from . import models
810
from .views import UpdateWithPrevUserView
@@ -40,8 +42,13 @@ class Meta:
4042
proxy = True
4143

4244

45+
class CustomStartViewTaskView(StartViewMixin, generic.View):
46+
pass
47+
48+
4349
class SimpleWorkflow(models.SimpleWorkflowState):
4450
start_view = tasks.StartView(fields="__all__", path="custom/postfix/")
51+
custom_start_view = CustomStartViewTaskView()
4552
start_method = tasks.Start()
4653
save_the_princess = tasks.UpdateView(fields="__all__")
4754

@@ -50,6 +57,7 @@ def end(self):
5057

5158
edges = (
5259
(start_view, save_the_princess),
60+
(custom_start_view, save_the_princess),
5361
(start_method, save_the_princess),
5462
(save_the_princess, end),
5563
)

0 commit comments

Comments
 (0)