def startup_server(self): if os.environ.get('DKCLI_CONFIG_LOCATION') is not None: config_file_location = os.path.expandvars( '${DKCLI_CONFIG_LOCATION}').strip() else: config_file_location = "../DKCloudCommandConfig.json" # get the connection info config = DKCloudCommandConfig() config.init_from_file(config_file_location) config.delete_jwt() config.save_to_stored_file_location() app_config = { "mesos-url": MESOS_URL, "chronos-url": CHRONOS_URL, "generic-run-script": "https://s3.amazonaws.com/mesos-scripts/generic_run_recipe_v2.sh", "github-customer": "DKCustomers", "working-dir": "work", "port-number": "14001" } server_config = None with tempfile.NamedTemporaryFile(delete=False, dir='./') as temp: temp.write(json.dumps(app_config)) server_config = temp.name temp.flush() self.server_thread = Process(target=main, args=(None, server_config, False)) self.server_thread.start() time.sleep(3)
def test_read_config_from_disk(self): cfg = DKCloudCommandConfig() cfg.init_from_file("files/UnitTestConfig.json") self.assertEquals(cfg.get_port(), u'00') self.assertEquals(cfg.get_password(), u'shhh') self.assertEquals(cfg.get_username(), u'[email protected]') self.assertEquals(cfg.get_ip(), u'IP') self.assertTrue(cfg.get_file_location()) # make sure absolute location get saved pass
def setUpClass(cls): if os.environ.get("DKCLI_CONFIG_LOCATION") is not None: config_file_location = os.path.expandvars("${DKCLI_CONFIG_LOCATION}").strip() else: config_file_location = "../DKCloudCommandConfig.json" # get the connection info config = DKCloudCommandConfig() config.init_from_file(config_file_location) config.delete_jwt() config.save_to_stored_file_location()
def test_save_config_from_disk(self): target_path = os.path.join(self._TEMPFILE_LOCATION, 'DKCloudCommandConfig.json') cfg = DKCloudCommandConfig() cfg.init_from_file("../DKCloudCommandConfig.json") cfg.set_jwt('newTokenForYou') cfg.set_file_location('/tmp/lala.json') cfg.save_to_file(target_path) cfg2 = DKCloudCommandConfig() cfg2.init_from_file(target_path) self.assertTrue(cfg.get_jwt(), 'newTokenForYou') self.assertTrue(cfg.get_file_location(), '/tmp/lala.json') os.remove(target_path) pass