[Checkins] SVN: megrok.feeds/trunk/ After much pain, wrote a unit test that prints out an atom feed, using

Brandon Rhodes brandon at rhodesmill.org
Sat Jul 19 15:46:51 EDT 2008


Log message for revision 88612:
  After much pain, wrote a unit test that prints out an atom feed, using
  entirely components defined in the test itself.  Will now factor things
  out of the test, but first am checking this in lest I never again am
  able to get back to a working state!
  

Changed:
  U   megrok.feeds/trunk/buildout.cfg
  A   megrok.feeds/trunk/src/megrok/feeds/configure.zcml
  U   megrok.feeds/trunk/src/megrok/feeds/ftesting.zcml
  U   megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py

-=-
Modified: megrok.feeds/trunk/buildout.cfg
===================================================================
--- megrok.feeds/trunk/buildout.cfg	2008-07-19 17:47:26 UTC (rev 88611)
+++ megrok.feeds/trunk/buildout.cfg	2008-07-19 19:46:47 UTC (rev 88612)
@@ -4,6 +4,8 @@
 find-links = http://download.zope.org/distribution/
 extends = http://grok.zope.org/releaseinfo/grok-0.13.cfg
 versions = versions
+# temporary, until Rope is fixed or I figure out how to wrangle it
+eggs-directory = eggs
 
 [test]
 recipe = zc.recipe.testrunner

Added: megrok.feeds/trunk/src/megrok/feeds/configure.zcml
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/configure.zcml	                        (rev 0)
+++ megrok.feeds/trunk/src/megrok/feeds/configure.zcml	2008-07-19 19:46:47 UTC (rev 88612)
@@ -0,0 +1,6 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    xmlns:grok="http://namespaces.zope.org/grok">
+
+</configure>

Modified: megrok.feeds/trunk/src/megrok/feeds/ftesting.zcml
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/ftesting.zcml	2008-07-19 17:47:26 UTC (rev 88611)
+++ megrok.feeds/trunk/src/megrok/feeds/ftesting.zcml	2008-07-19 19:46:47 UTC (rev 88612)
@@ -6,6 +6,7 @@
    >
 
   <include package="grok" />
+  <include package="megrok.feeds" />
   <grok:grok package="megrok.feeds.ftests" />
 
   <securityPolicy

Modified: megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py
===================================================================
--- megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py	2008-07-19 17:47:26 UTC (rev 88611)
+++ megrok.feeds/trunk/src/megrok/feeds/ftests/atom/atom.py	2008-07-19 19:46:47 UTC (rev 88612)
@@ -1,37 +1,128 @@
 """
 A grok.AtomFeed syndicates sub-objects into an Atom feed.
 
-  >>> c = grok.MammothBox()
-  >>> getRootFolder()["c"] = c
+  >>> box = MammothBox()
+  >>> getRootFolder()["box"] = box
 
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
-  >>> browser.open("http://localhost/c/@@atom")
+  >>> browser.open("http://localhost/box/@@atom")
   >>> print browser.contents
-  <html>...
-  ...Manfred the Mammoth...
-  ...Really big...
-  ...
-
+  <?xml version="1.0" encoding="utf-8" ?>
+  <?xml-stylesheet href="atom.css" type="text/css"?>
+  <feed xmlns="http://www.w3.org/2005/Atom"
+        xmlns:dc="http://purl.org/dc/elements/1.1/"
+        xml:base="" xml:lang="en">
+    <title type="html">This is the title</title>
+    <subtitle>A box full of mammoths.</subtitle>
+  <BLANKLINE>
+    <updated>2008-07...</updated>
+  <BLANKLINE>
+    <link rel="alternate" type="text/html"/>
+  <BLANKLINE>
+    <link rel="self" type="application/atom+xml"
+          href="CANNA KNOW THIS, CAPTN!"/>
+  <!-- XXX TODO: Use this, it's better!
+          tal:attributes="href string:${view/absolute_url}" -->
+  <BLANKLINE>
+  <BLANKLINE>
+  <BLANKLINE>
+    <id>urn:syndication:xyzzy</id>
+  <BLANKLINE>
+  <BLANKLINE>
+  <BLANKLINE>
+  <BLANKLINE>
+  </feed>
+  <BLANKLINE>
+  
 """
 import grok
 from zope import schema
 from zope.interface import Interface, implements
 from zope.schema.fieldproperty import FieldProperty
 
+#
+
+#from megrok.feeds
+from vice.outbound.core.browser.feed import Atom_1_0_FeedView
+from vice.outbound.core.interfaces import IFeed, IFeedItem
+
+from zope.interface import Interface
+class IFeedable(Interface):
+    pass # marker interface
+
+# need three things:
+# (1) we need to create an adapter from MammothBox to IFeed
+# (2) we need to mark MammothBox as IFeedable
+# (3) we need to create a View that makes an IFeedable render
+
+#
+
 class IMammoth(Interface):
     name = schema.TextLine(title=u"Name")
     size = schema.TextLine(title=u"Size", default=u"Quite normal")
 
-class MammothBox(grok.OrderedContainer):
-    pass
+class MammothBox(object): #grok.Container): #grok.Application, #grok.Container
+    implements(IFeedable) #(2)
+    def __init__(self):
+        import zope.component
+        provideAdapter(AtomFormat,
+                       #adapts=(IFeedable, IHTTPRequest),
+                       (IFeedable, IHTTPRequest),#IDefaultBrowserLayer),
+                       #provides=Interface,
+                       provides=IBrowserView,
+                       name=u'atom')
+        #print "########################", \
+        #    zope.component.getAdapters()
 
+from datetime import datetime
+
+class MammothBoxFeed(grok.Adapter): #(1)
+    grok.context(MammothBox)
+    grok.provides(IFeed)
+    def __init__(self, context):
+        self.context = context
+        self.description = 'A box full of mammoths.'
+        self.modified = datetime.now()
+        self.name = 'This Mammoth Box'
+        self.title = 'This is the title'
+        self.UID = 'xyzzy'
+        self.alternate_url = 'ALT'
+
+    @property
+    def context_url(self):
+        return grok.url(context)
+
+    @property
+    def self_url(self):
+        return 'CANNA KNOW THIS, CAPTN!'
+
+    def __iter__(self):
+        while False:
+            yield None
+
+class AtomFormat(Atom_1_0_FeedView): #, grok.View):
+    grok.context(MammothBox)
+    #@grok.require('zope.View')
+    #def __call__(self, *args, **kw):
+    #    super(self, AtomFormat).__call__(self, *args, **kw)
+
+from zope.component import provideAdapter
+from zope.publisher.interfaces.browser import IBrowserPage, IBrowserView
+from zope.publisher.interfaces.http import IHTTPRequest
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+
 class Mammoth(grok.Model):
     implements(IMammoth)
     
     name = FieldProperty(IMammoth['name'])    
     size = FieldProperty(IMammoth['size'])    
 
-class Atom(grok.AtomFeed):
-    grok.context(MammothBox)
+class MammothItem(grok.Adapter): #(3)
+    grok.context(Mammoth)
+    grok.implements(IFeedItem)
+    def __init__(self, context):
+        self.context = context
+        self.title = 'Mammoth %s' % self.name
+        # DUH, don't need this yet, will finish later



More information about the Checkins mailing list