~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maastesting/rabbit.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
__metaclass__ = type
13
13
__all__ = [
14
14
    "get_rabbit",
15
 
    "RabbitServerSettings",
16
15
    "start_rabbit",
17
16
    "stop_rabbit",
18
 
    "use_rabbit_fixture",
19
 
    "uses_rabbit_fixture",
20
17
    ]
21
18
 
22
 
from functools import wraps
23
 
 
24
 
from fixtures import Fixture
25
19
from rabbitfixture.server import RabbitServer
26
 
from testtools.monkey import MonkeyPatcher
27
 
 
28
 
 
29
 
class RabbitServerSettings(Fixture):
30
 
    """
31
 
    This patches the active Django settings to point the application at the
32
 
    ephemeral RabbitMQ server specified by the given configuration.
33
 
    """
34
 
 
35
 
    def __init__(self, config):
36
 
        super(RabbitServerSettings, self).__init__()
37
 
        self.config = config
38
 
 
39
 
    def setUp(self):
40
 
        super(RabbitServerSettings, self).setUp()
41
 
        from django.conf import settings
42
 
        patcher = MonkeyPatcher()
43
 
        patcher.add_patch(
44
 
            settings, "RABBITMQ_HOST",
45
 
            "%s:%d" % (self.config.hostname, self.config.port))
46
 
        patcher.add_patch(settings, "RABBITMQ_USERID", "guest")
47
 
        patcher.add_patch(settings, "RABBITMQ_PASSWORD", "guest")
48
 
        patcher.add_patch(settings, "RABBITMQ_VIRTUAL_HOST", "/")
49
 
        patcher.add_patch(settings, "RABBITMQ_PUBLISH", True)
50
 
        self.addCleanup(patcher.restore)
51
 
        patcher.patch()
52
 
 
53
20
 
54
21
# See {start,stop,get}_rabbit().
55
22
rabbit = None
76
43
    global rabbit
77
44
    start_rabbit()
78
45
    return rabbit
79
 
 
80
 
 
81
 
def use_rabbit_fixture(test):
82
 
    """Ensure that a :class:`RabbitServer` is started, and Django's setting
83
 
    updated to point to it, and that Django's settings are returned to their
84
 
    original values at the end.
85
 
    """
86
 
    config = get_rabbit().config
87
 
    fixture = RabbitServerSettings(config)
88
 
    test.useFixture(fixture)
89
 
 
90
 
 
91
 
def uses_rabbit_fixture(func):
92
 
    """Decorate a test function with `use_rabbit_fixture`."""
93
 
    @wraps(func)
94
 
    def wrapper(self):
95
 
        use_rabbit_fixture(self)
96
 
        return func(self)
97
 
    return wrapper