[Checkins] SVN: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/ add tests for directoryresources in of various registrations

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Oct 13 15:26:51 EDT 2008


Log message for revision 92149:
  add tests for directoryresources in of various registrations

Changed:
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/__init__.py
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/dirresource.py
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/__init__.py
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/anotherfile.txt
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/file.txt
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/baz/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/baz/file.txt
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/file.txt
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/foo/
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/foo/file.txt
  A   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/resource.py
  U   grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/test_functional.py

-=-
Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/__init__.py
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/__init__.py	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/__init__.py	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+# this is a package

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/dirresource.py
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/dirresource.py	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/dirresource.py	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1,67 @@
+"""
+A directory resource defined without an explicit name direective is available
+through the dotted name of the module in which the directoryresource is
+defined::
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> browser.open(
+  ...     'http://localhost/@@/'
+  ...     'grokcore.view.ftests.directoryresource.fixture.resource/file.txt')
+  >>> print browser.contents
+  Foo resource file's content.
+
+Directoryresource registrations can be differentiated based on layers (and
+skins)::
+
+  >>> browser.open(
+  ...     'http://localhost/++skin++another/@@/'
+  ...     'grokcore.view.ftests.directoryresource.fixture.resource/file.txt')
+  >>> print browser.contents
+  Anotherfoo resource file's content.
+
+This resource is only available on the particular layer::
+
+  >>> browser.open(
+  ...     'http://localhost/++skin++another/@@/'
+  ...     'grokcore.view.ftests.directoryresource.fixture.resource/'
+  ...     'anotherfile.txt')
+  >>> print browser.contents
+  Anotherfoo resource anotherfile's content.
+
+  >>> browser.handleErrors = True
+  >>> browser.open(
+  ...     'http://localhost/@@/'
+  ...     'grokcore.view.ftests.directoryresource.fixture.resource/'
+  ...     'anotherfile.txt')
+  Traceback (most recent call last):
+  ...
+  httperror_seek_wrapper: HTTP Error 404: Not Found
+
+Directoryresources can be registered under an explicit name::
+
+  >>> browser.handleErrors = False
+  >>> browser.open('http://localhost/@@/fropple/file.txt')
+  >>> print browser.contents
+  Bar resource file's content.
+
+Subdirectories are published as directoryresources recusively::
+
+  >>> browser.open('http://localhost/@@/fropple/baz/file.txt')
+  >>> print browser.contents
+  Baz resource file's content.
+
+A relative path to a directory with resources::
+
+  >>> browser.open('http://localhost/@@/frepple/file.txt')
+  >>> print browser.contents
+  Baz resource file's content.
+
+An absolute path to a directory with resources::
+
+  >>> browser.open('http://localhost/@@/frupple/file.txt')
+  >>> print browser.contents
+  Baz resource file's content.
+
+"""

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/__init__.py
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/__init__.py	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/__init__.py	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+# this is a package

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/anotherfile.txt
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/anotherfile.txt	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/anotherfile.txt	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+Anotherfoo resource anotherfile's content.
\ No newline at end of file

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/file.txt
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/file.txt	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/anotherfoo/file.txt	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+Anotherfoo resource file's content.
\ No newline at end of file

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/baz/file.txt
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/baz/file.txt	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/baz/file.txt	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+Baz resource file's content.
\ No newline at end of file

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/file.txt
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/file.txt	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/bar/file.txt	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+Bar resource file's content.
\ No newline at end of file

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/foo/file.txt
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/foo/file.txt	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/foo/file.txt	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1 @@
+Foo resource file's content.
\ No newline at end of file

Added: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/resource.py
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/resource.py	                        (rev 0)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/directoryresource/fixture/resource.py	2008-10-13 19:26:50 UTC (rev 92149)
@@ -0,0 +1,26 @@
+import os
+import grokcore.view
+
+class DirectoryResourceFoo(grokcore.view.DirectoryResource):
+    grokcore.view.path('foo')
+
+class IAnotherLayer(grokcore.view.IDefaultBrowserLayer):
+    grokcore.view.skin('another')
+
+class DirectoryResourceFooOnLayer(grokcore.view.DirectoryResource):
+    grokcore.view.layer(IAnotherLayer)
+    grokcore.view.path('anotherfoo')
+
+class DirectoryResourceBarWithName(grokcore.view.DirectoryResource):
+    grokcore.view.name('fropple')
+    grokcore.view.path('bar')
+
+class DirectoryResourceBazInsubdirWithName(grokcore.view.DirectoryResource):
+    grokcore.view.name('frepple')
+    grokcore.view.path('bar/baz')
+
+absolute_path = os.path.join(os.path.dirname(__file__), 'bar', 'baz')
+
+class DirectoryResourceQuxWithNameAbsolutePath(grokcore.view.DirectoryResource):
+    grokcore.view.name('frupple')
+    grokcore.view.path(absolute_path)

Modified: grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/test_functional.py
===================================================================
--- grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/test_functional.py	2008-10-13 19:25:32 UTC (rev 92148)
+++ grokcore.view/branches/jw-generic_directory_resource/src/grokcore/view/ftests/test_functional.py	2008-10-13 19:26:50 UTC (rev 92149)
@@ -51,6 +51,6 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    for name in ['view', 'staticdir', 'url']:
+    for name in ['view', 'staticdir', 'url', 'directoryresource']:
         suite.addTest(suiteFromPackage(name))
     return suite



More information about the Checkins mailing list