15
17
from zope.component import getUtility, ComponentLookupError
17
19
from canonical.config import config, dbconfig
20
from canonical.pidfile import pidfile_path
18
21
from canonical.librarian.client import LibrarianClient, UploadFailed
19
22
from canonical.librarian.interfaces import ILibrarianClient
20
from canonical.testing import (
21
BaseLayer, DatabaseLayer, FunctionalLayer, LaunchpadFunctionalLayer,
22
LaunchpadLayer, LaunchpadScriptLayer, LaunchpadZopelessLayer,
23
from canonical.launchpad.ftests.harness import LaunchpadTestSetup
24
from canonical.testing.layers import (
25
AppServerLayer, BaseLayer, DatabaseLayer, FunctionalLayer,
26
LaunchpadFunctionalLayer, LaunchpadLayer, LaunchpadScriptLayer,
27
LaunchpadZopelessLayer, LayerInvariantError, LayerIsolationError,
23
28
LibrarianLayer, ZopelessLayer)
320
325
self.assertEqual(user, 'librarian')
328
class AppServerTestCase(BaseTestCase):
329
layer = AppServerLayer
331
want_component_architecture = True
332
want_launchpad_database = True
333
want_librarian_running = True
334
want_functional_flag = True
335
want_zopeless_flag = False
337
def testAppServerIsAvailable(self):
338
# Test that the app server is up and running.
339
root_url = AppServerLayer.appserver_config.vhost.mainsite.rooturl
340
home_page = urlopen(root_url).read()
342
'What is Launchpad?' in home_page,
343
"Home page couldn't be retrieved:\n%s" % home_page)
345
def testSetUpTwiceRaisesInvariantError(self):
346
# Calling setUp another time should raises an isolation error.
347
self.assertRaises(LayerInvariantError, AppServerLayer.setUp)
350
class AppServerSetupTestCase(unittest.TestCase):
351
"""Tests for the setUp and tearDown components of AppServerLayer."""
352
# We need the layer below AppServerLayer
353
layer = LaunchpadFunctionalLayer
356
# If the app server was started, kill it.
357
if AppServerLayer.appserver is not None:
358
AppServerLayer.tearDown()
360
def test_tearDown(self):
361
# Test that tearDown kills the app server and remove the PID file.
362
AppServerLayer.setUp()
363
pid = AppServerLayer.appserver.pid
364
pid_file = pidfile_path('launchpad', AppServerLayer.appserver_config)
365
AppServerLayer.tearDown()
366
self.assertRaises(OSError, os.kill, pid, 0)
367
self.failIf(os.path.exists(pid_file), "PID file wasn't removed")
368
self.failUnless(AppServerLayer.appserver is None,
369
"appserver class attribute wasn't reset")
371
def test_testTearDownRaisesIsolationError(self):
372
# A LayerIsolationError should be raised if the app server dies.
373
AppServerLayer.setUp()
374
AppServerLayer.testSetUp()
375
os.kill(AppServerLayer.appserver.pid, signal.SIGTERM)
376
AppServerLayer.appserver.wait()
377
self.assertRaises(LayerIsolationError, AppServerLayer.testTearDown)
379
def test_testTearDownResetsDB(self):
380
# The database should be reset after each test since
381
AppServerLayer.setUp()
382
AppServerLayer.testSetUp()
383
AppServerLayer.testTearDown()
384
self.assertEquals(True, LaunchpadTestSetup()._reset_db)
323
387
class TestNameTestCase(unittest.TestCase):
324
388
layer = BaseLayer
325
389
def testTestName(self):