[Checkins] SVN: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ more tests

Christian Klinger cklinger at novareto.de
Wed Nov 18 08:11:02 EST 2009


Log message for revision 105819:
  more tests

Changed:
  U   Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt
  U   Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_hashedresource.py
  U   Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/utils.py

-=-
Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt	2009-11-18 10:37:47 UTC (rev 105818)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/README.txt	2009-11-18 13:11:02 UTC (rev 105819)
@@ -28,7 +28,7 @@
   ...     pass
 
   >>> root = getRootFolder()
-  >>> root['myapp'] = Application()
+  >>> root['myapp'] = myapp = Application()
 
 Our application has to be a Site to access the right url for the inclusions
 
@@ -37,6 +37,10 @@
   >>> root['myapp']
   <megrok.resource.ftests.Application object at ...>
 
+
+Inclusions & Library
+--------------------
+
 Let's start with a Library. A Library is in the context of megrok.resource
 a ResourceDirectory which holds a kind of different ResourceInclusions
 
@@ -44,11 +48,34 @@
   >>> import grokcore.view as view 
   >>> import grokcore.component as grok 
 
-  >>> class MyStylesA(Library):
+  >>> class MyStyles(Library):
   ...    view.path('css')
   ...    grok.name('mystyles')
   ...
   ...    inclusion(name='myjs', file='a.js')  
 
-  >>> grok.testing.grok_component('MyStylesA', MyStylesA)
+  >>> grok.testing.grok_component('MyStyles', MyStyles)
   True
+
+
+View & Include
+--------------
+
+To include a resource we need in the most cases a view.
+
+  >>> class MyView(view.View):
+  ...     grok.context(Application)
+  ...     view.template('templates/myview.pt')
+  ...     include(MyStyles, 'myjs')
+
+  >>> grok.testing.grok_component('MyView', MyView)
+  True
+
+
+  >>> from zope.component import getMultiAdapter
+  >>> from zope.publisher.browser import TestRequest
+
+  >>> myview = getMultiAdapter((myapp, TestRequest()), name=u'myview')
+  >>> myview
+  <megrok.resource.ftests.MyView object at ...>
+

Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_hashedresource.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_hashedresource.py	2009-11-18 10:37:47 UTC (rev 105818)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/ftests/test_hashedresource.py	2009-11-18 13:11:02 UTC (rev 105819)
@@ -18,53 +18,50 @@
 Inclusion with z3c.hashedresource
 ---------------------------------
 
+First we get the hash for the HashedStyle Library to compare it
+with the inclusion we get in the page.
+
+   >>> from zope.component import getAdapter
+   >>> from zope.publisher.browser import TestRequest
+   >>> library = getAdapter(TestRequest(), name='hashedstyles')
+   >>> library
+   <grokcore.view.components.DirectoryResource object at ...>
+
+   >>> from z3c.hashedresource.interfaces import IResourceContentsHash
+   >>> hash = IResourceContentsHash(library)
+   
+
 Here we proof if we get the resource "a.js" in the context
 of a hashedresource.
 
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
-  >>> browser.open('http://localhost/application/withhash')
+  >>> ajs = 'http://localhost/++noop++%s/@@/hashedstyles/a.js' % hash
+  >>> browser.open(ajs)
   >>> print browser.contents
-  <html>
-    <head>
-       <script type="text/javascript"
-       src="http://localhost/@@/hasedstyles/++noop++05d3614435a4164676867ad1f1320cd2/@@/hasedstyles/a.js"></script>
-   </head>
-    <body>
-       <h1> HI GROK </h1>
-    </body>
-  </html>  
+  /* Simple JS */
 """
 
-
 import grokcore.component as grok
 import grokcore.view as view
 
+from zope.app.container import btree
 from zope.interface import Interface
-from megrok.resource import Library, include, inclusion, hashed
 from hurry.resource import ResourceInclusion
-
-from zope.app.container import btree
-
 from zope.app.component.site import SiteManagerContainer
+from megrok.resource import Library, include, inclusion, hashed
 
-#class Application(btree.BTreeContainer):
+
 class Application(SiteManagerContainer):
     """ Sample Application """
 
 class HashedStyles(Library):
     view.path('css')
-    grok.name('hasedstyles')
+    grok.name('hashedstyles')
     hashed() 
     inclusion(name='JS', file='a.js')
 
 
-class WithHash(view.View):
-    grok.context(Interface)
-    include(HashedStyles, 'JS')
-    template = view.PageTemplateFile('templates/myview.pt')
-
-
 ###TestSetup
 def test_suite():
     from zope.testing import doctest

Modified: Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/utils.py
===================================================================
--- Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/utils.py	2009-11-18 10:37:47 UTC (rev 105818)
+++ Sandbox/cklinger/megrok.resource/trunk/src/megrok/resource/utils.py	2009-11-18 13:11:02 UTC (rev 105819)
@@ -11,7 +11,6 @@
 from zope.interface import Interface
 
 
-#@grok.adapter(Library)
 @grok.adapter(Interface)
 @grok.implementer(ILibraryUrl)
 def library_url(library):
@@ -26,11 +25,3 @@
         url = '%s/++noop++%s/@@/%s' % (url, hash, library.name)
 
     return url
-
-#@grok.adapter(Interface)
-#@grok.implementer(ILibraryUrl)
-#def library_url(library):
-#    request = getRequest()
-#    return str(component.getMultiAdapter((getSite(), request),
-#                                         IAbsoluteURL)) + '/@@/' + library.name
-        



More information about the checkins mailing list