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

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 11299
Proposed branch: lp:~mwhudson/launchpad/vostok-add-root
Merge into: lp:launchpad
Prerequisite: lp:~mwhudson/launchpad/vostok-add-layer
Diff against target: 238 lines (+140/-5)
10 files modified
lib/lp/vostok/browser/__init__.py (+4/-0)
lib/lp/vostok/browser/configure.zcml (+22/-0)
lib/lp/vostok/browser/root.py (+15/-0)
lib/lp/vostok/browser/tests/__init__.py (+4/-0)
lib/lp/vostok/browser/tests/request.py (+19/-0)
lib/lp/vostok/browser/tests/test_root.py (+38/-0)
lib/lp/vostok/configure.zcml (+7/-0)
lib/lp/vostok/publisher.py (+12/-4)
lib/lp/vostok/templates/root.pt (+3/-0)
lib/lp/vostok/tests/test_publisher.py (+16/-1)
To merge this branch: bzr merge lp:~mwhudson/launchpad/vostok-add-root
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+31239@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

> class VostokRootView(LaunchpadView):
> pass

Shouldn't you at least have

    __used_for__ = IVostokRoot

Instead of:
    view = getMultiAdapter(
       (VostokRoot(), VostokTestRequest()), name='+index')
    view.initialize()

Can you alter the get_initialized_view function?

> class IVostokRoot(Interface): # might need to inherit from some IRoot thing

You can probably lose the comment.

Also... the root.pt needs some work :-)

Why is the
  getUtility(IOpenLaunchBag).clear()
needed in test_root_object?

review: Needs Information
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

On Thu, 29 Jul 2010 23:27:43 -0000, Tim Penhey <email address hidden> wrote:
> Review: Needs Information
> > class VostokRootView(LaunchpadView):
> > pass
>
> Shouldn't you at least have
>
> __used_for__ = IVostokRoot

After a bit of googling, apparently not. Maybe I should sed out all the
existing __used_for__s in our code base :-)

> Instead of:
> view = getMultiAdapter(
> (VostokRoot(), VostokTestRequest()), name='+index')
> view.initialize()
>
> Can you alter the get_initialized_view function?

Apparently yes, once I was told that it's actually called
create_initialized_view :-)

> > class IVostokRoot(Interface): # might need to inherit from some IRoot thing
>
> You can probably lose the comment.

Yeah, thanks.

> Also... the root.pt needs some work :-)

That's in the next pipe :-)

> Why is the
> getUtility(IOpenLaunchBag).clear()
> needed in test_root_object?

Errr... because the test blows up if its not there. Specifically, the
root object seems to be cached on the launchbag, and if the launchpad
isn't set up, it blows up.

I don't know if this is still used at all, quite possibly not, but that
seems a job for another branch.

I've expanded the comment.

Cheers,
mwh

=== modified file 'lib/lp/vostok/browser/root.py'
--- lib/lp/vostok/browser/root.py 2010-07-15 07:49:25 +0000
+++ lib/lp/vostok/browser/root.py 2010-07-29 23:45:26 +0000
@@ -12,4 +12,4 @@
1212
1313
14class VostokRootView(LaunchpadView):14class VostokRootView(LaunchpadView):
15 pass15 """The view for the Vostok root object."""
1616
=== modified file 'lib/lp/vostok/browser/tests/test_root.py'
--- lib/lp/vostok/browser/tests/test_root.py 2010-07-29 04:30:04 +0000
+++ lib/lp/vostok/browser/tests/test_root.py 2010-07-29 23:51:17 +0000
@@ -8,14 +8,15 @@
8import unittest8import unittest
99
10from zope.app.publisher.browser import getDefaultViewName10from zope.app.publisher.browser import getDefaultViewName
11from zope.component import getMultiAdapter
1211
13from canonical.testing.layers import FunctionalLayer12from canonical.testing.layers import FunctionalLayer
1413
15from lp.testing import TestCase14from lp.testing import TestCase
15from lp.testing.views import create_initialized_view
16from lp.vostok.browser.root import VostokRootView16from lp.vostok.browser.root import VostokRootView
17from lp.vostok.browser.tests.request import VostokTestRequest17from lp.vostok.browser.tests.request import VostokTestRequest
18from lp.vostok.publisher import VostokRoot18from lp.vostok.publisher import VostokLayer, VostokRoot
19
1920
20class TestBrowseRoot(TestCase):21class TestBrowseRoot(TestCase):
2122
@@ -28,9 +29,8 @@
2829
29 def test_root_index_view(self):30 def test_root_index_view(self):
30 # VostokRootView is registered as the view for the VostokRoot object.31 # VostokRootView is registered as the view for the VostokRoot object.
31 view = getMultiAdapter(32 view = create_initialized_view(
32 (VostokRoot(), VostokTestRequest()), name='+index')33 VostokRoot(), name='+index', layer=VostokLayer)
33 view.initialize()
34 self.assertIsInstance(view, VostokRootView)34 self.assertIsInstance(view, VostokRootView)
3535
3636
3737
=== modified file 'lib/lp/vostok/publisher.py'
--- lib/lp/vostok/publisher.py 2010-07-14 14:27:27 +0000
+++ lib/lp/vostok/publisher.py 2010-07-29 23:39:07 +0000
@@ -28,7 +28,7 @@
28 implements(VostokLayer)28 implements(VostokLayer)
2929
3030
31class IVostokRoot(Interface): # might need to inherit from some IRoot thing31class IVostokRoot(Interface):
32 """Marker interface for the root vostok object."""32 """Marker interface for the root vostok object."""
3333
3434
3535
=== modified file 'lib/lp/vostok/tests/test_publisher.py'
--- lib/lp/vostok/tests/test_publisher.py 2010-07-29 04:28:08 +0000
+++ lib/lp/vostok/tests/test_publisher.py 2010-07-30 00:01:34 +0000
@@ -37,7 +37,8 @@
37 request, publication = get_request_and_publication(37 request, publication = get_request_and_publication(
38 host=config.vhost.vostok.hostname)38 host=config.vhost.vostok.hostname)
39 self.assertProvides(request, VostokLayer)39 self.assertProvides(request, VostokLayer)
40 # XXX This shouldn't be needed:40 # XXX getApplication caches the root object in the LaunchBag, so we
41 # need to set it up, or it crashes.
41 getUtility(IOpenLaunchBag).clear()42 getUtility(IOpenLaunchBag).clear()
42 root = publication.getApplication(request)43 root = publication.getApplication(request)
43 self.assertIsInstance(root, VostokRoot)44 self.assertIsInstance(root, VostokRoot)
Revision history for this message
Tim Penhey (thumper) wrote :

The XXX comment should have name, date and bug as well.

Other than that, this is good to go now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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-30 00:06:10 +0000
@@ -0,0 +1,4 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Browser code for the Linaro archive management skin."""
05
=== 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-30 00:06:10 +0000
@@ -0,0 +1,22 @@
1<configure
2 xmlns="http://namespaces.zope.org/zope"
3 xmlns:browser="http://namespaces.zope.org/browser"
4 xmlns:i18n="http://namespaces.zope.org/i18n"
5 xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
6 i18n_domain="launchpad">
7
8 <browser:defaultView
9 for="lp.vostok.publisher.IVostokRoot"
10 name="+index"
11 />
12
13 <browser:page
14 for="lp.vostok.publisher.IVostokRoot"
15 name="+index"
16 class="lp.vostok.browser.root.VostokRootView"
17 template="../templates/root.pt"
18 permission="zope.Public"
19 layer="lp.vostok.publisher.VostokLayer"
20 />
21
22</configure>
023
=== 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-30 00:06:10 +0000
@@ -0,0 +1,15 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Browser code for the Vostok root."""
5
6__metaclass__ = type
7__all__ = [
8 'VostokRootView',
9 ]
10
11from canonical.launchpad.webapp import LaunchpadView
12
13
14class VostokRootView(LaunchpadView):
15 """The view for the Vostok root object."""
016
=== 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-30 00:06:10 +0000
@@ -0,0 +1,4 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for the browser code of the Linaro archive management skin."""
05
=== 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-30 00:06:10 +0000
@@ -0,0 +1,19 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""A VostokLayer request class for use in tests."""
5
6__metaclass__ = type
7__all__ = [
8 'VostokTestRequest',
9 ]
10
11from zope.interface import implements
12
13from canonical.launchpad.webapp.servers import LaunchpadTestRequest
14
15from lp.vostok.publisher import VostokLayer
16
17
18class VostokTestRequest(LaunchpadTestRequest):
19 implements(VostokLayer)
020
=== 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-30 00:06:10 +0000
@@ -0,0 +1,38 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for browsing the root of the vostok skin."""
5
6__metaclass__ = type
7
8import unittest
9
10from zope.app.publisher.browser import getDefaultViewName
11
12from canonical.testing.layers import FunctionalLayer
13
14from lp.testing import TestCase
15from lp.testing.views import create_initialized_view
16from lp.vostok.browser.root import VostokRootView
17from lp.vostok.browser.tests.request import VostokTestRequest
18from lp.vostok.publisher import VostokLayer, VostokRoot
19
20
21class TestBrowseRoot(TestCase):
22
23 layer = FunctionalLayer
24
25 def test_root_default_view_name(self):
26 # The default view for the vostok root object is called "+index".
27 view_name = getDefaultViewName(VostokRoot(), VostokTestRequest())
28 self.assertEquals('+index', view_name)
29
30 def test_root_index_view(self):
31 # VostokRootView is registered as the view for the VostokRoot object.
32 view = create_initialized_view(
33 VostokRoot(), name='+index', layer=VostokLayer)
34 self.assertIsInstance(view, VostokRootView)
35
36
37def test_suite():
38 return unittest.TestLoader().loadTestsFromName(__name__)
039
=== modified file 'lib/lp/vostok/configure.zcml'
--- lib/lp/vostok/configure.zcml 2010-07-30 00:06:05 +0000
+++ lib/lp/vostok/configure.zcml 2010-07-30 00:06:10 +0000
@@ -5,10 +5,17 @@
5 xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"5 xmlns:xmlrpc="http://namespaces.zope.org/xmlrpc"
6 i18n_domain="launchpad">6 i18n_domain="launchpad">
77
8 <include package=".browser" />
9
8 <publisher10 <publisher
9 name="vostok"11 name="vostok"
10 factory="lp.vostok.publisher.vostok_request_publication_factory"12 factory="lp.vostok.publisher.vostok_request_publication_factory"
11 methods="*"13 methods="*"
12 mimetypes="*" />14 mimetypes="*" />
1315
16 <securedutility
17 class="lp.vostok.publisher.VostokRoot"
18 provides="lp.vostok.publisher.IVostokRoot">
19 <allow interface="lp.vostok.publisher.IVostokRoot" />
20 </securedutility>
14</configure>21</configure>
1522
=== modified file 'lib/lp/vostok/publisher.py'
--- lib/lp/vostok/publisher.py 2010-07-30 00:06:05 +0000
+++ lib/lp/vostok/publisher.py 2010-07-30 00:06:10 +0000
@@ -11,7 +11,7 @@
11 ]11 ]
1212
1313
14from zope.interface import implements14from zope.interface import implements, Interface
15from zope.publisher.interfaces.browser import (15from zope.publisher.interfaces.browser import (
16 IBrowserRequest, IDefaultBrowserLayer)16 IBrowserRequest, IDefaultBrowserLayer)
1717
@@ -28,10 +28,18 @@
28 implements(VostokLayer)28 implements(VostokLayer)
2929
3030
31# We *might* end up customizing the root object and so need our own31class IVostokRoot(Interface):
32# LaunchpadBrowserPublication subclass. Not yet though.32 """Marker interface for the root vostok object."""
33
34
35class VostokRoot:
36 implements(IVostokRoot)
37
38
39class VostokBrowserPublication(LaunchpadBrowserPublication):
40 root_object_interface = IVostokRoot
3341
3442
35def vostok_request_publication_factory():43def vostok_request_publication_factory():
36 return VirtualHostRequestPublicationFactory(44 return VirtualHostRequestPublicationFactory(
37 'vostok', VostokBrowserRequest, LaunchpadBrowserPublication)45 'vostok', VostokBrowserRequest, VostokBrowserPublication)
3846
=== 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-30 00:06:10 +0000
@@ -0,0 +1,3 @@
1<big>
2THIS IS VOSTOK
3</big>
04
=== modified file 'lib/lp/vostok/tests/test_publisher.py'
--- lib/lp/vostok/tests/test_publisher.py 2010-07-30 00:06:05 +0000
+++ lib/lp/vostok/tests/test_publisher.py 2010-07-30 00:06:10 +0000
@@ -9,11 +9,14 @@
99
10from canonical.config import config10from canonical.config import config
11from canonical.testing.layers import FunctionalLayer11from canonical.testing.layers import FunctionalLayer
12from canonical.launchpad.webapp.interfaces import IOpenLaunchBag
1213
13from lp.testing import TestCase14from lp.testing import TestCase
14from lp.testing.publication import get_request_and_publication15from lp.testing.publication import get_request_and_publication
1516
16from lp.vostok.publisher import VostokLayer17from lp.vostok.publisher import VostokLayer, VostokRoot
18
19from zope.component import getUtility
1720
1821
19class TestRegistration(TestCase):22class TestRegistration(TestCase):
@@ -28,6 +31,18 @@
28 host=config.vhost.vostok.hostname)31 host=config.vhost.vostok.hostname)
29 self.assertProvides(request, VostokLayer)32 self.assertProvides(request, VostokLayer)
3033
34 def test_root_object(self):
35 # The root object for requests to the vostok host is an instance of
36 # VostokRoot.
37 request, publication = get_request_and_publication(
38 host=config.vhost.vostok.hostname)
39 self.assertProvides(request, VostokLayer)
40 # XXX getApplication caches the root object in the LaunchBag, so we
41 # need to set it up, or it crashes.
42 getUtility(IOpenLaunchBag).clear()
43 root = publication.getApplication(request)
44 self.assertIsInstance(root, VostokRoot)
45
3146
32def test_suite():47def test_suite():
33 return unittest.TestLoader().loadTestsFromName(__name__)48 return unittest.TestLoader().loadTestsFromName(__name__)