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_workflow(self):
"""
"""
workflows.utils.set_workflow(self.user, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
def test_remove_workflow_1(self):
"""Removes workflow from model
"""
ctype = ContentType.objects.get_for_model(self.user)
result = workflows.utils.get_workflow(ctype)
self.assertEqual(result, None)
workflows.utils.set_workflow_for_model(ctype, self.w)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
workflows.utils.remove_workflow(ctype)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, None)
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, None)
def test_remove_workflow_from_model(self):
"""
"""
ctype = ContentType.objects.get_for_model(self.user)
result = workflows.utils.get_workflow(ctype)
self.assertEqual(result, None)
workflows.utils.set_workflow_for_model(ctype, self.w)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
workflows.utils.remove_workflow_from_model(ctype)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, None)
result = workflows.utils.get_workflow_for_object(self.user)
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)
def test_remove_workflow_from_model(self):
"""
"""
ctype = ContentType.objects.get_for_model(self.user)
result = workflows.utils.get_workflow(ctype)
self.assertEqual(result, None)
workflows.utils.set_workflow_for_model(ctype, self.w)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
workflows.utils.remove_workflow_from_model(ctype)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, None)
result = workflows.utils.get_workflow_for_object(self.user)
self.assertEqual(result, None)
def test_remove_workflow_1(self):
"""Removes workflow from model
"""
ctype = ContentType.objects.get_for_model(self.user)
result = workflows.utils.get_workflow(ctype)
self.assertEqual(result, None)
workflows.utils.set_workflow_for_model(ctype, self.w)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, self.w)
result = workflows.utils.get_workflow(self.user)
self.assertEqual(result, self.w)
workflows.utils.remove_workflow(ctype)
result = workflows.utils.get_workflow_for_model(ctype)
self.assertEqual(result, None)
result = workflows.utils.get_workflow_for_object(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 get_workflow(self):
"""Returns the current workflow of the object.
"""
return workflows.utils.get_workflow(self)
def get_objects(self):
"""Returns all objects which have this workflow assigned. Globally
(via the object's content type) or locally (via the object itself).
"""
import workflows.utils
objs = []
# Get all objects whose content type has this workflow
for wmr in WorkflowModelRelation.objects.filter(workflow=self):
ctype = wmr.content_type
# We have also to check whether the global workflow is not
# overwritten.
for obj in ctype.model_class().objects.all():
if workflows.utils.get_workflow(obj) == self:
objs.append(obj)
# Get all objects whose local workflow this workflow
for wor in WorkflowObjectRelation.objects.filter(workflow=self):
if wor.content not in objs:
objs.append(wor.content)
return objs