Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
CMFDefault.tests.test_Discussions.DiscussionTests Class Reference
Inheritance diagram for CMFDefault.tests.test_Discussions.DiscussionTests:
Inheritance graph
[legend]
Collaboration diagram for CMFDefault.tests.test_Discussions.DiscussionTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_policy
def test_nestedReplies
def test_itemCataloguing
def test_itemWorkflowNotification
def test_deletePropagation
def test_deleteReplies
def test_newTalkbackIsWrapped
def test_existingTalkbackIsWrapped

Public Attributes

 site
 test_wf_notified

Static Public Attributes

 layer = EventZCMLLayer

Private Member Functions

def _makeDummyContent

Detailed Description

Definition at line 105 of file test_Discussions.py.


Member Function Documentation

def CMFDefault.tests.test_Discussions.DiscussionTests._makeDummyContent (   self,
  id,
  args,
  kw 
) [private]

Definition at line 118 of file test_Discussions.py.

00118 
00119     def _makeDummyContent(self, id, *args, **kw):
00120         return self.site._setObject( id, DummyContent(id, *args, **kw) )

Here is the caller graph for this function:

Definition at line 109 of file test_Discussions.py.

00109 
00110     def setUp(self):
00111         SecurityTest.setUp(self)
00112         self.site = DummySite('site').__of__(self.root)
00113         sm = getSiteManager()
00114         self.site._setObject( 'portal_discussion', DiscussionTool() )
00115         sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
00116         self.site._setObject( 'portal_membership', DummyTool() )
00117         self.site._setObject( 'portal_types', TypesTool() )

Definition at line 265 of file test_Discussions.py.

00265 
00266     def test_deletePropagation( self ):
00267         ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
00268         dtool = self.site.portal_discussion
00269         test = self._makeDummyContent('test', catalog=1)
00270         test.allow_discussion = 1
00271 
00272         talkback = dtool.getDiscussionFor(test)
00273         talkback.createReply( title='test'
00274                             , text='blah'
00275                             )
00276         self.assertEqual( len(ctool), 2 )
00277         self.site._delObject('test')
00278         self.assertEqual( len(ctool), 0 )

Here is the call graph for this function:

Definition at line 279 of file test_Discussions.py.

00279 
00280     def test_deleteReplies(self):
00281         dtool = self.site.portal_discussion
00282         ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
00283         test = self._makeDummyContent('test')
00284         test.allow_discussion = 1
00285 
00286         # Create a structure 6 levels deep for testing
00287         talkback = dtool.getDiscussionFor(test)
00288         id1 = talkback.createReply(title='test1', text='blah')
00289         reply1 = talkback.getReply(id1)
00290         talkback1 = dtool.getDiscussionFor(reply1)
00291         id2 = talkback1.createReply(title='test2', text='blah')
00292         reply2 = talkback1.getReply(id2)
00293         talkback2 = dtool.getDiscussionFor(reply2)
00294         id3 = talkback2.createReply(title='test3', text='blah')
00295         reply3 = talkback2.getReply(id3)
00296         talkback3 = dtool.getDiscussionFor(reply3)
00297         id4 = talkback3.createReply(title='test4', text='blah')
00298         reply4 = talkback3.getReply(id4)
00299         talkback4 = dtool.getDiscussionFor(reply4)
00300         id5 = talkback4.createReply(title='test5', text='blah')
00301         reply5 = talkback4.getReply(id5)
00302         talkback5 = dtool.getDiscussionFor(reply5)
00303         id6 = talkback5.createReply(title='test6', text='blah')
00304         reply6 = talkback5.getReply(id6)
00305         talkback6 = dtool.getDiscussionFor(reply6)
00306 
00307         self.assertEqual(len(talkback.getReplies()), 1)
00308         self.assertEqual(len(talkback1.getReplies()), 1)
00309         self.assertEqual(len(talkback2.getReplies()), 1)
00310         self.assertEqual(len(talkback3.getReplies()), 1)
00311         self.assertEqual(len(talkback4.getReplies()), 1)
00312         self.assertEqual(len(talkback5.getReplies()), 1)
00313         self.assertEqual(len(talkback6.getReplies()), 0)
00314         self.assertEqual(len(ctool), 7)
00315 
00316         talkback3.deleteReply(id4)
00317         self.assertEqual(len(talkback.getReplies()), 1)
00318         self.assertEqual(len(talkback1.getReplies()), 1)
00319         self.assertEqual(len(talkback2.getReplies()), 1)
00320         self.assertEqual(len(talkback3.getReplies()), 0)
00321         self.assertEqual(len(ctool), 4)
00322 
00323         talkback.deleteReply(id1)
00324         self.assertEqual(len(talkback.getReplies()), 0)
00325         self.assertEqual(len(ctool), 1)

Here is the call graph for this function:

Definition at line 335 of file test_Discussions.py.

00335 
00336     def test_existingTalkbackIsWrapped(self):
00337         test = self._makeDummyContent('test')
00338         test.allow_discussion = 1
00339         dtool = self.site.portal_discussion
00340         talkback = dtool.getDiscussionFor(test)
00341         talkback = dtool.getDiscussionFor(test)
00342         self.failUnless(hasattr(talkback, 'aq_base'))
00343         # Acquire a portal tool
00344         self.failUnless(getToolByName(talkback, 'portal_discussion'))
00345 

Here is the call graph for this function:

Definition at line 203 of file test_Discussions.py.

00203 
00204     def test_itemCataloguing( self ):
00205         ctool = self.site._setObject( 'portal_catalog', CatalogTool() )
00206         dtool = self.site.portal_discussion
00207         catalog = ctool._catalog
00208         test = self._makeDummyContent('test', catalog=1)
00209         test.allow_discussion = 1
00210 
00211         self.assertEqual( len(ctool), 1 )
00212         self.failUnless( has_path( catalog, test.getPhysicalPath() ) )
00213         talkback = dtool.getDiscussionFor(test)
00214         self.assertEqual( talkback.getPhysicalPath(),
00215                           ('', 'bar', 'site', 'test', 'talkback') )
00216         talkback.createReply( title='test'
00217                             , text='blah'
00218                             )
00219         self.assertEqual( len(ctool), 2 )
00220         for reply in talkback.getReplies():
00221             self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
00222             self.failUnless( has_path( catalog,
00223                               '/bar/site/test/talkback/%s' % reply.getId() ) )
00224 
00225         reply1 = talkback.getReplies()[0]
00226         talkback1 = dtool.getDiscussionFor(reply1)
00227         talkback1.createReply( title='test2'
00228                              , text='blah2'
00229                              )
00230         for reply in talkback.getReplies():
00231             self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
00232             self.failUnless( has_path( catalog,
00233                               '/bar/site/test/talkback/%s' % reply.getId() ) )
00234         for reply in talkback1.getReplies():
00235             self.failUnless( has_path( catalog, reply.getPhysicalPath() ) )
00236             self.failUnless( has_path( catalog,
00237                               '/bar/site/test/talkback/%s' % reply.getId() ) )

Here is the call graph for this function:

Definition at line 238 of file test_Discussions.py.

00238 
00239     def test_itemWorkflowNotification(self):
00240         from Products.CMFDefault.DiscussionItem import DiscussionItem
00241 
00242         dtool = self.site.portal_discussion
00243         test = self._makeDummyContent('test')
00244         test.allow_discussion = 1
00245         talkback = dtool.getDiscussionFor(test)
00246 
00247         # Monkey patch into the class to test, urgh.
00248         def notifyWorkflowCreated(self):
00249             self.test_wf_notified = 1
00250             DiscussionItem.inheritedAttribute('notifyWorkflowCreated')(self)
00251         old_method = getattr(DiscussionItem, 'notifyWorkflowCreated', None)
00252         DiscussionItem.notifyWorkflowCreated = notifyWorkflowCreated
00253         DiscussionItem.test_wf_notified = 0
00254 
00255         try:
00256             reply_id = talkback.createReply(title='test', text='blah')
00257             reply = talkback.getReplies()[0]
00258             self.assertEqual(reply.test_wf_notified, 1)
00259         finally:
00260             delattr(DiscussionItem, 'test_wf_notified')
00261             if old_method is None:
00262                 delattr(DiscussionItem, 'notifyWorkflowCreated')
00263             else:
00264                 DiscussionItem.notifyWorkflowCreated = old_method

Here is the call graph for this function:

Definition at line 153 of file test_Discussions.py.

00153 
00154     def test_nestedReplies( self ):
00155         dtool = self.site.portal_discussion
00156         test = self._makeDummyContent('test')
00157         test.allow_discussion = 1
00158         talkback = dtool.getDiscussionFor(test)
00159         assert talkback._getDiscussable() == test
00160         assert talkback._getDiscussable( outer=1 ) == test
00161         assert not talkback.hasReplies( test )
00162         assert len( talkback.getReplies() ) == 0
00163 
00164         reply_id = talkback.createReply( title='test', text='blah' )
00165         assert talkback.hasReplies( test )
00166         assert len( talkback.getReplies() ) == 1
00167         assert talkback.getReply( reply_id )
00168 
00169         reply1 = talkback.getReplies()[0]
00170         items = talkback._container.items()
00171         self.assertEqual( reply1.getId(), items[0][0] )
00172         self.assertEqual( reply1.inReplyTo(), test )
00173         self.assertEqual( reply1.listCreators(), ('dummy',) )
00174 
00175         parents = reply1.parentsInThread()
00176         assert len( parents ) == 1
00177         assert test in parents
00178 
00179         talkback1 = dtool.getDiscussionFor(reply1)
00180         assert talkback == talkback1
00181         assert len( talkback1.getReplies() ) == 0
00182         assert len( talkback.getReplies() ) == 1
00183 
00184         talkback1.createReply( title='test2'
00185                              , text='blah2'
00186                              )
00187         assert len( talkback._container ) == 2
00188         assert talkback1.hasReplies( reply1 )
00189         assert len( talkback1.getReplies() ) == 1
00190         assert len( talkback.getReplies() ) == 1
00191 
00192         reply2 = talkback1.getReplies()[0]
00193         assert reply2.inReplyTo() == reply1
00194 
00195         parents = reply2.parentsInThread()
00196         assert len( parents ) == 2
00197         assert parents[ 0 ] == test
00198         assert parents[ 1 ] == reply1
00199 
00200         parents = reply2.parentsInThread( 1 )
00201         assert len( parents ) == 1
00202         assert parents[ 0 ] == reply1

Here is the call graph for this function:

Definition at line 326 of file test_Discussions.py.

00326 
00327     def test_newTalkbackIsWrapped(self):
00328         test = self._makeDummyContent('test')
00329         test.allow_discussion = 1
00330         dtool = self.site.portal_discussion
00331         talkback = dtool.getDiscussionFor(test)
00332         self.failUnless(hasattr(talkback, 'aq_base'))
00333         # Acquire a portal tool
00334         self.failUnless(getToolByName(talkback, 'portal_discussion'))

Here is the call graph for this function:

Definition at line 121 of file test_Discussions.py.

00121 
00122     def test_policy( self ):
00123         dtool = self.site.portal_discussion
00124         ttool = self.site.portal_types
00125         test = self._makeDummyContent('test')
00126         self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
00127         assert getattr( test, 'talkback', None ) is None
00128 
00129         test.allow_discussion = 1
00130         assert dtool.getDiscussionFor(test)
00131         assert test.talkback
00132 
00133         del test.talkback
00134         del test.allow_discussion
00135         fti = FTIDATA_DUMMY[0].copy()
00136         ttool._setObject( 'Dummy Content', FTI(**fti) )
00137         self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
00138         assert getattr( test, 'talkback', None ) is None
00139 
00140         ti = getattr(ttool, 'Dummy Content')
00141         ti.allow_discussion = 1
00142         assert dtool.getDiscussionFor(test)
00143         assert test.talkback
00144 
00145         del test.talkback
00146         ti.allow_discussion = 0
00147         self.assertRaises(DiscussionNotAllowed, dtool.getDiscussionFor, test)
00148         assert getattr( test, 'talkback', None ) is None
00149 
00150         test.allow_discussion = 1
00151         assert dtool.getDiscussionFor(test)
00152         assert test.talkback

Here is the call graph for this function:


Member Data Documentation

Definition at line 107 of file test_Discussions.py.

Definition at line 111 of file test_Discussions.py.

Definition at line 248 of file test_Discussions.py.


The documentation for this class was generated from the following file: