[Checkins] SVN: Sandbox/ulif/grok-adminui-experimental/src/grok/ Tests for broken object handling.

Uli Fouquet uli at gnufix.de
Mon Aug 27 17:32:59 EDT 2007


Log message for revision 79299:
  Tests for broken object handling.

Changed:
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/admin/docgrok.py
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view_templates/applications.pt
  U   Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/apps.py
  A   Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/brokenobjs.py

-=-
Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/docgrok.py
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/admin/docgrok.py	2007-08-27 20:54:26 UTC (rev 79298)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/admin/docgrok.py	2007-08-27 21:32:59 UTC (rev 79299)
@@ -490,7 +490,11 @@
         ob = resolve(self.path)
         filename = ob.__file__
         module_info = ModuleInfo(filename, self.path)
-        infos = module_info.getSubModuleInfos()
+        try:
+            infos = module_info.getSubModuleInfos(exclude_tests=False)
+        except TypeError:
+            # Another version of martian.scan is installed
+            infos = module_info.getSubModuleInfos()
         if filter_func is not None:
             infos = filter(filter_func, infos)
         result = []

Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py	2007-08-27 20:54:26 UTC (rev 79298)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view.py	2007-08-27 21:32:59 UTC (rev 79299)
@@ -371,7 +371,8 @@
 
         # Installed apps...
         inst_apps = [x for x in self.context.values()
-                     if hasattr(x, '__class__') and x.__class__ in apps]
+                     if hasattr(x, '__class__') and x.__class__ in apps
+                     and not issubclass(x.__class__, Broken)]
         inst_apps.sort(lambda x, y: cmp(x.__name__, y.__name__))
         self.installed_applications = inst_apps
 

Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view_templates/applications.pt
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view_templates/applications.pt	2007-08-27 20:54:26 UTC (rev 79298)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/admin/view_templates/applications.pt	2007-08-27 21:32:59 UTC (rev 79299)
@@ -2,15 +2,21 @@
   <div metal:fill-slot="content">
 
     <form tal:define="apps context/values"
-	  tal:attributes="action string:${context/@@absolute_url}/delete"
-	  tal:condition="apps|nothing">
-      <fieldset
-	  tal:condition="python: len(view.installed_applications)">
+	  tal:attributes="action string:${context/@@absolute_url}/delete">
+
+      <fieldset>
         <legend>Installed applications</legend>
-        <div tal:repeat="app view/installed_applications">
+
+	<div tal:condition="not: python: len(view.installed_applications)">
+	  <p class="menu-description1">Currently no working applications are 
+	  installed.</p>
+	</div>
+
+	<div tal:condition="python: len(view.installed_applications) or True" 
+	     tal:repeat="app view/installed_applications">
 	  <input type="checkbox" 
 		 class="checkbox" 
-                 tal:attributes="value app/__name__;
+		 tal:attributes="value app/__name__;
 				 name string:items" />
 	  <a tal:attributes="href string:${context/@@absolute_url}/${app/__name__}">
 	    <span tal:replace="app/__name__"/>
@@ -18,7 +24,7 @@
 	  </a>
 	  &nbsp;&nbsp;
 	  [<a href=""
-	      tal:attributes="href string:${context/@@absolute_url}/${app/__name__}/@@inspect.html"
+	  tal:attributes="href string:${context/@@absolute_url}/${app/__name__}/@@inspect.html"
 	  >object browser</a>]
 	</div>
 
@@ -35,16 +41,11 @@
 	</div>
 
 	<p>
-	  <input class="button" type="submit" value="Delete Selected"/></p>
+	  <input tal:condition="python:len(view.installed_applications)+len(view.broken_applications) > 0"
+	      class="button" type="submit" value="Delete Selected"/></p>
       </fieldset>
     </form>
 
-    <fieldset
-	tal:condition="not: python: len(view.installed_applications)">
-      <legend>Installed applications</legend>
-      <p class="menu-description1">Currently no applications are installed.</p>
-    </fieldset>
-
     <fieldset>	
       <legend>Add application</legend>
 

Modified: Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/apps.py
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/apps.py	2007-08-27 20:54:26 UTC (rev 79298)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/apps.py	2007-08-27 21:32:59 UTC (rev 79299)
@@ -36,7 +36,7 @@
   >>> print browser.contents
   <html xmlns="http://www.w3.org/1999/xhtml">
   ...
-  ... <p ...>Currently no applications are installed.</p>
+  ... <p ...>Currently no working applications are...installed.</p>
   ...
 
 We are able to add a mammoth manager...
@@ -90,7 +90,7 @@
   >>> print browser.contents
   <html xmlns="http://www.w3.org/1999/xhtml">
   ...
-  ... <p ...>Currently no applications are installed.</p>
+  ... <p ...>Currently no working applications are...installed.</p>
   ...
   ...<legend>Add application</legend>
   ...

Added: Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/brokenobjs.py
===================================================================
--- Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/brokenobjs.py	                        (rev 0)
+++ Sandbox/ulif/grok-adminui-experimental/src/grok/ftests/admin/brokenobjs.py	2007-08-27 21:32:59 UTC (rev 79299)
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+The admin-UI now supports detection and deletion of broken objects. It
+is still limited to IApplication objects in the root folder. Options
+to repair broken objects are also still missing.
+
+We first setup the environment:
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+If no broken applications are in the root, everything should look as
+usual:
+
+  >>> browser.open('http://localhost/applications')
+  >>> 'broken' not in browser.contents
+  True
+
+Now we grok this module, to have a new application type available,
+which is intentionally broken:
+
+  >>> import grok
+  >>> grok.grok('grok.ftests.admin.brokenobjs')
+  >>> browser.open('http://localhost/applications')
+  >>> 'PseudoBroken' in browser.contents
+  True
+
+We add an instance of that new type:
+
+  >>> subform = browser.getForm(name='PseudoBroken')
+  >>> subform
+  <zope.testbrowser.browser.Form object at 0x...>
+
+  >>> subform.getControl('Name your new app').value = 'mybrokenobj'
+  >>> subform.getControl('Create').click()
+
+and the broken object should show up in the applications list:
+
+ >>> print browser.contents
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ ...
+ ...Currently no working applications are...installed...
+ ...
+ ...Broken applications:...
+ ...
+ ...(broken type: grok.ftests.admin.brokenobjs.PseudoBroken)...
+ ...This application is broken!...
+ ...
+
+If we want to delete the broken object, we can do so:
+
+  >>> ctrl = browser.getControl(name='items')
+  >>> ctrl.getControl(value='mybrokenobj').selected = True
+  >>> browser.getControl('Delete Selected').click()
+  >>> print browser.contents
+  <html xmlns="http://www.w3.org/1999/xhtml">
+  ...
+  ...Application `mybrokenobj` was successfully deleted.
+  ...
+
+and the 'Broken applications' section won't show up anymore:
+
+  >>> 'Broken applications:' not in browser.contents
+  True
+
+
+"""
+import grok
+from ZODB.broken import Broken
+class PseudoBroken(grok.Application, grok.Container, Broken):
+    """A class intentianally broken.
+    """
+    pass



More information about the Checkins mailing list