Back to index

plone3  3.1.7
testDiffTool.py
Go to the documentation of this file.
00001 #
00002 # CMFDiffTool tests
00003 #
00004 
00005 import BaseTestCase
00006 from Products.CMFDiffTool.CMFDiffTool import registerDiffType
00007 from Products.CMFDiffTool.CMFDiffTool import unregisterDiffType
00008 
00009 class DummyDiff:
00010     meta_type = "Dummy Diff Type"
00011 
00012 class DummyDiff2:
00013     meta_type = "Second Dummy Diff Type"
00014 
00015 class TestDiffTool(BaseTestCase.BaseTestCase):
00016     """Test the portal_diff tool"""
00017 
00018     def afterSetUp(self):
00019         self.p_diff = self.portal.portal_diff
00020         registerDiffType(DummyDiff)
00021 
00022     def testInterface(self):
00023         """Ensure that tool instances implement the portal_diff interface"""
00024         from Products.CMFDiffTool.interfaces.portal_diff import portal_diff
00025         self.failUnless(portal_diff.isImplementedBy(self.p_diff))
00026 
00027     def testRegisterDiffType(self):
00028         """Test registration of Diff types"""
00029         unregisterDiffType(DummyDiff)
00030         self.failIf('Dummy Diff Type' in self.p_diff.listDiffTypes())
00031         registerDiffType(DummyDiff)
00032         self.failUnless('Dummy Diff Type' in self.p_diff.listDiffTypes())
00033 
00034     def testSetDiff(self):
00035         """Test setDiffForPortalType() method"""
00036         d = {'field1':'TestDiff', 'field2':'Dummy Diff Type'}
00037         self.p_diff.setDiffForPortalType('Document', d)
00038         self.failUnless(self.p_diff.getDiffForPortalType('Document') == d)
00039 
00040     def testSetDiffReplaces(self):
00041         """Test that setDiffForPortalType() replaces old data"""
00042         d1 = {'field1':'TestDiff', 'field2':'Dummy Diff Type'}
00043         d2 = {'field3':'Dummy Diff Type'}
00044         self.p_diff.setDiffForPortalType('Document', d1)
00045         self.p_diff.setDiffForPortalType('Document', d2)
00046         self.failUnless(self.p_diff.getDiffForPortalType('Document') == d2)
00047 
00048     def testSingleSetDiffField(self):
00049         """Test setDiffField method"""
00050         self.p_diff.setDiffField('Document', 'title', 'Dummy Diff Type')
00051         self.failUnless(self.p_diff.getDiffForPortalType('Document') == {'title':'Dummy Diff Type'})
00052 
00053     def testMultipleSetDiffField(self):
00054         """Test setDiffField method adding a second field to one content type"""
00055         self.p_diff.setDiffField('Document', 'title', 'Dummy Diff Type')
00056         self.p_diff.setDiffField('Document', 'description', 'Dummy Diff Type')
00057         d = {'title':'Dummy Diff Type', 'description':'Dummy Diff Type'}
00058         self.failUnless(self.p_diff.getDiffForPortalType('Document') == d)
00059 
00060     def testReplaceSetDiffField(self):
00061         """Test that setDiffField does a replace for existing fields"""
00062         registerDiffType(DummyDiff2)
00063         self.p_diff.setDiffField('Document', 'title', 'Dummy Diff Type')
00064         self.p_diff.setDiffField('Document', 'title', 'Second Dummy Diff Type')
00065         d = {'title':'Second Dummy Diff Type'}
00066         self.failUnless(self.p_diff.getDiffForPortalType('Document') == d)
00067         unregisterDiffType(DummyDiff2)
00068 
00069     def testSetDiffFieldNameFailure(self):
00070         self.assertRaises('BadRequest', self.p_diff.setDiffField, 'Bob', 'title', 'Dummy Diff Type')
00071 
00072     def testSetDiffFieldBlankFieldFailure(self):
00073         self.assertRaises('BadRequest', self.p_diff.setDiffField, 'Document', '', 'Dummy Diff Type')
00074 
00075     def testSetDiffFieldInvalidDiffFailure(self):
00076         self.assertRaises('BadRequest', self.p_diff.setDiffField, 'Document', 'title', 'NoDiff')
00077 
00078     def beforeTearDown(self):
00079         # Undo changes that don't get rolled back (i.e. module level changes)
00080         unregisterDiffType(DummyDiff)
00081 
00082 
00083 def test_suite():
00084     import unittest
00085     suite = unittest.TestSuite()
00086     suite.addTest(unittest.makeSuite(TestDiffTool))
00087     return suite
00088