← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~mwhudson/launchpad/vostok-add-root into lp:launchpad/devel

 

Michael Hudson has proposed merging lp:~mwhudson/launchpad/vostok-add-root into lp:launchpad/devel with lp:~mwhudson/launchpad/vostok-add-layer as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


Hi,

This branch adds a custom root object for the vostok vhost.  This makes us more
separate from the other Launchpad publication stuff, which given the goal of
vostok is a good thing (tm).

Cheers,
mwh
-- 
https://code.launchpad.net/~mwhudson/launchpad/vostok-add-root/+merge/31239
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~mwhudson/launchpad/vostok-add-root into lp:launchpad/devel.
=== added directory 'lib/lp/vostok/browser'
=== added file 'lib/lp/vostok/browser/__init__.py'
--- lib/lp/vostok/browser/__init__.py	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/__init__.py	2010-07-29 05:11:14 +0000
@@ -0,0 +1,4 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Browser code for the Linaro archive management skin."""

=== added file 'lib/lp/vostok/browser/configure.zcml'
--- lib/lp/vostok/browser/configure.zcml	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/configure.zcml	2010-07-29 05:11:14 +0000
@@ -0,0 +1,22 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope";
+   xmlns:browser="http://namespaces.zope.org/browser";
+   xmlns:i18n="http://namespaces.zope.org/i18n";
+   xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc";
+   i18n_domain="launchpad">
+
+  <browser:defaultView
+     for="lp.vostok.publisher.IVostokRoot"
+     name="+index"
+     />
+
+  <browser:page
+     for="lp.vostok.publisher.IVostokRoot"
+     name="+index"
+     class="lp.vostok.browser.root.VostokRootView"
+     template="../templates/root.pt"
+     permission="zope.Public"
+     layer="lp.vostok.publisher.VostokLayer"
+     />
+
+</configure>

=== added file 'lib/lp/vostok/browser/root.py'
--- lib/lp/vostok/browser/root.py	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/root.py	2010-07-29 05:11:14 +0000
@@ -0,0 +1,15 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Browser code for the Vostok root."""
+
+__metaclass__ = type
+__all__ = [
+    'VostokRootView',
+    ]
+
+from canonical.launchpad.webapp import LaunchpadView
+
+
+class VostokRootView(LaunchpadView):
+    pass

=== added directory 'lib/lp/vostok/browser/tests'
=== added file 'lib/lp/vostok/browser/tests/__init__.py'
--- lib/lp/vostok/browser/tests/__init__.py	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/tests/__init__.py	2010-07-29 05:11:14 +0000
@@ -0,0 +1,4 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the browser code of the Linaro archive management skin."""

=== added file 'lib/lp/vostok/browser/tests/request.py'
--- lib/lp/vostok/browser/tests/request.py	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/tests/request.py	2010-07-29 05:11:14 +0000
@@ -0,0 +1,19 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""A VostokLayer request class for use in tests."""
+
+__metaclass__ = type
+__all__ = [
+    'VostokTestRequest',
+    ]
+
+from zope.interface import implements
+
+from canonical.launchpad.webapp.servers import LaunchpadTestRequest
+
+from lp.vostok.publisher import VostokLayer
+
+
+class VostokTestRequest(LaunchpadTestRequest):
+    implements(VostokLayer)

=== added file 'lib/lp/vostok/browser/tests/test_root.py'
--- lib/lp/vostok/browser/tests/test_root.py	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/browser/tests/test_root.py	2010-07-29 05:11:14 +0000
@@ -0,0 +1,38 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for browsing the root of the vostok skin."""
+
+__metaclass__ = type
+
+import unittest
+
+from zope.app.publisher.browser import getDefaultViewName
+from zope.component import getMultiAdapter
+
+from canonical.testing.layers import FunctionalLayer
+
+from lp.testing import TestCase
+from lp.vostok.browser.root import VostokRootView
+from lp.vostok.browser.tests.request import VostokTestRequest
+from lp.vostok.publisher import VostokRoot
+
+class TestBrowseRoot(TestCase):
+
+    layer = FunctionalLayer
+
+    def test_root_default_view_name(self):
+        # The default view for the vostok root object is called "+index".
+        view_name = getDefaultViewName(VostokRoot(), VostokTestRequest())
+        self.assertEquals('+index', view_name)
+
+    def test_root_index_view(self):
+        # VostokRootView is registered as the view for the VostokRoot object.
+        view = getMultiAdapter(
+            (VostokRoot(), VostokTestRequest()), name='+index')
+        view.initialize()
+        self.assertIsInstance(view, VostokRootView)
+
+
+def test_suite():
+    return unittest.TestLoader().loadTestsFromName(__name__)

=== modified file 'lib/lp/vostok/configure.zcml'
--- lib/lp/vostok/configure.zcml	2010-07-29 05:11:12 +0000
+++ lib/lp/vostok/configure.zcml	2010-07-29 05:11:14 +0000
@@ -5,10 +5,17 @@
    xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc";
    i18n_domain="launchpad">
 
+  <include package=".browser" />
+
   <publisher
      name="vostok"
      factory="lp.vostok.publisher.vostok_request_publication_factory"
      methods="*"
      mimetypes="*" />
 
+  <securedutility
+     class="lp.vostok.publisher.VostokRoot"
+     provides="lp.vostok.publisher.IVostokRoot">
+    <allow interface="lp.vostok.publisher.IVostokRoot" />
+  </securedutility>
 </configure>

=== modified file 'lib/lp/vostok/publisher.py'
--- lib/lp/vostok/publisher.py	2010-07-29 05:11:12 +0000
+++ lib/lp/vostok/publisher.py	2010-07-29 05:11:14 +0000
@@ -11,7 +11,7 @@
     ]
 
 
-from zope.interface import implements
+from zope.interface import implements, Interface
 from zope.publisher.interfaces.browser import (
     IBrowserRequest, IDefaultBrowserLayer)
 
@@ -28,10 +28,18 @@
     implements(VostokLayer)
 
 
-# We *might* end up customizing the root object and so need our own
-# LaunchpadBrowserPublication subclass.  Not yet though.
+class IVostokRoot(Interface): # might need to inherit from some IRoot thing
+    """Marker interface for the root vostok object."""
+
+
+class VostokRoot:
+    implements(IVostokRoot)
+
+
+class VostokBrowserPublication(LaunchpadBrowserPublication):
+    root_object_interface = IVostokRoot
 
 
 def vostok_request_publication_factory():
     return VirtualHostRequestPublicationFactory(
-        'vostok', VostokBrowserRequest, LaunchpadBrowserPublication)
+        'vostok', VostokBrowserRequest, VostokBrowserPublication)

=== added directory 'lib/lp/vostok/templates'
=== added file 'lib/lp/vostok/templates/root.pt'
--- lib/lp/vostok/templates/root.pt	1970-01-01 00:00:00 +0000
+++ lib/lp/vostok/templates/root.pt	2010-07-29 05:11:14 +0000
@@ -0,0 +1,3 @@
+<big>
+THIS IS VOSTOK
+</big>

=== modified file 'lib/lp/vostok/tests/test_publisher.py'
--- lib/lp/vostok/tests/test_publisher.py	2010-07-29 05:11:12 +0000
+++ lib/lp/vostok/tests/test_publisher.py	2010-07-29 05:11:14 +0000
@@ -9,11 +9,14 @@
 
 from canonical.config import config
 from canonical.testing.layers import FunctionalLayer
+from canonical.launchpad.webapp.interfaces import IOpenLaunchBag
 
 from lp.testing import TestCase
 from lp.testing.publication import get_request_and_publication
 
-from lp.vostok.publisher import VostokLayer
+from lp.vostok.publisher import VostokLayer, VostokRoot
+
+from zope.component import getUtility
 
 
 class TestRegistration(TestCase):
@@ -28,6 +31,17 @@
             host=config.vhost.vostok.hostname)
         self.assertProvides(request, VostokLayer)
 
+    def test_root_object(self):
+        # The root object for requests to the vostok host is an instance of
+        # VostokRoot.
+        request, publication = get_request_and_publication(
+            host=config.vhost.vostok.hostname)
+        self.assertProvides(request, VostokLayer)
+        # XXX This shouldn't be needed:
+        getUtility(IOpenLaunchBag).clear()
+        root = publication.getApplication(request)
+        self.assertIsInstance(root, VostokRoot)
+
 
 def test_suite():
     return unittest.TestLoader().loadTestsFromName(__name__)