~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Gary Poster
  • Date: 2011-09-20 22:33:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14015.
  • Revision ID: gary.poster@canonical.com-20110920223307-zt1kr1px2ixjg9mn
Add yui xhr integration test support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    'TwistedLaunchpadZopelessLayer',
45
45
    'TwistedLayer',
46
46
    'YUITestLayer',
 
47
    'YUIAppServerLayer',
47
48
    'ZopelessAppServerLayer',
48
49
    'ZopelessDatabaseLayer',
49
50
    'ZopelessLayer',
755
756
        cls.force_dirty_database()
756
757
        cls._db_fixture.tearDown()
757
758
        cls._db_fixture = None
758
 
        cls._db_template_fixture.tearDown()
759
 
        cls._db_template_fixture = None
 
759
        if os.environ.get('LP_TEST_INSTANCE'):
 
760
            cls._db_template_fixture.tearDown()
 
761
            cls._db_template_fixture = None
760
762
 
761
763
    @classmethod
762
764
    @profiled
1745
1747
    smtp_controller = None
1746
1748
 
1747
1749
    @classmethod
1748
 
    def _setConfig(cls):
 
1750
    def setConfig(cls):
1749
1751
        """Stash a config for use."""
1750
1752
        cls.appserver_config = CanonicalConfig(
1751
1753
            BaseLayer.appserver_config_name, 'runlaunchpad')
1752
1754
 
1753
1755
    @classmethod
1754
1756
    def setUp(cls):
1755
 
        cls._setConfig()
 
1757
        cls.setConfig()
1756
1758
        cls.startSMTPServer()
1757
1759
        cls.startAppServer()
1758
1760
 
1778
1780
 
1779
1781
    @classmethod
1780
1782
    @profiled
1781
 
    def startAppServer(cls):
 
1783
    def startAppServer(cls, run_name='run'):
1782
1784
        """Start the app server if it hasn't already been started."""
1783
1785
        if cls.appserver is not None:
1784
1786
            raise LayerInvariantError('App server already running')
1785
1787
        cls._cleanUpStaleAppServer()
1786
 
        cls._runAppServer()
 
1788
        cls._runAppServer(run_name)
1787
1789
        cls._waitUntilAppServerIsReady()
1788
1790
 
1789
1791
    @classmethod
1875
1877
            pidfile.remove_pidfile('launchpad', cls.appserver_config)
1876
1878
 
1877
1879
    @classmethod
1878
 
    def _runAppServer(cls):
 
1880
    def _runAppServer(cls, run_name):
1879
1881
        """Start the app server using runlaunchpad.py"""
1880
1882
        _config = cls.appserver_config
1881
1883
        cmd = [
1882
 
            os.path.join(_config.root, 'bin', 'run'),
 
1884
            os.path.join(_config.root, 'bin', run_name),
1883
1885
            '-C', 'configs/%s/launchpad.conf' % _config.instance_name]
1884
1886
        environ = dict(os.environ)
1885
1887
        environ['LPCONFIG'] = _config.instance_name
1888
1890
            env=environ, cwd=_config.root)
1889
1891
 
1890
1892
    @classmethod
 
1893
    def appserver_root_url(cls):
 
1894
        return cls.appserver_config.vhost.mainsite.rooturl
 
1895
 
 
1896
    @classmethod
1891
1897
    def _waitUntilAppServerIsReady(cls):
1892
1898
        """Wait until the app server accepts connection."""
1893
1899
        assert cls.appserver is not None, "App server isn't started."
1894
 
        root_url = cls.appserver_config.vhost.mainsite.rooturl
 
1900
        root_url = cls.appserver_root_url()
1895
1901
        until = datetime.datetime.now() + WAIT_INTERVAL
1896
1902
        while until > datetime.datetime.now():
1897
1903
            try:
2001
2007
 
2002
2008
 
2003
2009
class YUITestLayer(FunctionalLayer):
2004
 
    """The base class for all YUITests cases."""
 
2010
    """The layer for all YUITests cases."""
 
2011
 
 
2012
 
 
2013
class YUIAppServerLayer(MemcachedLayer, RabbitMQLayer):
 
2014
    """The layer for all YUIAppServer test cases."""
 
2015
 
 
2016
    @classmethod
 
2017
    @profiled
 
2018
    def setUp(cls):
 
2019
        LayerProcessController.setConfig()
 
2020
        LayerProcessController.startAppServer('run-testapp')
 
2021
 
 
2022
    @classmethod
 
2023
    @profiled
 
2024
    def tearDown(cls):
 
2025
        LayerProcessController.stopAppServer()
 
2026
 
 
2027
    @classmethod
 
2028
    @profiled
 
2029
    def testSetUp(cls):
 
2030
        LaunchpadLayer.resetSessionDb()