~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-12-18 15:13:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14547.
  • Revision ID: curtis.hovey@canonical.com-20111218151307-sdm2gzobt5tplbe0
Moved badges to lp.app.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
    )
102
102
from zope.server.logger.pythonlogger import PythonLogger
103
103
 
104
 
from lp.services import pidfile
105
 
from lp.services.config import (
 
104
from canonical.config import (
 
105
    CanonicalConfig,
106
106
    config,
107
107
    dbconfig,
108
 
    LaunchpadConfig,
109
108
    )
110
 
from lp.services.config.fixture import (
 
109
from canonical.config.fixture import (
111
110
    ConfigFixture,
112
111
    ConfigUseFixture,
113
112
    )
114
 
from lp.services.database.sqlbase import session_store
 
113
from canonical.database.sqlbase import session_store
 
114
from canonical.launchpad.scripts import execute_zcml_for_scripts
 
115
from canonical.launchpad.webapp.authorization import (
 
116
    LaunchpadPermissiveSecurityPolicy,
 
117
    )
 
118
from canonical.launchpad.webapp.interfaces import (
 
119
    DEFAULT_FLAVOR,
 
120
    IOpenLaunchBag,
 
121
    IStoreSelector,
 
122
    MAIN_STORE,
 
123
    )
 
124
from canonical.launchpad.webapp.servers import (
 
125
    LaunchpadAccessLogger,
 
126
    register_launchpad_request_publication_factories,
 
127
    )
 
128
import canonical.launchpad.webapp.session
 
129
from canonical.lazr import pidfile
 
130
from canonical.lazr.testing.layers import MockRootFolder
 
131
from canonical.lazr.timeout import (
 
132
    get_default_timeout_function,
 
133
    set_default_timeout_function,
 
134
    )
 
135
from canonical.librarian.testing.server import LibrarianServerFixture
 
136
from canonical.testing import reset_logging
 
137
from canonical.testing.profiled import profiled
 
138
from canonical.testing.smtpd import SMTPController
115
139
from lp.services.googlesearch.tests.googleserviceharness import (
116
140
    GoogleServiceTestSetup,
117
141
    )
118
 
from lp.services.librarianserver.testing.server import LibrarianServerFixture
119
142
from lp.services.mail.mailbox import (
120
143
    IMailBox,
121
144
    TestMailBox,
125
148
from lp.services.memcache.client import memcache_client_factory
126
149
from lp.services.osutils import kill_by_pidfile
127
150
from lp.services.rabbit.server import RabbitServer
128
 
from lp.services.scripts import execute_zcml_for_scripts
129
 
from lp.services.testing.profiled import profiled
130
 
from lp.services.timeout import (
131
 
    get_default_timeout_function,
132
 
    set_default_timeout_function,
133
 
    )
134
 
from lp.services.webapp.authorization import LaunchpadPermissiveSecurityPolicy
135
 
from lp.services.webapp.interfaces import (
136
 
    DEFAULT_FLAVOR,
137
 
    IOpenLaunchBag,
138
 
    IStoreSelector,
139
 
    MAIN_STORE,
140
 
    )
141
 
from lp.services.webapp.servers import (
142
 
    LaunchpadAccessLogger,
143
 
    register_launchpad_request_publication_factories,
144
 
    )
145
 
import lp.services.webapp.session
146
151
from lp.testing import (
147
152
    ANONYMOUS,
148
153
    login,
149
154
    logout,
150
 
    reset_logging,
151
155
    )
152
156
from lp.testing.dbuser import switch_dbuser
153
157
from lp.testing.pgsql import PgTestSetup
154
 
from lp.testing.smtpd import SMTPController
155
158
 
156
159
 
157
160
orig__call__ = zope.app.testing.functional.HTTPCaller.__call__
254
257
            break
255
258
 
256
259
 
257
 
class MockRootFolder:
258
 
    """Implement the minimum functionality required by Z3 ZODB dependencies
259
 
 
260
 
    Installed as part of FunctionalLayer.testSetUp() to allow the http()
261
 
    method (zope.app.testing.functional.HTTPCaller) to work.
262
 
    """
263
 
    @property
264
 
    def _p_jar(self):
265
 
        return self
266
 
 
267
 
    def sync(self):
268
 
        pass
269
 
 
270
 
 
271
260
class BaseLayer:
272
261
    """Base layer.
273
262
 
559
548
    @classmethod
560
549
    def appserver_config(cls):
561
550
        """Return a config suitable for AppServer tests."""
562
 
        return LaunchpadConfig(cls.appserver_config_name)
 
551
        return CanonicalConfig(cls.appserver_config_name)
563
552
 
564
553
    @classmethod
565
554
    def appserver_root_url(cls, facet='mainsite', ensureSlash=False):
806
795
        cls._db_fixture.tearDown()
807
796
 
808
797
        # Fail tests that forget to uninstall their database policies.
809
 
        from lp.services.webapp.adapter import StoreSelector
 
798
        from canonical.launchpad.webapp.adapter import StoreSelector
810
799
        while StoreSelector.get_current() is not None:
811
800
            BaseLayer.flagTestIsolationFailure(
812
801
                "Database policy %s still installed"
824
813
    def installMockDb(cls):
825
814
        assert cls.mockdb_mode is None, 'mock db already installed'
826
815
 
827
 
        from lp.testing.mockdb import (
 
816
        from canonical.testing.mockdb import (
828
817
                script_filename, ScriptRecorder, ScriptPlayer,
829
818
                )
830
819
 
1050
1039
        """
1051
1040
        if LaunchpadLayer._raw_sessiondb_connection is None:
1052
1041
            from storm.uri import URI
1053
 
            from lp.services.webapp.adapter import (
 
1042
            from canonical.launchpad.webapp.adapter import (
1054
1043
                LaunchpadSessionDatabase)
1055
1044
            launchpad_session_database = LaunchpadSessionDatabase(
1056
1045
                URI('launchpad-session:'))
1122
1111
 
1123
1112
        # Access the cookie manager's secret to get the cache populated.
1124
1113
        # If we don't, it may issue extra queries depending on test order.
1125
 
        lp.services.webapp.session.idmanager.secret
 
1114
        canonical.launchpad.webapp.session.idmanager.secret
1126
1115
        # If our request publication factories were defined using ZCML,
1127
1116
        # they'd be set up by set_up_functional_test().setUp(). Since
1128
1117
        # they're defined by Python code, we need to call that code
1386
1375
    @profiled
1387
1376
    def testSetUp(cls):
1388
1377
        # Reset any statistics
1389
 
        from lp.services.webapp.opstats import OpStats
 
1378
        from canonical.launchpad.webapp.opstats import OpStats
1390
1379
        OpStats.resetStats()
1391
1380
 
1392
1381
        # Connect Storm
1400
1389
        endInteraction()
1401
1390
 
1402
1391
        # Reset any statistics
1403
 
        from lp.services.webapp.opstats import OpStats
 
1392
        from canonical.launchpad.webapp.opstats import OpStats
1404
1393
        OpStats.resetStats()
1405
1394
 
1406
1395
        # Disconnect Storm so it doesn't get in the way of database resets
1740
1729
    @classmethod
1741
1730
    def setConfig(cls):
1742
1731
        """Stash a config for use."""
1743
 
        cls.appserver_config = LaunchpadConfig(
 
1732
        cls.appserver_config = CanonicalConfig(
1744
1733
            BaseLayer.appserver_config_name, 'runlaunchpad')
1745
1734
 
1746
1735
    @classmethod