Skip to content

Commit

Permalink
Fixed test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnegara committed Oct 2, 2019
1 parent 1cb9c73 commit c004afd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
14 changes: 6 additions & 8 deletions tabpy/tabpy_server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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])
Expand All @@ -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])

Expand All @@ -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(
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/server_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit c004afd

Please sign in to comment.