~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/testing/layers.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-27 18:36:34 UTC
  • mfrom: (13023.9.12 rabbit-layer)
  • Revision ID: launchpad@pqm.canonical.com-20110627183634-96p3qvorpmvutpic
[r=jtv][no-qa] Introducing RabbitMQLayer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    'reconnect_stores',
53
53
    ]
54
54
 
 
55
from cProfile import Profile
55
56
import datetime
56
57
import errno
57
58
import gc
62
63
import subprocess
63
64
import sys
64
65
import tempfile
 
66
from textwrap import dedent
65
67
import threading
66
68
import time
67
 
from cProfile import Profile
68
 
from textwrap import dedent
69
 
from unittest import TestCase, TestResult
 
69
from unittest import (
 
70
    TestCase,
 
71
    TestResult,
 
72
    )
70
73
from urllib import urlopen
71
74
 
72
75
from fixtures import (
73
76
    Fixture,
74
77
    MonkeyPatch,
75
78
    )
 
79
from lazr.restful.utils import safe_hasattr
76
80
import psycopg2
77
81
from storm.zope.interfaces import IZStorm
78
82
import transaction
 
83
from windmill.bin.admin_lib import (
 
84
    start_windmill,
 
85
    teardown as windmill_teardown,
 
86
    )
79
87
import wsgi_intercept
80
88
from wsgi_intercept import httplib2_intercept
81
 
 
82
 
from lazr.restful.utils import safe_hasattr
83
 
 
84
 
from windmill.bin.admin_lib import (
85
 
    start_windmill, teardown as windmill_teardown)
86
 
 
 
89
from zope.app.publication.httpfactory import chooseClasses
87
90
import zope.app.testing.functional
 
91
from zope.app.testing.functional import (
 
92
    FunctionalTestSetup,
 
93
    ZopePublication,
 
94
    )
 
95
from zope.component import (
 
96
    getUtility,
 
97
    globalregistry,
 
98
    provideUtility,
 
99
    )
 
100
from zope.component.interfaces import ComponentLookupError
88
101
import zope.publisher.publish
89
 
from zope.app.publication.httpfactory import chooseClasses
90
 
from zope.app.testing.functional import FunctionalTestSetup, ZopePublication
91
 
from zope.component import getUtility, provideUtility
92
 
from zope.component import globalregistry
93
 
from zope.component.interfaces import ComponentLookupError
94
102
from zope.security.management import getSecurityPolicy
95
103
from zope.security.simplepolicies import PermissiveSecurityPolicy
96
104
from zope.server.logger.pythonlogger import PythonLogger
97
105
from zope.testing.testrunner.runner import FakeInputContinueGenerator
98
106
 
99
 
import canonical.launchpad.webapp.session
100
 
from canonical.launchpad.webapp.vhosts import allvhosts
101
 
from canonical.lazr import pidfile
102
 
from canonical.config import CanonicalConfig, config, dbconfig
 
107
from canonical.config import (
 
108
    CanonicalConfig,
 
109
    config,
 
110
    dbconfig,
 
111
    )
103
112
from canonical.config.fixture import (
104
113
    ConfigFixture,
105
114
    ConfigUseFixture,
106
115
    )
107
116
from canonical.database.revision import (
108
 
    confirm_dbrevision, confirm_dbrevision_on_startup)
 
117
    confirm_dbrevision,
 
118
    confirm_dbrevision_on_startup,
 
119
    )
109
120
from canonical.database.sqlbase import (
110
121
    cursor,
111
122
    session_store,
112
123
    ZopelessTransactionManager,
113
124
    )
114
125
from canonical.launchpad.interfaces.mailbox import IMailBox
115
 
from canonical.launchpad.webapp.interfaces import IOpenLaunchBag
116
 
from lp.testing import ANONYMOUS, login, logout, is_logged_in
117
 
import lp.services.mail.stub
118
 
from lp.services.mail.mailbox import TestMailBox
119
126
from canonical.launchpad.scripts import execute_zcml_for_scripts
120
 
from lp.services.googlesearch.tests.googleserviceharness import (
121
 
    GoogleServiceTestSetup)
122
127
from canonical.launchpad.webapp.interfaces import (
123
 
        DEFAULT_FLAVOR, IStoreSelector, MAIN_STORE)
 
128
    DEFAULT_FLAVOR,
 
129
    IOpenLaunchBag,
 
130
    IStoreSelector,
 
131
    MAIN_STORE,
 
132
    )
124
133
from canonical.launchpad.webapp.servers import (
125
 
    LaunchpadAccessLogger, register_launchpad_request_publication_factories)
 
134
    LaunchpadAccessLogger,
 
135
    register_launchpad_request_publication_factories,
 
136
    )
 
137
import canonical.launchpad.webapp.session
 
138
from canonical.launchpad.webapp.vhosts import allvhosts
 
139
from canonical.lazr import pidfile
126
140
from canonical.lazr.testing.layers import MockRootFolder
127
141
from canonical.lazr.timeout import (
128
 
    get_default_timeout_function, set_default_timeout_function)
 
142
    get_default_timeout_function,
 
143
    set_default_timeout_function,
 
144
    )
 
145
from canonical.librarian.testing.server import LibrarianServerFixture
129
146
from canonical.lp import initZopeless
130
 
from canonical.librarian.testing.server import LibrarianServerFixture
131
147
from canonical.testing import reset_logging
132
148
from canonical.testing.profiled import profiled
133
149
from canonical.testing.smtpd import SMTPController
 
150
from lp.services.googlesearch.tests.googleserviceharness import (
 
151
    GoogleServiceTestSetup,
 
152
    )
 
153
from lp.services.mail.mailbox import TestMailBox
 
154
import lp.services.mail.stub
134
155
from lp.services.memcache.client import memcache_client_factory
135
156
from lp.services.osutils import kill_by_pidfile
 
157
from lp.services.rabbit.testing.server import RabbitServer
 
158
from lp.testing import (
 
159
    ANONYMOUS,
 
160
    is_logged_in,
 
161
    login,
 
162
    logout,
 
163
    )
136
164
from lp.testing.pgsql import PgTestSetup
137
165
 
138
166
 
640
668
        MemcachedLayer.client.flush_all()  # Only do this in tests!
641
669
 
642
670
 
 
671
class RabbitMQLayer(BaseLayer):
 
672
    """Provides tests access to a rabbitMQ instance."""
 
673
    _reset_between_tests = True
 
674
 
 
675
    rabbit = RabbitServer()
 
676
 
 
677
    _is_setup = False
 
678
 
 
679
    @classmethod
 
680
    @profiled
 
681
    def setUp(cls):
 
682
        cls.rabbit.setUp()
 
683
        cls.config_fixture.add_section(
 
684
            cls.rabbit.config.service_config)
 
685
        cls.appserver_config_fixture.add_section(
 
686
            cls.rabbit.config.service_config)
 
687
        cls._is_setup = True
 
688
 
 
689
    @classmethod
 
690
    @profiled
 
691
    def tearDown(cls):
 
692
        if not cls._is_setup:
 
693
            return
 
694
        cls.rabbit.cleanUp()
 
695
        cls._is_setup = False
 
696
        # Can't pop the config above, so bail here and let the test runner
 
697
        # start a sub-process.
 
698
        raise NotImplementedError
 
699
 
 
700
    @classmethod
 
701
    @profiled
 
702
    def testSetUp(cls):
 
703
        pass
 
704
 
 
705
    @classmethod
 
706
    @profiled
 
707
    def testTearDown(cls):
 
708
        pass
 
709
 
 
710
 
643
711
# We store a reference to the DB-API connect method here when we
644
712
# put a proxy in its place.
645
713
_org_connect = None
937
1005
    return None
938
1006
 
939
1007
 
940
 
class LaunchpadLayer(LibrarianLayer, MemcachedLayer):
 
1008
class LaunchpadLayer(LibrarianLayer, MemcachedLayer, RabbitMQLayer):
941
1009
    """Provides access to the Launchpad database and daemons.
942
1010
 
943
1011
    We need to ensure that the database setup runs before the daemon