# # Test case for Task content # import os, sys, re if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from Testing import ZopeTestCase from Testing.ZopeTestCase.functional import Functional from KrihvelTestCase import KrihvelTestCase from Products.Krihvel.BaseTask import BaseTask from Products.Archetypes.public import PrimaryFieldMarshaller types = ('Paper',) class TestTasks(KrihvelTestCase,Functional): def afterSetUp(self): self.types=self.portal.portal_types def construct(self, portal_type, id, folder): folder.invokeFactory(type_name=portal_type,id=id) self.failUnless(id in folder.objectIds()) return getattr(folder, id) def construct2(self, portal_type, id, folder): fti = self.types.getTypeInfo(portal_type) fti.constructInstance(folder, id=id) self.failUnless(id in folder.objectIds()) return getattr(folder, id) def testExistence(self): for pt in types: ob = self.construct(pt,pt,self.folder) self.failUnlessEqual(ob._getPortalTypeName(),pt) self.failUnlessEqual(ob.portal_type,pt) id2 = "%s2" % pt ob = self.construct(pt,id2,self.folder) self.failUnlessEqual(ob._getPortalTypeName(),pt) self.failUnlessEqual(ob.portal_type,pt) def testBaseTaskAbstractness(self): self.assertRaises(ValueError,self.construct,'BaseTask','test',self.folder) class TestPaper(TestTasks): def testEditing(self): ID='paper' TITLE='Test' EXERCISE='
Test paragraph
' ob=self.construct('Paper', ID ,self.folder) ob.edit(title=TITLE, Exercise=EXERCISE) self.assertEqual(ob.Title(), TITLE) self.assertEqual(ob.getBody(), BODY) def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(TestTasks)) suite.addTest(makeSuite(TestPaper)) return suite if __name__ == '__main__': framework()