Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_state(self):
"""
"""
result = workflows.utils.get_state(self.user)
self.assertEqual(result, None)
workflows.utils.set_workflow(self.user, self.w)
result = workflows.utils.get_state(self.user)
self.assertEqual(result, self.w.initial_state)
def test_do_transition(self):
"""
"""
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
# by transition
workflows.utils.do_transition(self.page_1, self.make_public, self.user)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.public.name)
# by name
workflows.utils.do_transition(self.page_1, "Make private", self.user)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
# name which does not exist
result = workflows.utils.do_transition(self.page_1, "Make pending", self.user)
self.assertEqual(result, False)
wrong = Transition.objects.create(name="Wrong", workflow=self.w, destination = self.public)
# name which does not exist
result = workflows.utils.do_transition(self.page_1, wrong, self.user)
def test_set_initial_state(self):
"""
"""
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
workflows.utils.do_transition(self.page_1, self.make_public, self.user)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.public.name)
workflows.utils.set_initial_state(self.page_1)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
def test_set_initial_state(self):
"""
"""
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
workflows.utils.do_transition(self.page_1, self.make_public, self.user)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.public.name)
workflows.utils.set_initial_state(self.page_1)
state = workflows.utils.get_state(self.page_1)
self.assertEqual(state.name, self.private.name)
def transitions(context, obj):
"""
"""
request = context.get("request")
return {
"transitions" : workflows.utils.get_allowed_transitions(obj, request.user),
"state" : workflows.utils.get_state(obj),
}
def get_state(self):
"""Returns the current workflow state of the object.
"""
return workflows.utils.get_state(self)
def transitions(context, obj):
"""
"""
request = context.get("request")
return {
"transitions" : workflows.utils.get_allowed_transitions(obj, request.user),
"state" : workflows.utils.get_state(obj),
}
def state(self):
""" Get the state in workflow for the instance of the workflow managed
model
:return: the state of the managed instance
:rtype: `workflows.models.State `_
"""
return get_state(self)