Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
CMFPlone.tests.testBrowserDefault.TestPloneToolBrowserDefault Class Reference
Inheritance diagram for CMFPlone.tests.testBrowserDefault.TestPloneToolBrowserDefault:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.tests.testBrowserDefault.TestPloneToolBrowserDefault:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def compareLayoutVsView
def compareLayoutVsCall
def testBrowserDefaultMixinFolderDefaultPage
def testBrowserDefaultMixinFolderIndexHtml
def testBrowserDefaultMixinFolderGlobalDefaultPage
def testViewMethodWithBrowserDefaultMixinGetsSelectedLayout
def testCallWithBrowserDefaultMixinGetsSelectedLayout
def testBrowserDefaultMixinFileViewMethodGetsTemplate
def testBrowserDefaultMixinFileDumpsContent
def testIndexHtmlNotAcquired
def testIndexHtmlReplaceableWrapper
def testCallDocumentGivesTemplate
def testCallFolderWithoutDefaultPageGivesTemplate
def testCallFolderWithDefaultPageGivesTemplate
def testCallFileGivesTemplate
def testReselectingDefaultLayoutAfterDefaultPageWorks
def testBrowserDefaultMixinWithoutFtiGivesSensibleError
def testFolderDefaultPageSameAsSelfWithPageMissing

Public Attributes

 basic_auth
 putils

Detailed Description

Test the PloneTool's browserDefault() method in various use cases.
This class basically tests the functionality when items have default pages
and actions that resolve to actual objects. The cases where a default_page
may be set to a non-existing object are covered by TestDefaultPage below.

Definition at line 25 of file testBrowserDefault.py.


Member Function Documentation

Definition at line 32 of file testBrowserDefault.py.

00032 
00033     def afterSetUp(self):
00034         self.setRoles(['Manager'])
00035         self.basic_auth = '%s:%s' % (default_user, default_password)
00036 
00037         _createObjectByType('Folder',       self.portal, 'atctfolder')
00038         _createObjectByType('Document',     self.portal, 'atctdocument')
00039         _createObjectByType('File',         self.portal, 'atctfile')
00040 
00041         self.putils = getToolByName(self.portal, "plone_utils")

Here is the call graph for this function:

Definition at line 74 of file testBrowserDefault.py.

00074 
00075     def compareLayoutVsCall(self, obj):
00076         if hasattr(aq_base(obj), 'getLayout'):
00077             viewaction = obj.getLayout()
00078         else:
00079             viewaction = obj.getTypeInfo().getActionInfo('object/view')['url'].split('/')[-1]
00080 
00081         base_path = obj.absolute_url(1)
00082         viewed = getattr(obj, viewaction)()
00083         called = obj()
00084 
00085         # request/ACTUAL_URL is fubar in tests, remove line that depends on it
00086         called = RE_REMOVE_DOCCONT.sub('', called)
00087         viewed = RE_REMOVE_DOCCONT.sub('', viewed)
00088 
00089         if not called or not viewed:
00090             self.fail('No body in response')
00091 
00092         if not viewed == called:
00093             diff = difflib.unified_diff(viewed.split("\n"),
00094                                         called.split("\n"))
00095             self.fail("\n".join([line for line in diff]))

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.testBrowserDefault.TestPloneToolBrowserDefault.compareLayoutVsView (   self,
  obj,
  path = "",
  viewaction = None 
)

Definition at line 42 of file testBrowserDefault.py.

00042 
00043     def compareLayoutVsView(self, obj, path="", viewaction=None):
00044         if viewaction is None:
00045             if hasattr(aq_base(obj), 'getLayout'):
00046                 viewaction = obj.getLayout()
00047             else:
00048                 viewaction = obj.getTypeInfo().getActionInfo('object/view')['url'].split('/')[-1]
00049 
00050         resolved = getattr(obj, viewaction)()
00051         base_path = obj.absolute_url(1)
00052 
00053         response = self.publish(base_path+path, self.basic_auth)
00054         body = response.getBody().decode('utf-8')
00055 
00056         # request/ACTUAL_URL is fubar in tests, remove lines that depend on it
00057         resolved = RE_REMOVE_DOCCONT.sub('', resolved)
00058         resolved = RE_REMOVE_NAVTREE.sub('', resolved)
00059         resolved = RE_REMOVE_TABS.sub('', resolved)
00060         
00061         body = RE_REMOVE_DOCCONT.sub('', body)
00062         body = RE_REMOVE_NAVTREE.sub('', body)
00063         body = RE_REMOVE_TABS.sub('', body)
00064 
00065         if not body:
00066             self.fail('No body in response')
00067 
00068         if not body == resolved:
00069             diff = difflib.unified_diff(body.split("\n"),
00070                                         resolved.split("\n"))
00071             self.fail("\n".join([line for line in diff]))
00072 
00073         return response

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 131 of file testBrowserDefault.py.

00131 
00132     def testBrowserDefaultMixinFileDumpsContent(self):
00133         response = self.publish(self.portal.atctfile.absolute_url(1), self.basic_auth)
00134         self.failUnlessEqual(response.getBody(), str(self.portal.atctfile.getFile()))
00135 

Definition at line 128 of file testBrowserDefault.py.

00128 
00129     def testBrowserDefaultMixinFileViewMethodGetsTemplate(self):
00130         self.compareLayoutVsView(self.portal.atctfile, path="/view")

Here is the call graph for this function:

Definition at line 98 of file testBrowserDefault.py.

00098 
00099     def testBrowserDefaultMixinFolderDefaultPage(self):
00100         self.portal.atctfolder.invokeFactory('Document', 'default')
00101         self.portal.atctfolder.setDefaultPage('default')
00102         self.assertEqual(self.putils.browserDefault(self.portal.atctfolder),
00103                          (self.portal.atctfolder, ['default'],))

Definition at line 112 of file testBrowserDefault.py.

00112 
00113     def testBrowserDefaultMixinFolderGlobalDefaultPage(self):
00114         getToolByName(self.portal, "portal_properties").site_properties.manage_changeProperties(default_page = ['foo'])
00115         self.portal.atctfolder.invokeFactory('Document', 'foo')
00116         self.assertEqual(self.putils.browserDefault(self.portal.atctfolder),
00117                          (self.portal.atctfolder, ['foo']))

Here is the call graph for this function:

Definition at line 104 of file testBrowserDefault.py.

00104 
00105     def testBrowserDefaultMixinFolderIndexHtml(self):
00106         self.portal.atctfolder.invokeFactory('Document', 'default')
00107         self.portal.atctfolder.setDefaultPage('default')
00108         # index_html should always win - it's an explicit override!
00109         self.portal.atctfolder.invokeFactory('Document', 'index_html')
00110         self.assertEqual(self.putils.browserDefault(self.portal.atctfolder),
00111                          (self.portal.atctfolder, ['index_html'],))

Definition at line 178 of file testBrowserDefault.py.

00178 
00179     def testBrowserDefaultMixinWithoutFtiGivesSensibleError(self):
00180         # Test for issue http://dev.plone.org/plone/ticket/5676
00181         # Ensure that the error displayed for missing FTIs is not so cryptic
00182         getToolByName(self.portal, "portal_types")._delOb('Document')
00183 
00184         self.assertRaises(AttributeError,
00185                           self.portal.plone_utils.browserDefault,
00186                           self.portal.atctdocument)

Here is the call graph for this function:

Definition at line 153 of file testBrowserDefault.py.

00153 
00154     def testCallDocumentGivesTemplate(self):
00155         self.compareLayoutVsCall(self.portal.atctdocument)

Here is the call graph for this function:

Definition at line 164 of file testBrowserDefault.py.

00164 
00165     def testCallFileGivesTemplate(self):
00166         self.portal.atctfolder.invokeFactory('File', 'f1')
00167         self.compareLayoutVsCall(self.portal.atctfolder.f1)

Here is the call graph for this function:

Definition at line 159 of file testBrowserDefault.py.

00159 
00160     def testCallFolderWithDefaultPageGivesTemplate(self):
00161         self.portal.atctfolder.invokeFactory('Document', 'doc')
00162         self.portal.atctfolder.setDefaultPage('doc')
00163         self.compareLayoutVsCall(self.portal.atctfolder)

Here is the call graph for this function:

Definition at line 156 of file testBrowserDefault.py.

00156 
00157     def testCallFolderWithoutDefaultPageGivesTemplate(self):
00158         self.compareLayoutVsCall(self.portal.atctfolder)

Here is the call graph for this function:

Definition at line 123 of file testBrowserDefault.py.

00123 
00124     def testCallWithBrowserDefaultMixinGetsSelectedLayout(self):
00125         self.compareLayoutVsView(self.portal.atctdocument, path="")

Here is the call graph for this function:

Definition at line 187 of file testBrowserDefault.py.

00187 
00188     def testFolderDefaultPageSameAsSelfWithPageMissing(self):
00189         # We need to avoid infinite recursion in the case that
00190         # a page with the same id as the folder was made the default
00191         # page and then deleted. See http://dev.plone.org/plone/ticket/5704
00192         # We should fallback on the default layout folder_listing
00193         f = self.portal.atctfolder
00194         f.invokeFactory('Document', f.getId())
00195         f.setDefaultPage(f.getId())
00196         self.assertEqual(self.putils.browserDefault(f),
00197                          (f, [f.getId()],))
00198         f._delObject(f.getId())
00199         self.assertEqual(self.putils.browserDefault(f),
00200                          (f, ['folder_listing'],))
00201 

Definition at line 138 of file testBrowserDefault.py.

00138 
00139     def testIndexHtmlNotAcquired(self):
00140         self.portal.atctfolder.invokeFactory('Document', 'index_html')
00141         self.portal.atctfolder.invokeFactory('Folder', 'subfolder')
00142         layout = self.portal.atctfolder.getLayout()
00143         self.assertEqual(self.putils.browserDefault(self.portal.atctfolder.subfolder),
00144                          (self.portal.atctfolder.subfolder, [layout]))

Definition at line 145 of file testBrowserDefault.py.

00145 
00146     def testIndexHtmlReplaceableWrapper(self):
00147         self.portal.atctdocument.index_html = ReplaceableWrapper(None)
00148         layout = self.portal.atctdocument.getLayout()
00149         self.assertEqual(self.putils.browserDefault(self.portal.atctdocument),
00150                          (self.portal.atctdocument, [layout]))

Definition at line 170 of file testBrowserDefault.py.

00170 
00171     def testReselectingDefaultLayoutAfterDefaultPageWorks(self):
00172         defaultLayout = self.portal.atctfolder.getDefaultLayout()
00173         self.portal.atctfolder.invokeFactory('Document', 'default')
00174         self.portal.atctfolder.setDefaultPage('default')
00175         self.portal.atctfolder.setLayout(defaultLayout)
00176         self.assertEqual(self.portal.atctfolder.getDefaultPage(), None)
00177         self.assertEqual(self.portal.atctfolder.defaultView(), defaultLayout)

Definition at line 120 of file testBrowserDefault.py.

00120 
00121     def testViewMethodWithBrowserDefaultMixinGetsSelectedLayout(self):
00122         self.compareLayoutVsView(self.portal.atctdocument, path="/view")

Here is the call graph for this function:


Member Data Documentation

Definition at line 34 of file testBrowserDefault.py.

Definition at line 40 of file testBrowserDefault.py.


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