From: Matt S. <dop...@us...> - 2004-10-01 05:29:44
|
Update of /cvsroot/collective/ATImportTool/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18035/tests Modified Files: common.py test_registry.py Added Files: test_import.py Log Message: * Nested content importing is now supported. * Added some tests * created ImportTool.py, ATImportTool.py is basically the command line component for now * Other stuff I forgot --- NEW FILE: test_import.py --- """ from Products.ATImportTool.ImportTool import ImportTool IT = ImportTool() IT.setDefaultType('ATFolder') IT.setDefaultFolder(app.importing) IT.setImportUser('importer') from Products.ATImportTool.DataContainers import ContentCollection,Content,Field from Products.ATImportTool.tests.common import * c=makeDummyFolderContent() IT.Import(c) """ Index: test_registry.py =================================================================== RCS file: /cvsroot/collective/ATImportTool/tests/test_registry.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test_registry.py 3 Sep 2004 23:30:06 -0000 1.2 +++ test_registry.py 1 Oct 2004 05:29:25 -0000 1.3 @@ -3,63 +3,104 @@ execfile(os.path.join(sys.path[0], 'framework.py')) from Products.ATImportTool.tests.utils import * -from Products.ATImportTool.tests.common import DummyTransform +from Products.ATImportTool.tests.common import * from Products.ATImportTool.transforms import * from unittest import TestCase, TestSuite, makeSuite from Products.ATImportTool.DataTransform import DataTransform from Products.ATImportTool.DataTransformRegistry import DataTransformTool from Products.ATImportTool.DataTransformRegistry import DataTransformException +from Products.ATImportTool.DataReaderRegistry import DataReaderTool +from Products.ATImportTool.DataReaderRegistry import DataReaderException from Products.ATImportTool.Registry import RegistryException DTT=DataTransformTool +DTT.register('dummy',DummyTransform) -class RegistryTests(TestCase): +class TransformRegistryTests(TestCase): #fakeObject=makeFakeObject() def test_register(self): - - try: - DTT.register('dummy',DummyTransform()) - except: - pass - #pass-in bad transform self.assertRaises(RegistryException, DTT.register,'name',str) - #make sure we are returning the right class - assert isinstance(DTT.get('dummy'),DummyTransform) + assert isinstance(DTT.getTransform('dummy'),DummyTransform) #don't allow dupe names - self.assertRaises(RegistryException, DTT.register,'dummy',DummyTransform()) + self.assertRaises(RegistryException, DTT.register,'dummy',DummyTransform) + + #don't allow registering of instances + self.assertRaises(RegistryException, DTT.register,'dummy_',DummyTransform()) #def test_list_transform(self): def test_transform(self): - try: - DTT.register('dummy',DummyTransform()) - except: - pass - - t=DTT.get('dummy') + t=DTT.getTransform('dummy') in1='a' out1=t(in1) self.assertEquals(in1,out1) + def test_get(self): + assert DTT.get('dummy')!=None + assert DTT.get('wrong name')==None + self.assertRaises(DataTransformException, DTT.getTransform ,'wrong name') + + +DRT=DataReaderTool +DRT.register('dummy',DummyReader) + +class ReaderRegistryTests(TestCase): + + #fakeObject=makeFakeObject() + def test_register(self): + #pass-in bad transform + self.assertRaises(RegistryException, DRT.register,'name',str) + + #make sure we are returning the right class + assert isinstance(DTT.get('dummy'),DummyTransform) + + #don't allow dupe names + self.assertRaises(RegistryException, DRT.register,'dummy',DummyReader) + + #don't allow registering of instances + self.assertRaises(RegistryException, DRT.register,'dummy_',DummyReader()) + + #def test_list_transform(self): + + def test_transform(self): + o=DRT.getReader('dummy') + + self.assertEquals(o[0].getName(),'name1') + self.assertEquals(o[1].getName(),'name2') + self.assertEquals(o[2].getName(),'name3') + self.assertEquals(o[3].getName(),'name4') + + self.assertEquals(o[0].getValue(),'data1') + self.assertEquals(o[1].getValue(),'a|b|c|d') + self.assertEquals(o[2].getValue(),'data2') + self.assertEquals(o[3].getValue(),'data3') + + self.assertEquals(o[0].getTransforms(),[]) + self.assertEquals(o[1].getTransforms(),['list']) + self.assertEquals(o[2].getTransforms(),[]) + self.assertEquals(o[3].getTransforms(),[]) + + + def test_get(self): try: - DTT.register('dummy',DummyTransform()) + DRT.register('dummy',DummyTransform()) except: pass - assert DTT.get('dummy')!=None - assert DTT.get('wrong name')==None - self.assertRaises(DataTransformException, DTT.getTransform ,'wrong name') + assert DRT.get('dummy')!=None + assert DRT.get('wrong name')==None + self.assertRaises(DataTransformException, DRT.getReader ,'wrong name') def test_suite(): suite = TestSuite() - suite.addTest(makeSuite(RegistryTests)) + suite.addTest(makeSuite(TransformRegistryTests)) return suite if __name__ == '__main__': Index: common.py =================================================================== RCS file: /cvsroot/collective/ATImportTool/tests/common.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- common.py 3 Sep 2004 23:09:16 -0000 1.1 +++ common.py 1 Oct 2004 05:29:25 -0000 1.2 @@ -1,4 +1,9 @@ from Products.ATImportTool.DataTransform import DataTransform +## This file got overwritten somehow, and it is probably missing some things for now +## I haven't had time to run the tests and find out yet + +from Products.ATImportTool.DataContainers import ContentCollection,Content,Field + class TestPreconditionFailed(Exception): """ Some modules are missing or other preconditions have failed """ def __init__(self, test, precondition): @@ -17,3 +22,18 @@ def transform(self,data,ploneInstance=None,objectData=None): return data + +def makeDummyFolderContent(): + cc=ContentCollection() + for i in range(10): + c=Content() + c.add(Field(n='id',v='folder%s'%i)) + c.add(Field(n='title',v='Folder %s'%i)) + for ii in range(5): + child=Content() + child.add(Field(n='id',v='sub_folder%s_%s'%(i,ii))) + child.add(Field(n='title',v='Sub Folder %s.%s'%(i,ii))) + c.addChild(child) + cc.add(c) + + return cc \ No newline at end of file |