Skip to content
Snippets Groups Projects
Commit f133f0c8 authored by Jimmy Petersson's avatar Jimmy Petersson
Browse files

Use strtobool to parse boolean env variables

parent cac17605
No related branches found
No related tags found
No related merge requests found
import os import os
from distutils.util import strtobool
def get_args_from_env(): def get_args_from_env():
...@@ -11,10 +12,12 @@ def get_args_from_env(): ...@@ -11,10 +12,12 @@ def get_args_from_env():
) )
kwargs = dict( kwargs = dict(
htdigest_file=os.environ.get('KLAUS_HTDIGEST_FILE'), htdigest_file=os.environ.get('KLAUS_HTDIGEST_FILE'),
use_smarthttp=bool(os.environ.get('KLAUS_USE_SMARTHTTP')), use_smarthttp=strtobool(os.environ.get('KLAUS_USE_SMARTHTTP', '0')),
require_browser_auth=bool(os.environ.get('KLAUS_REQUIRE_BROWSER_AUTH')), require_browser_auth=strtobool(
disable_push=bool(os.environ.get('KLAUS_DISABLE_PUSH')), os.environ.get('KLAUS_REQUIRE_BROWSER_AUTH', '0')),
unauthenticated_push=bool(os.environ.get('KLAUS_UNAUTHENTICATED_PUSH')), disable_push=strtobool(os.environ.get('KLAUS_DISABLE_PUSH', '0')),
unauthenticated_push=strtobool(
os.environ.get('KLAUS_UNAUTHENTICATED_PUSH', '0')),
ctags_policy=os.environ.get('KLAUS_CTAGS_POLICY', 'none') ctags_policy=os.environ.get('KLAUS_CTAGS_POLICY', 'none')
) )
return args, kwargs return args, kwargs
...@@ -49,8 +49,8 @@ def test_app_args_from_env(): ...@@ -49,8 +49,8 @@ def test_app_args_from_env():
'KLAUS_HTDIGEST_FILE': HTDIGEST_FILE, 'KLAUS_HTDIGEST_FILE': HTDIGEST_FILE,
'KLAUS_USE_SMARTHTTP': 'yes', 'KLAUS_USE_SMARTHTTP': 'yes',
'KLAUS_REQUIRE_BROWSER_AUTH': '1', 'KLAUS_REQUIRE_BROWSER_AUTH': '1',
'KLAUS_DISABLE_PUSH': 'false', # TODO? 'KLAUS_DISABLE_PUSH': 'false',
'KLAUS_UNAUTHENTICATED_PUSH': '0', # TODO? 'KLAUS_UNAUTHENTICATED_PUSH': '0',
'KLAUS_CTAGS_POLICY': 'ALL' 'KLAUS_CTAGS_POLICY': 'ALL'
}, },
([TEST_REPO], TEST_SITE_NAME), ([TEST_REPO], TEST_SITE_NAME),
...@@ -58,11 +58,21 @@ def test_app_args_from_env(): ...@@ -58,11 +58,21 @@ def test_app_args_from_env():
htdigest_file=HTDIGEST_FILE, htdigest_file=HTDIGEST_FILE,
use_smarthttp=True, use_smarthttp=True,
require_browser_auth=True, require_browser_auth=True,
disable_push=True, disable_push=False,
unauthenticated_push=True, unauthenticated_push=False,
ctags_policy='ALL') ctags_policy='ALL')
) )
with pytest.raises(ValueError):
check_env(
{
'KLAUS_REPOS': TEST_REPO,
'KLAUS_SITE_NAME': TEST_SITE_NAME,
'KLAUS_HTDIGEST_FILE': HTDIGEST_FILE,
'KLAUS_USE_SMARTHTTP': 'unsupported',
}, (), {}
)
def test_wsgi(): def test_wsgi():
clear_env() clear_env()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment