Work in progress: re-building loops package as a 'concept management framework'
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@807 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
b7a0b9d836
commit
a36b761129
7 changed files with 6 additions and 464 deletions
|
@ -1,75 +0,0 @@
|
||||||
<!-- $Id$ -->
|
|
||||||
|
|
||||||
<configure
|
|
||||||
xmlns:zope="http://namespaces.zope.org/zope"
|
|
||||||
xmlns="http://namespaces.zope.org/browser"
|
|
||||||
i18n_domain="zope"
|
|
||||||
>
|
|
||||||
|
|
||||||
<addform
|
|
||||||
label="Add Task"
|
|
||||||
name="AddTask.html"
|
|
||||||
schema="loops.interfaces.ITask"
|
|
||||||
content_factory="loops.task.Task"
|
|
||||||
fields="title"
|
|
||||||
permission="zope.ManageContent"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<addMenuItem
|
|
||||||
class="loops.task.Task"
|
|
||||||
title="Task"
|
|
||||||
description="A Task is a piece of work or something else a resource may be allocated to"
|
|
||||||
permission="zope.ManageContent"
|
|
||||||
view="AddTask.html"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<editform
|
|
||||||
label="Edit Task"
|
|
||||||
name="edit.html"
|
|
||||||
schema="loops.interfaces.ITask"
|
|
||||||
for="loops.interfaces.ITask"
|
|
||||||
permission="zope.ManageContent"
|
|
||||||
menu="zmi_views" title="Edit"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<containerViews
|
|
||||||
for="loops.interfaces.ITask"
|
|
||||||
index="zope.View"
|
|
||||||
contents="zope.View"
|
|
||||||
add="zope.ManageContent"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<defaultView
|
|
||||||
for="loops.interfaces.ITask"
|
|
||||||
name="details.html"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<page
|
|
||||||
name="details.html"
|
|
||||||
for="loops.interfaces.ITask"
|
|
||||||
class=".task.Details"
|
|
||||||
template="task_details.pt"
|
|
||||||
permission="zope.View"
|
|
||||||
menu="zmi_views" title="Details"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<pages
|
|
||||||
for="loops.interfaces.ITask"
|
|
||||||
class=".task.SubtaskAssignments"
|
|
||||||
permission="zope.ManageContent"
|
|
||||||
>
|
|
||||||
|
|
||||||
<page
|
|
||||||
name="subtasks.html"
|
|
||||||
template="subtasks_assign.pt"
|
|
||||||
menu="zmi_views" title="Subtasks"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<page
|
|
||||||
name="subtask_assign"
|
|
||||||
attribute="assignSubtask"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</pages>
|
|
||||||
|
|
||||||
</configure>
|
|
|
@ -12,7 +12,9 @@
|
||||||
<span class="label">Subtasks</span>:
|
<span class="label">Subtasks</span>:
|
||||||
<span class="field"
|
<span class="field"
|
||||||
tal:repeat="task context/getSubtasks">
|
tal:repeat="task context/getSubtasks">
|
||||||
<span tal:content="task/title">subtask</span>
|
<span tal:condition="python: task is None">**deleted**</span>
|
||||||
|
<span tal:condition="python: task is not None"
|
||||||
|
tal:content="task/title">subtask</span>
|
||||||
<span class="field" tal:condition="not:repeat/task/end"> - </span>
|
<span class="field" tal:condition="not:repeat/task/end"> - </span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
<span class="label">Subtasks</span>:
|
<span class="label">Subtasks</span>:
|
||||||
<span class="field"
|
<span class="field"
|
||||||
tal:repeat="task context/getSubtasks">
|
tal:repeat="task context/getSubtasks">
|
||||||
<span tal:content="task/title">subtask</span>
|
<span tal:condition="python: task is None">**deleted**</span>
|
||||||
|
<span tal:condition="python: task is not None"
|
||||||
|
tal:content="task/title">subtask</span>
|
||||||
<span class="field" tal:condition="not:repeat/task/end"> - </span>
|
<span class="field" tal:condition="not:repeat/task/end"> - </span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
75
resource.py
75
resource.py
|
@ -1,75 +0,0 @@
|
||||||
#
|
|
||||||
# Copyright (c) 2004 Helmut Merz helmutm@cy55.de
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program; if not, write to the Free Software
|
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
#
|
|
||||||
|
|
||||||
"""
|
|
||||||
Definition of the Resource class.
|
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
|
||||||
|
|
||||||
from zope.interface import implements
|
|
||||||
from zope.app.container.ordered import OrderedContainer
|
|
||||||
from zope.app import zapi
|
|
||||||
|
|
||||||
from interfaces import IResource
|
|
||||||
|
|
||||||
|
|
||||||
class Resource(OrderedContainer):
|
|
||||||
|
|
||||||
implements(IResource)
|
|
||||||
|
|
||||||
title = u''
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
OrderedContainer.__init__(self)
|
|
||||||
self._allocations = {}
|
|
||||||
|
|
||||||
|
|
||||||
def getTasksAllocatedTo(self, allocTypes=None, taskTypes=None):
|
|
||||||
from sets import Set
|
|
||||||
allocs = self._allocations
|
|
||||||
res = Set()
|
|
||||||
for at in allocs.keys():
|
|
||||||
if allocTypes is None or at in allocTypes:
|
|
||||||
res.union_update(allocs[at])
|
|
||||||
return tuple(res)
|
|
||||||
|
|
||||||
|
|
||||||
# Helper methods:
|
|
||||||
|
|
||||||
def _addAllocation(self, task, allocType):
|
|
||||||
#called by Task.allocateResource
|
|
||||||
tList = self._allocations.get(allocType, [])
|
|
||||||
tList.append(task)
|
|
||||||
self._allocations[allocType] = tList
|
|
||||||
|
|
||||||
def _removeAllocations(self, task, allocTypes):
|
|
||||||
#called by Task.deallocateResource
|
|
||||||
allocs = self._allocations
|
|
||||||
for at in allocTypes or allocs.keys():
|
|
||||||
if task in allocs[at]:
|
|
||||||
allocs[at].remove(task)
|
|
||||||
|
|
||||||
def _createResourceName(self, container=None):
|
|
||||||
prefix = 'rsc'
|
|
||||||
container = container or zapi.getParent(self)
|
|
||||||
last = max([ int(n[len(prefix):]) for n in container.keys() ] or [0])
|
|
||||||
return prefix + str(last+1)
|
|
||||||
|
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
# $Id$
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
#from zope.testing.doctestunit import DocTestSuite
|
|
||||||
from zope.interface.verify import verifyClass
|
|
||||||
#from zope.app.tests.setup import placelessSetUp
|
|
||||||
#from zope.app.container.tests.test_icontainer import TestSampleContainer
|
|
||||||
from zope.app.container.interfaces import IContained
|
|
||||||
from zope.app.folder import Folder
|
|
||||||
|
|
||||||
from loops.resource import Resource
|
|
||||||
from loops.task import Task
|
|
||||||
from loops.interfaces import IResource
|
|
||||||
|
|
||||||
#class Test(TestSampleContainer):
|
|
||||||
class Test(unittest.TestCase):
|
|
||||||
"Test methods of the Resource class."
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
#placelessSetUp()
|
|
||||||
self.f1 = Folder()
|
|
||||||
self.f1.__name__ = u'f1'
|
|
||||||
self.r1 = Resource()
|
|
||||||
self.f1['rsc1'] = self.r1
|
|
||||||
self.t1 = Task()
|
|
||||||
self.f1['tsk1'] = self.t1
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# the tests...
|
|
||||||
|
|
||||||
def testInterface(self):
|
|
||||||
self.assert_(IResource.providedBy(Resource()),
|
|
||||||
'Interface IResource is not implemented by class Resource.')
|
|
||||||
self.assert_(IContained.providedBy(Resource()),
|
|
||||||
'Interface IContained is not implemented by class Resource.')
|
|
||||||
verifyClass(IResource, Resource)
|
|
||||||
|
|
||||||
def testContained(self):
|
|
||||||
self.assertEqual(u'rsc1', self.r1.__name__)
|
|
||||||
self.assertEqual(u'f1', self.r1.__parent__.__name__)
|
|
||||||
|
|
||||||
def testTitle(self):
|
|
||||||
r = Resource()
|
|
||||||
self.assertEqual(u'', r.title)
|
|
||||||
r.title = u'First Resource'
|
|
||||||
self.assertEqual(u'First Resource', r.title)
|
|
||||||
|
|
||||||
def testAllocateToTask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
self.assertEqual((), r1.getTasksAllocatedTo())
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
self.assertEqual((t1,), r1.getTasksAllocatedTo())
|
|
||||||
|
|
||||||
def testDeallocateFromTask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
self.assertEqual((t1,), r1.getTasksAllocatedTo())
|
|
||||||
t1.deallocateResource(r1)
|
|
||||||
self.assertEqual((), r1.getTasksAllocatedTo())
|
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
|
||||||
return unittest.TestSuite((
|
|
||||||
# DocTestSuite('loops.tests.doctests'),
|
|
||||||
unittest.makeSuite(Test),
|
|
||||||
))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main(defaultTest='test_suite')
|
|
239
test_task.py
239
test_task.py
|
@ -1,239 +0,0 @@
|
||||||
# $Id$
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from zope.testing.doctestunit import DocTestSuite
|
|
||||||
from zope.interface.verify import verifyClass
|
|
||||||
#from zope.app.tests.setup import placelessSetUp
|
|
||||||
from zope.app.testing.setup import placefulSetUp
|
|
||||||
#from zope.app.container.tests.test_icontainer import TestSampleContainer
|
|
||||||
from zope.app.container.interfaces import IContained
|
|
||||||
from zope.app.folder import Folder
|
|
||||||
from zope.app import zapi
|
|
||||||
|
|
||||||
from loops.task import Task
|
|
||||||
from loops.interfaces import ITask
|
|
||||||
|
|
||||||
#class Test(TestSampleContainer):
|
|
||||||
class TestTask(unittest.TestCase):
|
|
||||||
"Test methods of the Task class."
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
# placelessSetUp()
|
|
||||||
placefulSetUp()
|
|
||||||
self.f1 = Folder()
|
|
||||||
self.f1.__name__ = u'f1'
|
|
||||||
self.t1 = Task()
|
|
||||||
self.f1['tsk1'] = self.t1
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# the tests...
|
|
||||||
|
|
||||||
def testQualifier(self):
|
|
||||||
t = Task()
|
|
||||||
self.assertEqual(u'', t.qualifier)
|
|
||||||
t.qualifier = u'troubleticket'
|
|
||||||
self.assertEqual(u'troubleticket', t.qualifier)
|
|
||||||
|
|
||||||
def testSubtasks(self):
|
|
||||||
t1 = Task()
|
|
||||||
self.assertEqual((), t1.getSubtasks())
|
|
||||||
t2 = Task()
|
|
||||||
self.assertEqual((), t2.getSubtasks())
|
|
||||||
self.assertEqual((), t2.getParentTasks())
|
|
||||||
t1.assignSubtask(t2)
|
|
||||||
self.assertEqual((t2,), t1.getSubtasks())
|
|
||||||
self.assertEqual((t1,), t2.getParentTasks())
|
|
||||||
|
|
||||||
def testCreateSubtask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
self.assertEqual((), t1.getSubtasks())
|
|
||||||
t2 = t1.createSubtask()
|
|
||||||
self.assertEqual((t1,), t2.getParentTasks())
|
|
||||||
self.assertEqual((t2,), t1.getSubtasks())
|
|
||||||
|
|
||||||
def testDeassignSubtask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
t2 = t1.createSubtask()
|
|
||||||
self.assertEqual((t1,), t2.getParentTasks())
|
|
||||||
t1.deassignSubtask(t2)
|
|
||||||
self.assertEqual((), t2.getParentTasks())
|
|
||||||
self.assertEqual((), t1.getSubtasks())
|
|
||||||
|
|
||||||
def testSubtasksOrdering(self):
|
|
||||||
t1 = self.t1
|
|
||||||
st1 = t1.createSubtask()
|
|
||||||
st2 = t1.createSubtask()
|
|
||||||
st2.priority = 2
|
|
||||||
self.assertEqual((st1, st2), t1.getSubtasks())
|
|
||||||
st1.priority = 3
|
|
||||||
self.assertEqual((st2, st1), t1.getSubtasks())
|
|
||||||
|
|
||||||
|
|
||||||
from loops.resource import Resource
|
|
||||||
|
|
||||||
class TestTaskResource(unittest.TestCase):
|
|
||||||
"Test methods of the Task class related to Resource allocations."
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
#placelessSetUp()
|
|
||||||
#placefulSetUp()
|
|
||||||
self.f1 = Folder()
|
|
||||||
self.f1.__name__ = u'f1'
|
|
||||||
self.t1 = Task()
|
|
||||||
self.r1 = Resource()
|
|
||||||
self.f1['tsk1'] = self.t1
|
|
||||||
self.f1['rsc1'] = self.r1
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# the tests...
|
|
||||||
|
|
||||||
def testAllocateResource(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
self.assertEqual((), t1.getAllocatedResources())
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
self.assertEqual((r1,), t1.getAllocatedResources())
|
|
||||||
|
|
||||||
def testDeallocateResource(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
self.assertEqual((r1,), t1.getAllocatedResources())
|
|
||||||
t1.deallocateResource(r1)
|
|
||||||
self.assertEqual((), t1.getAllocatedResources())
|
|
||||||
|
|
||||||
def testCreateAndAllocateResource(self):
|
|
||||||
t1 = self.t1
|
|
||||||
self.assertEqual((), t1.getAllocatedResources())
|
|
||||||
r1 = t1.createAndAllocateResource()
|
|
||||||
self.assertEqual((r1,), t1.getAllocatedResources())
|
|
||||||
|
|
||||||
|
|
||||||
from loops.constraint import ResourceConstraint
|
|
||||||
|
|
||||||
class TestTaskResourceConstraints(unittest.TestCase):
|
|
||||||
"Test methods of the Task class related to checking for allowed resources."
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.f1 = Folder()
|
|
||||||
self.f1.__name__ = u'f1'
|
|
||||||
self.t1 = Task()
|
|
||||||
self.r1 = Resource()
|
|
||||||
self.f1['tsk1'] = self.t1
|
|
||||||
self.r1['rsc1'] = self.r1
|
|
||||||
self.rc1 = ResourceConstraint()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# the tests...
|
|
||||||
|
|
||||||
def testRequireExplicit(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
rc1 = self.rc1
|
|
||||||
|
|
||||||
self.assertEqual(True, t1.isResourceAllowed(r1)) # no check
|
|
||||||
self.assertEqual((), t1.getCandidateResources()) # no candidates
|
|
||||||
self.assertEqual(None, t1.getAllowedResources([r1]))# can't say without constraint
|
|
||||||
|
|
||||||
self.t1.resourceConstraints.append(self.rc1) # empty constraint
|
|
||||||
self.assertEqual(False, t1.isResourceAllowed(r1)) # does not allow
|
|
||||||
self.assertEqual((), t1.getCandidateResources()) # anything
|
|
||||||
self.assertEqual((), t1.getAllowedResources([r1]))
|
|
||||||
|
|
||||||
rc1.referenceValues = ([r1])
|
|
||||||
self.assertEqual(True, t1.isResourceAllowed(r1))
|
|
||||||
self.assertEqual((r1,), t1.getCandidateResources())
|
|
||||||
self.assertEqual((r1,), t1.getAllowedResources([r1]))
|
|
||||||
|
|
||||||
def testRCCombination(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
r2 = Resource()
|
|
||||||
self.f1['rsc2'] = r2
|
|
||||||
rc1 = self.rc1
|
|
||||||
rc1.referenceValues = [r1, r2] # allow/select both resources
|
|
||||||
rc2 = ResourceConstraint()
|
|
||||||
rc2.referenceType = 'checkmethod'
|
|
||||||
rc2.referenceKey = 'isAllowedForTesting'
|
|
||||||
Resource.isAllowedForTesting = lambda self: zapi.name(self) == 'rsc1'
|
|
||||||
t1.resourceConstraints = [rc1, rc2]
|
|
||||||
self.assertEqual((r1,), t1.getAllowedResources())
|
|
||||||
|
|
||||||
def testIsValid(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
rc1 = self.rc1
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
self.failUnless(t1.isValid()) # no constraint - everything valid
|
|
||||||
self.t1.resourceConstraints.append(rc1) # empty constraint
|
|
||||||
self.failIf(t1.isValid()) # does not allow anything
|
|
||||||
rc1.referenceValues = [r1] # explicit allow
|
|
||||||
self.failUnless(t1.isValid()) #
|
|
||||||
|
|
||||||
def testIsValidParentTask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
rc1 = self.rc1
|
|
||||||
t1.allocateResource(r1)
|
|
||||||
pt = Task()
|
|
||||||
pt.assignSubtask(t1)
|
|
||||||
self.failUnless(pt.isValid()) # no constraint - everything valid
|
|
||||||
self.t1.resourceConstraints.append(rc1) # empty constraint
|
|
||||||
self.failIf(pt.isValid()) # does not allow anything
|
|
||||||
self.failUnless(pt.isValid(False)) # don't check subtasks
|
|
||||||
|
|
||||||
|
|
||||||
class TestTaskCopy(unittest.TestCase):
|
|
||||||
"Tests related to copying tasks e.g. when using task prototypes."
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.f1 = Folder()
|
|
||||||
self.f1.__name__ = u'f1'
|
|
||||||
self.t1 = Task()
|
|
||||||
self.r1 = Resource()
|
|
||||||
self.f1['tsk1'] = self.t1
|
|
||||||
self.f1['rsc1'] = self.r1
|
|
||||||
self.rc1 = ResourceConstraint()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# the tests...
|
|
||||||
|
|
||||||
def testCopyTask(self):
|
|
||||||
t1 = self.t1
|
|
||||||
r1 = self.r1
|
|
||||||
rc1 = self.rc1
|
|
||||||
ts1 = t1.createSubtask()
|
|
||||||
ts1.resourceConstraints.append(rc1)
|
|
||||||
ts1.allocateResource(r1)
|
|
||||||
t2 = t1.copyTask()
|
|
||||||
self.failIf(t1 is t2, 't1 and t2 are still the same')
|
|
||||||
self.assertEquals(1, len(t1.getSubtasks()))
|
|
||||||
st2 = t2.getSubtasks()
|
|
||||||
self.assertEquals(1, len(st2))
|
|
||||||
ts2 = st2[0]
|
|
||||||
self.failIf(ts1 is ts2, 'ts1 and ts2 are still the same')
|
|
||||||
self.assertEquals((r1,), ts2.getAllocatedResources())
|
|
||||||
self.assertEquals([rc1,], ts2.resourceConstraints)
|
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
|
||||||
return unittest.TestSuite((
|
|
||||||
DocTestSuite('loops.tests.doctests'),
|
|
||||||
unittest.makeSuite(TestTask),
|
|
||||||
unittest.makeSuite(TestTaskResource),
|
|
||||||
unittest.makeSuite(TestTaskResourceConstraints),
|
|
||||||
unittest.makeSuite(TestTaskCopy),
|
|
||||||
))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main(defaultTest='test_suite')
|
|
Loading…
Add table
Reference in a new issue