Back to index

plone3  3.1.7
test_content.py
Go to the documentation of this file.
00001 import unittest
00002 from plone.app.layout.viewlets.tests.base import ViewletsTestCase
00003 from plone.app.layout.viewlets.content import DocumentBylineViewlet
00004 from plone.locking.tests import addMember
00005 from plone.locking.interfaces import ILockable
00006 
00007 class TestDocumentBylineViewletView(ViewletsTestCase):
00008     """
00009     Test the document by line viewlet
00010     """
00011     def afterSetUp(self):
00012         addMember(self, 'Alan', roles=('Member', 'Manager'))
00013         addMember(self, 'Ano', roles=())
00014 
00015     def test_anonymous_locked_icon(self):
00016         request = self.app.REQUEST
00017         self.setRoles(['Manager', 'Member'])
00018         self.portal.invokeFactory('Document', 'd1')
00019         context = getattr(self.portal, 'd1')
00020         viewlet = DocumentBylineViewlet(context, request, None, None)
00021         viewlet.update()
00022         ILockable(context).lock()
00023         self.login('Ano')
00024         viewlet = DocumentBylineViewlet(context, request, None, None)
00025         viewlet.update()
00026         self.assertEqual(viewlet.locked_icon(), "")
00027 
00028     def test_locked_icon(self):
00029         request = self.app.REQUEST
00030         self.setRoles(['Manager', 'Member'])
00031         self.portal.invokeFactory('Document', 'd1')
00032         context = getattr(self.portal, 'd1')
00033         viewlet = DocumentBylineViewlet(context, request, None, None)
00034         viewlet.update()
00035         self.assertEqual(viewlet.locked_icon(), "")
00036         ILockable(context).lock()
00037         self.assertEqual(viewlet.locked_icon(), "")
00038         self.login('Alan')
00039         viewlet = DocumentBylineViewlet(context, request, None, None)
00040         viewlet.update()
00041         lockIconUrl = '<img src="http://nohost/plone/lock_icon.gif" alt="" \
00042 title="Locked" height="16" width="16" />'
00043         self.assertEqual(viewlet.locked_icon(), lockIconUrl)
00044 
00045 def test_suite():
00046     suite = unittest.TestSuite()
00047     suite.addTest(unittest.makeSuite(TestDocumentBylineViewletView))
00048     return suite