163
class RabbitFixture(Fixture):
164
"""Common fixture stuff for dealing with RabbitMQ servers.
166
In particular this adopts detail handling code from `testtools` so that
167
details from sub-fixtures are propagated up to the test case.
170
def useFixture(self, fixture):
171
super(RabbitFixture, self).useFixture(fixture)
172
self.addCleanup(self._gather_details, fixture.getDetails)
175
def _gather_details(self, getDetails):
176
"""Merge the details from getDetails() into self.getDetails().
178
Shamelessly adapted from `testtools.TestCase._gather_details`.
180
details = getDetails()
181
my_details = self.getDetails()
182
for name, content_object in details.items():
184
disambiguator = itertools.count(1)
185
while new_name in my_details:
186
new_name = '%s-%d' % (name, next(disambiguator))
188
content_bytes = list(content_object.iter_bytes())
189
content_callback = lambda: content_bytes
191
Content(content_object.content_type, content_callback))
194
class RabbitServerResources(RabbitFixture):
162
class RabbitServerResources(Fixture):
195
163
"""Allocate the resources a RabbitMQ server needs.
197
165
:ivar hostname: The host the RabbitMQ is on (always localhost for
222
190
return "%s@%s" % (self.nodename, socket.gethostname())
225
class RabbitServerEnvironment(RabbitFixture):
193
class RabbitServerEnvironment(Fixture):
226
194
"""Export the environment variables needed to talk to a RabbitMQ instance.
228
196
When setup this exports the key RabbitMQ variables:
321
289
password="guest", virtual_host="/", insist=False)
324
class RabbitServerRunner(RabbitFixture):
292
class RabbitServerRunner(Fixture):
325
293
"""Run a RabbitMQ server.
327
295
:ivar pid: The pid of the server.
416
384
"RabbitMQ (pid=%d) did not quit." % (self.pid,))
419
class RabbitServer(RabbitFixture):
387
class RabbitServer(Fixture):
420
388
"""A RabbitMQ server fixture.
422
390
When setup a RabbitMQ instance will be running and the environment
430
398
super(RabbitServer, self).setUp()
431
self.config = self.useFixture(RabbitServerResources())
432
self.runner = self.useFixture(RabbitServerRunner(self.config))
399
self.config = RabbitServerResources()
400
self.useFixture(self.config)
401
self.runner = RabbitServerRunner(self.config)
402
self.useFixture(self.runner)