7
7
from django .contrib .auth import get_user_model
8
8
from django .test import TestCase
9
9
from django .test .client import RequestFactory
10
+ from django_fsm_log .models import StateLog
10
11
11
12
from django_fsm import ConcurrentTransition
12
13
from django_fsm import FSMField
@@ -105,6 +106,7 @@ def setUpTestData(cls):
105
106
cls .user = get_user_model ().objects .create_user (username = "jacob" , password = "password" , is_staff = True ) # noqa: S106
106
107
107
108
def test_unknown_transition (self , mock_message_user ):
109
+ assert StateLog .objects .count () == 0
108
110
request = RequestFactory ().post (
109
111
path = "/" ,
110
112
data = {"_fsm_transition_to" : "unknown_transition" },
@@ -126,8 +128,10 @@ def test_unknown_transition(self, mock_message_user):
126
128
127
129
updated_blog_post = AdminBlogPost .objects .get (pk = blog_post .pk )
128
130
assert updated_blog_post .state == AdminBlogPostState .CREATED
131
+ assert StateLog .objects .count () == 0
129
132
130
133
def test_transition_applied (self , mock_message_user ):
134
+ assert StateLog .objects .count () == 0
131
135
request = RequestFactory ().post (
132
136
path = "/" ,
133
137
data = {"_fsm_transition_to" : "moderate" },
@@ -150,8 +154,11 @@ def test_transition_applied(self, mock_message_user):
150
154
151
155
updated_blog_post = AdminBlogPost .objects .get (pk = blog_post .pk )
152
156
assert updated_blog_post .state == AdminBlogPostState .REVIEWED
157
+ assert StateLog .objects .count () == 1
158
+ assert StateLog .objects .get ().by == self .user
153
159
154
160
def test_transition_not_allowed_exception (self , mock_message_user ):
161
+ assert StateLog .objects .count () == 0
155
162
request = RequestFactory ().post (
156
163
path = "/" ,
157
164
data = {"_fsm_transition_to" : "publish" },
@@ -174,8 +181,10 @@ def test_transition_not_allowed_exception(self, mock_message_user):
174
181
175
182
updated_blog_post = AdminBlogPost .objects .get (pk = blog_post .pk )
176
183
assert updated_blog_post .state == AdminBlogPostState .CREATED
184
+ assert StateLog .objects .count () == 0
177
185
178
186
def test_concurrent_transition_exception (self , mock_message_user ):
187
+ assert StateLog .objects .count () == 0
179
188
request = RequestFactory ().post (
180
189
path = "/" ,
181
190
data = {"_fsm_transition_to" : "moderate" },
@@ -202,3 +211,4 @@ def test_concurrent_transition_exception(self, mock_message_user):
202
211
203
212
updated_blog_post = AdminBlogPost .objects .get (pk = blog_post .pk )
204
213
assert updated_blog_post .state == AdminBlogPostState .CREATED
214
+ assert StateLog .objects .count () == 0
0 commit comments