diff --git a/tabpy/tabpy_server/app/app.py b/tabpy/tabpy_server/app/app.py index 71a0651b..b4b0af21 100644 --- a/tabpy/tabpy_server/app/app.py +++ b/tabpy/tabpy_server/app/app.py @@ -172,8 +172,7 @@ def _parse_config(self, config_file): def set_parameter(settings_key, config_key, - default_val=None, - check_env_var=False): + default_val=None): key_is_set = False if config_key is not None and\ @@ -192,20 +191,21 @@ def set_parameter(settings_key, logger.debug( f'Parameter {settings_key} set to ' f'"{self.settings[settings_key]}" ' - 'from default value') + 'from default value or environment variable') if not key_is_set: logger.debug( f'Parameter {settings_key} is not set') set_parameter(SettingsParameters.Port, ConfigParameters.TABPY_PORT, - default_val=9004, check_env_var=True) + default_val=9004) set_parameter(SettingsParameters.ServerVersion, None, default_val=__version__) set_parameter(SettingsParameters.EvaluateTimeout, ConfigParameters.TABPY_EVALUATE_TIMEOUT, default_val=30) + try: self.settings[SettingsParameters.EvaluateTimeout] = float( self.settings[SettingsParameters.EvaluateTimeout]) @@ -219,8 +219,7 @@ def set_parameter(settings_key, set_parameter(SettingsParameters.UploadDir, ConfigParameters.TABPY_QUERY_OBJECT_PATH, default_val=os.path.join(pkg_path, - 'tmp', 'query_objects'), - check_env_var=True) + 'tmp', 'query_objects')) if not os.path.exists(self.settings[SettingsParameters.UploadDir]): os.makedirs(self.settings[SettingsParameters.UploadDir]) @@ -241,8 +240,7 @@ def set_parameter(settings_key, # last dependence on batch/shell script set_parameter(SettingsParameters.StateFilePath, ConfigParameters.TABPY_STATE_PATH, - default_val=os.path.join(pkg_path, 'tabpy_server'), - check_env_var=True) + default_val=os.path.join(pkg_path, 'tabpy_server')) self.settings[SettingsParameters.StateFilePath] = os.path.realpath( os.path.normpath( os.path.expanduser( diff --git a/tests/unit/server_tests/test_config.py b/tests/unit/server_tests/test_config.py index 6d41ec36..388c95e6 100644 --- a/tests/unit/server_tests/test_config.py +++ b/tests/unit/server_tests/test_config.py @@ -32,16 +32,12 @@ def test_no_config_file(self, mock_os, pkg_path = os.path.dirname(tabpy.__file__) obj_path = os.path.join(pkg_path, 'tmp', 'query_objects') state_path = os.path.join(pkg_path, 'tabpy_server') - - mock_os.getenv.side_effect = [9004, obj_path, state_path] + mock_os.environ = { + 'TABPY_PORT': 9004, 'TABPY_QUERY_OBJECT_PATH': obj_path, + 'TABPY_STATE_PATH': state_path} TabPyApp(None) - getenv_calls = [ - call('TABPY_PORT'), - call('TABPY_QUERY_OBJECT_PATH'), - call('TABPY_STATE_PATH')] - mock_os.getenv.assert_has_calls(getenv_calls, any_order=True) self.assertEqual(len(mock_psws.mock_calls), 1) self.assertEqual(len(mock_tabpy_state.mock_calls), 1) self.assertEqual(len(mock_path_exists.mock_calls), 1) @@ -89,15 +85,12 @@ def test_config_file_present(self, mock_os, mock_path_exists, config_file.close() mock_parse_arguments.return_value = Namespace(config=config_file.name) - - mock_os.getenv.side_effect = [1234] mock_os.path.realpath.return_value = 'bar' + mock_os.environ = {'TABPY_PORT': 1234} app = TabPyApp(config_file.name) - getenv_calls = [call('TABPY_PORT')] - mock_os.getenv.assert_has_calls(getenv_calls, any_order=True) - self.assertEqual(app.settings['port'], 1234) + self.assertEqual(app.settings['port'], '1234') self.assertEqual(app.settings['server_version'], open('VERSION').read().strip()) self.assertEqual(app.settings['upload_dir'], 'foo')