-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathtests.py
More file actions
66 lines (46 loc) · 1.63 KB
/
tests.py
File metadata and controls
66 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pytest
from statemachine.exceptions import TransitionNotAllowed
from workflow.models import WorkflowSteps
from workflow.statemachines import WorfklowStateMachine
pytestmark = [
pytest.mark.django_db,
]
@pytest.fixture()
def Workflow():
from workflow.models import Workflow
return Workflow
@pytest.fixture()
def User():
from django.contrib.auth import get_user_model
return get_user_model()
@pytest.fixture()
def one(Workflow):
return Workflow.objects.create()
class TestWorkflow:
def test_one(self, one):
with pytest.raises(TransitionNotAllowed):
one.wf.send("publish")
def test_two(self, one):
# Managing this instance works if I call it like this instead.
# So this test works
wf = WorfklowStateMachine(one)
with pytest.raises(TransitionNotAllowed):
wf.send("publish")
def test_async_with_db_operation(self, one, User, Workflow):
"""Regression test for https://github.com/fgmacedo/python-statemachine/issues/446"""
user = User.objects.create_user("user")
one.user = user
one.save()
wf = WorfklowStateMachine(one)
wf.send("notify_user")
# And clear model cache, casing user to be loaded later on
one = Workflow.objects.get(pk=one.pk)
wf = WorfklowStateMachine(one)
wf.send("notify_user")
def test_should_publish(self, one):
one.is_active = True
one.publish()
one.save()
assert one.state == "published"
assert one.wf.current_state_value == "published"
assert one.wf.current_state_value == WorkflowSteps.PUBLISHED