Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Add all permissions which are managed by the workflow
wpr = WorkflowPermissionRelation.objects.create(workflow=self.w, permission=self.view)
wpr = WorkflowPermissionRelation.objects.create(workflow=self.w, permission=self.edit)
# Add permissions for single states
spr = StatePermissionRelation.objects.create(state=self.public, permission=self.view, role=self.owner)
spr = StatePermissionRelation.objects.create(state=self.private, permission=self.view, role=self.owner)
spr = StatePermissionRelation.objects.create(state=self.private, permission=self.edit, role=self.owner)
# Add inheritance block for single states
sib = StateInheritanceBlock.objects.create(state=self.private, permission=self.view)
sib = StateInheritanceBlock.objects.create(state=self.private, permission=self.edit)
sib = StateInheritanceBlock.objects.create(state=self.public, permission=self.edit)
workflows.utils.set_workflow(self.page_1, self.w)
def test_get_objects_for_workflow_3(self):
"""Workflow is added to content type and object.
"""
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [])
workflows.utils.set_workflow(self.user, self.w)
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [self.user])
ctype = ContentType.objects.get_for_model(self.user)
workflows.utils.set_workflow(ctype, self.w)
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [self.user])
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 setUp(self):
"""
"""
create_workflow(self)
self.user = User.objects.create(username='test_user',
first_name='Test', last_name='User')
self.flat_page = FlatPage.objects.create(url='/page-1', title='Page 1',
initializer=self.user)
set_workflow(self.flat_page, self.w)
def test_get_objects_for_workflow_3(self):
"""Workflow is added to content type and object.
"""
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [])
workflows.utils.set_workflow(self.user, self.w)
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [self.user])
ctype = ContentType.objects.get_for_model(self.user)
workflows.utils.set_workflow(ctype, self.w)
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [self.user])
def test_get_objects_for_workflow_1(self):
"""Workflow is added to object.
"""
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [])
workflows.utils.set_workflow(self.user, self.w)
result = workflows.utils.get_objects_for_workflow(self.w)
self.assertEqual(result, [self.user])
def test_by_state(self):
set_workflow(self.first_page, self.w)
set_workflow(self.second_page, self.w)
set_workflow(self.third_page, self.w)
result = FlatPage.objects.by_state('Private')
self.assertListEqual(list(result), [self.first_page, self.second_page,
self.third_page])
self.assertIsInstance(result, QuerySet)
self.first_page.change_state(self.make_public, self.user)
result = FlatPage.objects.by_state('Public')
self.assertListEqual(list(result), [self.first_page])
def test_by_state(self):
set_workflow(self.first_page, self.w)
set_workflow(self.second_page, self.w)
set_workflow(self.third_page, self.w)
result = FlatPage.objects.by_state('Private')
self.assertListEqual(list(result), [self.first_page, self.second_page,
self.third_page])
self.assertIsInstance(result, QuerySet)
self.first_page.change_state(self.make_public, self.user)
result = FlatPage.objects.by_state('Public')
self.assertListEqual(list(result), [self.first_page])
def test_get_editable_instances(self):
"""
"""
second_page = FlatPage.objects.create(url='/page-2', title='Page 2',
initializer=self.test_user)
third_page = FlatPage.objects.create(url='/page-3', title='Page 3',
initializer=self.test_user)
fourth_page = FlatPage.objects.create(url='/page-4', title='Page 4',
initializer=self.test_user)
fifth_page = FlatPage.objects.create(url='/page-5', title='Page 5',
initializer=self.test_user)
set_workflow(self.flat_page, self.w)
set_workflow(second_page, self.w)
set_workflow(third_page, self.w)
result = FlatPage.pending.editable_by_roles([self.publisher])
self.assertListEqual(list(result), [self.flat_page, second_page,
third_page])
result = FlatPage.pending.editable_by_roles([self.anonymous])
self.assertListEqual(list(result), [])
self.flat_page.change_state(self.make_public, self.test_user)
second_page.change_state(self.reject, self.test_user)
result = FlatPage.pending.editable_by_roles([self.publisher])
self.assertListEqual(list(result), [third_page])
def test_ended_manager(self):
set_workflow(self.first_page, self.w)
set_workflow(self.second_page, self.w)
set_workflow(self.third_page, self.w)
result = FlatPage.ended.all()
self.assertListEqual(list(result), [])
self.first_page.change_state(self.make_public, self.user)
self.second_page.change_state(self.reject, self.user)
result = FlatPage.ended.all()
self.assertListEqual(list(result), [self.second_page])
result = result.by_state('Rejected')
self.assertListEqual(list(result), [self.second_page])