def test_sets_restores_instance(self): fixture = ConfigUseFixture('foo') orig_instance = config.instance_name fixture.setUp() try: self.assertEqual('foo', config.instance_name) finally: fixture.cleanUp() self.assertEqual(orig_instance, config.instance_name)
def setUp(self): super(LibrarianWebMacaroonTestCase, self).setUp() # Copy launchpad.internal_macaroon_secret_key from the appserver # config so that we can issue macaroons using it. with ConfigUseFixture(self.layer.appserver_config_name): key = config.launchpad.internal_macaroon_secret_key self.pushConfig("launchpad", internal_macaroon_secret_key=key)
def test_override_directory(self): # The launchpad.config_overlay_dir setting can be used to load # extra config files over the top. This is useful for overlaying # non-version-controlled secrets. config_dir = self.useFixture(TempDir(rootdir='configs')) config_name = os.path.basename(config_dir.path) overlay_dir = self.useFixture(TempDir(rootdir='configs')) with open(config_dir.join('launchpad-lazr.conf'), 'w') as f: f.write(""" [meta] extends: ../testrunner/launchpad-lazr.conf [launchpad] config_overlay_dir: ../%s """ % os.path.basename(overlay_dir.path)) os.symlink( '../testrunner/launchpad.conf', config_dir.join('launchpad.conf')) config = lp.services.config.config with ConfigUseFixture(config_name): self.assertEqual('launchpad_main', config.launchpad.dbuser) self.assertEqual('', config.launchpad.site_message) with open(overlay_dir.join('00-test-lazr.conf'), 'w') as f: f.write(""" [launchpad] dbuser: overlay-user site_message: An overlay! """) with ConfigUseFixture(config_name): self.assertEqual('overlay-user', config.launchpad.dbuser) self.assertEqual('An overlay!', config.launchpad.site_message) with open(overlay_dir.join('01-test-lazr.conf'), 'w') as f: f.write(""" [launchpad] site_message: Another overlay! """) with ConfigUseFixture(config_name): self.assertEqual('overlay-user', config.launchpad.dbuser) self.assertEqual('Another overlay!', config.launchpad.site_message) os.unlink(overlay_dir.join('00-test-lazr.conf')) with ConfigUseFixture(config_name): self.assertEqual('launchpad_main', config.launchpad.dbuser) self.assertEqual('Another overlay!', config.launchpad.site_message)
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
def set_config_parameters(self, **kwargs): config_name = self.getUniqueString() config_fixture = self.useFixture( ConfigFixture( config_name, LaunchpadFunctionalLayer.config_fixture.instance_name)) setting_lines = ['[launchpad]'] + \ ['%s: %s' % (k, v) for k, v in kwargs.items()] config_fixture.add_section('\n'.join(setting_lines)) self.useFixture(ConfigUseFixture(config_name))
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 makeTurnipServer(self): turnip_server = FakeTurnipServer() config_name = self.factory.getUniqueString() config_fixture = self.useFixture( ConfigFixture(config_name, config.instance_name)) setting_lines = [ '[codehosting]', 'internal_git_api_endpoint: %s' % turnip_server.getURL(), ] config_fixture.add_section('\n' + '\n'.join(setting_lines)) self.useFixture(ConfigUseFixture(config_name)) turnip_server.start() self.addCleanup(turnip_server.stop) return turnip_server
def makeTargetGitServer(self): """Set up a target Git server that can receive imports.""" self.target_store = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.target_store) self.target_git_server = GitServer(self.target_store, use_server=True) self.target_git_server.start_server() self.addCleanup(self.target_git_server.stop_server) config_name = self.getUniqueString() config_fixture = self.useFixture( ConfigFixture(config_name, self.layer.config_fixture.instance_name)) setting_lines = [ "[codehosting]", "git_browse_root: %s" % self.target_git_server.get_url(""), "", "[launchpad]", "internal_macaroon_secret_key: some-secret", ] config_fixture.add_section("\n" + "\n".join(setting_lines)) self.useFixture(ConfigUseFixture(config_name)) self.useFixture(GitHostingFixture())