Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, None)
wp = Workflow.objects.create(name="Portal")
# Set for model
workflows.utils.set_workflow_for_model(ctype, wp)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, wp)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, wp)
# Set for object
workflows.utils.set_workflow_for_object(self.user, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
# The model still have wp
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, wp)
def test_remove_workflow_2(self):
"""Removes workflow from object
"""
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, None)
workflows.utils.set_workflow_for_object(self.user, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
result = workflows.utils.remove_workflow(self.user)
self.assertEqual(result, None)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, None)
wp = Workflow.objects.create(name="Portal")
# Set for model
workflows.utils.set_workflow_for_model(ctype, "Portal")
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, wp)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, wp)
# Set for object
workflows.utils.set_workflow_for_object(self.user, "Standard")
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
# The model still have wp
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, wp)
# Workflow which does not exist
result = workflows.utils.set_workflow_for_model(ctype, "Wrong")
self.assertEqual(result, False)
result = workflows.utils.set_workflow_for_object(self.user, "Wrong")
self.assertEqual(result, False)
def test_get_workflow_for_object(self):
"""
"""
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, None)
# Set workflow for a user
workflows.utils.set_workflow_for_object(self.user, self.w)
# Get workflow for the user
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, self.w)
# Set workflow for a FlatPage
page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
workflows.utils.set_workflow_for_object(page_1, self.w)
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow_for_object(page_1)
self.assertEqual(result, self.w)
def test_get_workflow_for_object(self):
"""
"""
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, None)
# Set workflow for a user
workflows.utils.set_workflow_for_object(self.user, self.w)
# Get workflow for the user
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, self.w)
# Set workflow for a FlatPage
page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
workflows.utils.set_workflow_for_object(page_1, self.w)
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow_for_object(page_1)
self.assertEqual(result, self.w)
self.assertEqual(result, wp)
# Set for object
workflows.utils.set_workflow_for_object(self.user, "Standard")
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
# The model still have wp
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, wp)
# Workflow which does not exist
result = workflows.utils.set_workflow_for_model(ctype, "Wrong")
self.assertEqual(result, False)
result = workflows.utils.set_workflow_for_object(self.user, "Wrong")
self.assertEqual(result, False)
"""Sets the passed workflow to the object. This will set the local
workflow for the object.
If the object has already the given workflow nothing happens.
Otherwise the object gets the passed workflow and the state is set to
the workflow's initial state.
**Parameters:**
workflow
The workflow which should be set to the object. Can be a Workflow
instance or a string with the workflow name.
obj
The object which gets the passed workflow.
"""
return workflows.utils.set_workflow_for_object(self, workflow)
def set_workflow(self, workflow):
""" Initiate a workflow for instance. """
if self.state is None:
if not workflow:
ctype = ContentType.objects.get_for_model(self)
workflow = get_workflow_for_model(ctype)
set_workflow_for_object(self, workflow)