Merge lp:~allenap/launchpad/add-rabbit-service-config-bug-803043 into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 13379
Proposed branch: lp:~allenap/launchpad/add-rabbit-service-config-bug-803043
Merge into: lp:launchpad
Prerequisite: lp:~allenap/launchpad/lp-app-longpoll
Diff against target: 163 lines (+55/-9)
4 files modified
lib/canonical/testing/layers.py (+3/-7)
lib/lp/testing/fixture.py (+22/-0)
lib/lp/testing/tests/test_fixture.py (+29/-1)
versions.cfg (+1/-1)
To merge this branch: bzr merge lp:~allenap/launchpad/add-rabbit-service-config-bug-803043
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+66930@code.launchpad.net

Commit message

[r=allenap][bug=803043] Move the Launchpad-specific parts of the RabbitServer fixture back from rabbitfixture into Launchpad.

Description of the change

Adds a RabbitServer subclass to the Launchpad tree, based on rabbitfixture's. It creates a service_config object in the same place as rabbitfixture did before version 0.2.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/testing/layers.py'
2--- lib/canonical/testing/layers.py 2011-07-04 03:10:41 +0000
3+++ lib/canonical/testing/layers.py 2011-07-05 16:44:58 +0000
4@@ -61,7 +61,6 @@
5 import socket
6 import subprocess
7 import sys
8-import tempfile
9 from textwrap import dedent
10 import threading
11 import time
12@@ -75,9 +74,7 @@
13 Fixture,
14 MonkeyPatch,
15 )
16-from lazr.restful.utils import safe_hasattr
17 import psycopg2
18-from rabbitfixture.server import RabbitServer
19 from storm.zope.interfaces import IZStorm
20 import transaction
21 import wsgi_intercept
22@@ -98,7 +95,6 @@
23 from zope.security.management import getSecurityPolicy
24 from zope.security.simplepolicies import PermissiveSecurityPolicy
25 from zope.server.logger.pythonlogger import PythonLogger
26-from zope.testing.testrunner.runner import FakeInputContinueGenerator
27
28 from canonical.config import (
29 CanonicalConfig,
30@@ -131,7 +127,6 @@
31 register_launchpad_request_publication_factories,
32 )
33 import canonical.launchpad.webapp.session
34-from canonical.launchpad.webapp.vhosts import allvhosts
35 from canonical.lazr import pidfile
36 from canonical.lazr.testing.layers import MockRootFolder
37 from canonical.lazr.timeout import (
38@@ -156,6 +151,7 @@
39 login,
40 logout,
41 )
42+from lp.testing.fixture import RabbitServer
43 from lp.testing.pgsql import PgTestSetup
44
45
46@@ -733,8 +729,8 @@
47 if os.environ.get('LP_TEST_INSTANCE'):
48 template_name = '_'.join([LaunchpadTestSetup.template,
49 os.environ.get('LP_TEST_INSTANCE')])
50- cls._db_template_fixture = LaunchpadTestSetup(dbname=template_name,
51- reset_sequences_sql=reset_sequences_sql)
52+ cls._db_template_fixture = LaunchpadTestSetup(
53+ dbname=template_name, reset_sequences_sql=reset_sequences_sql)
54 cls._db_template_fixture.setUp()
55 else:
56 template_name = LaunchpadTestSetup.template
57
58=== modified file 'lib/lp/testing/fixture.py'
59--- lib/lp/testing/fixture.py 2011-07-05 16:44:57 +0000
60+++ lib/lp/testing/fixture.py 2011-07-05 16:44:58 +0000
61@@ -5,12 +5,16 @@
62
63 __metaclass__ = type
64 __all__ = [
65+ 'RabbitServer',
66 'ZopeAdapterFixture',
67 'ZopeEventHandlerFixture',
68 'ZopeViewReplacementFixture',
69 ]
70
71+from textwrap import dedent
72+
73 from fixtures import Fixture
74+import rabbitfixture.server
75 from zope.component import (
76 getGlobalSiteManager,
77 provideHandler,
78@@ -24,6 +28,24 @@
79 )
80
81
82+class RabbitServer(rabbitfixture.server.RabbitServer):
83+ """A RabbitMQ server fixture with Launchpad-specific config.
84+
85+ :ivar service_config: A snippet of .ini that describes the `rabbitmq`
86+ configuration.
87+ """
88+
89+ def setUp(self):
90+ super(RabbitServer, self).setUp()
91+ self.config.service_config = dedent("""\
92+ [rabbitmq]
93+ host: localhost:%d
94+ userid: guest
95+ password: guest
96+ virtual_host: /
97+ """ % self.config.port)
98+
99+
100 class ZopeAdapterFixture(Fixture):
101 """A fixture to register and unregister an adapter."""
102
103
104=== modified file 'lib/lp/testing/tests/test_fixture.py'
105--- lib/lp/testing/tests/test_fixture.py 2011-07-05 16:44:57 +0000
106+++ lib/lp/testing/tests/test_fixture.py 2011-07-05 16:44:58 +0000
107@@ -5,6 +5,9 @@
108
109 __metaclass__ = type
110
111+from textwrap import dedent
112+
113+from fixtures import EnvironmentVariableFixture
114 from zope.component import (
115 adapts,
116 queryAdapter,
117@@ -16,7 +19,32 @@
118
119 from canonical.testing.layers import BaseLayer
120 from lp.testing import TestCase
121-from lp.testing.fixture import ZopeAdapterFixture
122+from lp.testing.fixture import (
123+ RabbitServer,
124+ ZopeAdapterFixture,
125+ )
126+
127+
128+class TestRabbitServer(TestCase):
129+
130+ layer = BaseLayer
131+
132+ def test_service_config(self):
133+ # Rabbit needs to fully isolate itself: an existing per user
134+ # .erlange.cookie has to be ignored, and ditto bogus HOME if other
135+ # tests fail to cleanup.
136+ self.useFixture(EnvironmentVariableFixture('HOME', '/nonsense/value'))
137+
138+ # RabbitServer pokes some .ini configuration into its config.
139+ with RabbitServer() as fixture:
140+ expected = dedent("""\
141+ [rabbitmq]
142+ host: localhost:%d
143+ userid: guest
144+ password: guest
145+ virtual_host: /
146+ """ % fixture.config.port)
147+ self.assertEqual(expected, fixture.config.service_config)
148
149
150 class IFoo(Interface):
151
152=== modified file 'versions.cfg'
153--- versions.cfg 2011-07-04 10:48:28 +0000
154+++ versions.cfg 2011-07-05 16:44:58 +0000
155@@ -65,7 +65,7 @@
156 pytz = 2010o
157 rdflib = 3.1.0
158 RestrictedPython = 3.5.1
159-rabbitfixture = 0.1
160+rabbitfixture = 0.2.1
161 roman = 1.4.0
162 # See http://code.google.com/p/selenium/issues/detail?id=1935 .
163 selenium = 2.0rc3-lp-distribute-fix