def test_db_naming_LP_TEST_INSTANCE_set(self): # when LP_TEST_INSTANCE is set, it is used for dynamic db naming. BaseLayer.setUp() self.addCleanup(BaseLayer.tearDown) fixture = PgTestSetup(dbname=PgTestSetup.dynamic) expected_name = "%s_%d" % (PgTestSetup.dbname, os.getpid()) self.assertDBName(expected_name, fixture)
def test_db_naming_LP_TEST_INSTANCE_set(self): # when LP_TEST_INSTANCE is set, it is used for dynamic db naming. BaseLayer.setUp() self.addCleanup(BaseLayer.tearDown) fixture = PgTestSetup(dbname=PgTestSetup.dynamic) raw_uuid = os.environ['LP_TEST_INSTANCE'].split('_', 1)[1] instance_uuid = uuid.UUID(raw_uuid) self.assertEqual(uuid.RFC_4122, instance_uuid.variant) self.assertEqual(1, instance_uuid.version) expected_name = "%s_%d_%s" % ( PgTestSetup.dbname, os.getpid(), instance_uuid.hex) self.assertDBName(expected_name, fixture)
def test_db_naming_stored_in_BaseLayer_configs(self): BaseLayer.setUp() self.addCleanup(BaseLayer.tearDown) fixture = PgTestSetup(dbname=PgTestSetup.dynamic) fixture.setUp() self.addCleanup(fixture.dropDb) self.addCleanup(fixture.tearDown) expected_value = 'dbname=%s host=localhost' % fixture.dbname self.assertEqual(expected_value, dbconfig.rw_main_master) self.assertEqual(expected_value, dbconfig.rw_main_slave) with ConfigUseFixture(BaseLayer.appserver_config_name): self.assertEqual(expected_value, dbconfig.rw_main_master) self.assertEqual(expected_value, dbconfig.rw_main_slave)
def test_db_naming_stored_in_BaseLayer_configs(self): BaseLayer.setUp() self.addCleanup(BaseLayer.tearDown) fixture = PgTestSetup(dbname=PgTestSetup.dynamic) fixture.setUp() self.addCleanup(fixture.dropDb) self.addCleanup(fixture.tearDown) expected_value = 'dbname=%s' % fixture.dbname self.assertEqual(expected_value, dbconfig.rw_main_master) self.assertEqual(expected_value, dbconfig.rw_main_slave) with ConfigUseFixture(BaseLayer.appserver_config_name): self.assertEqual(expected_value, dbconfig.rw_main_master) self.assertEqual(expected_value, dbconfig.rw_main_slave)
def setup(): # This code needs to be run after other zcml setup happens in # runlaunchpad, so it is passed in as a callable. We set up layers # here because we need to control fixtures within this process, and # because we want interactive tests to be as similar as possible to # tests run in the testrunner. # Note that this changes the config instance-name, with the result # that the configuration of utilities may become invalidated. # XXX Robert Collins, bug=883980: In short, we should derive the # other services from the test runner, rather than duplicating # the work of test setup within the slave appserver. That will # permit reuse of the librarian, DB, rabbit etc, and # correspondingly easier assertions and inspection of interactions # with other services. That would mean we do not need to set up rabbit # or the librarian here: the test runner would control and take care # of that. BaseLayer.setUp() teardowns.append(BaseLayer.tearDown) RabbitMQLayer.setUp() teardowns.append(RabbitMQLayer.tearDown) # We set up the database here even for the test suite because we want # to be able to control the database here in the subprocess. It is # possible to do that when setting the database up in the parent # process, but it is messier. This is simple. installFakeConnect() teardowns.append(uninstallFakeConnect) DatabaseLayer.setUp() teardowns.append(DatabaseLayer.tearDown) # The Librarian needs access to the database, so setting it up here # where we are setting up the database makes the most sense. LibrarianLayer.setUp() teardowns.append(LibrarianLayer.tearDown) # Switch to the appserver config. fixture = ConfigUseFixture(BaseLayer.appserver_config_name) fixture.setUp() teardowns.append(fixture.cleanUp) # Interactive tests always need this. We let functional tests use # a local one too because of simplicity. LayerProcessController.startSMTPServer() teardowns.append(LayerProcessController.stopSMTPServer) if interactive_tests: root_url = config.appserver_root_url() print '*' * 70 print 'In a few seconds, go to ' + root_url + '/+yuitest' print '*' * 70