Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
klaus
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
jonashaag
klaus
Commits
adfbdc61
Commit
adfbdc61
authored
8 years ago
by
Jimmy Petersson
Browse files
Options
Downloads
Patches
Plain Diff
Use monkeypatch for os.environ
parent
f133f0c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_contrib.py
+21
-13
21 additions, 13 deletions
tests/test_contrib.py
with
21 additions
and
13 deletions
tests/test_contrib.py
+
21
−
13
View file @
adfbdc61
...
...
@@ -11,25 +11,23 @@ from .utils import *
from
.test_make_app
import
can_reach_unauth
,
can_push_auth
def
clear_env
():
for
var
in
list
(
os
.
environ
):
if
var
.
startswith
(
'
KLAUS_
'
):
os
.
environ
.
pop
(
var
)
def
check_env
(
env
,
expected_args
,
expected_kwargs
):
clear_env
()
os
.
environ
.
update
(
env
)
args
,
kwargs
=
app_args
.
get_args_from_env
()
assert
args
==
expected_args
assert
kwargs
==
expected_kwargs
def
test_app_args_from_env
():
clear_env
()
def
test_missing_in_env
(
monkeypatch
):
"""
Test that KeyError is raised when required env var is missing
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
with
pytest
.
raises
(
KeyError
):
args
,
kwargs
=
app_args
.
get_args_from_env
()
def
test_minimum_env
(
monkeypatch
):
"""
Test to provide only required env var
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
check_env
(
{
'
KLAUS_SITE_NAME
'
:
TEST_SITE_NAME
},
([],
TEST_SITE_NAME
),
...
...
@@ -42,6 +40,10 @@ def test_app_args_from_env():
ctags_policy
=
'
none
'
)
)
def
test_complete_env
(
monkeypatch
):
"""
Test to provide all supported env var
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
check_env
(
{
'
KLAUS_REPOS
'
:
TEST_REPO
,
...
...
@@ -63,6 +65,10 @@ def test_app_args_from_env():
ctags_policy
=
'
ALL
'
)
)
def
test_unsupported_boolean_env
(
monkeypatch
):
"""
Test that unsupported boolean env var raises ValueError
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
with
pytest
.
raises
(
ValueError
):
check_env
(
{
...
...
@@ -74,8 +80,9 @@ def test_app_args_from_env():
)
def
test_wsgi
():
clear_env
()
def
test_wsgi
(
monkeypatch
):
"""
Test start of wsgi app
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
os
.
environ
[
'
KLAUS_REPOS
'
]
=
TEST_REPO
os
.
environ
[
'
KLAUS_SITE_NAME
'
]
=
TEST_SITE_NAME
from
klaus.contrib
import
wsgi
...
...
@@ -91,8 +98,9 @@ def test_wsgi():
assert
can_push_auth
()
def
test_wsgi_autoreload
():
clear_env
()
def
test_wsgi_autoreload
(
monkeypatch
):
"""
Test start of wsgi autoreload app
"""
monkeypatch
.
setattr
(
os
,
'
environ
'
,
os
.
environ
.
copy
())
os
.
environ
[
'
KLAUS_REPOS_ROOT
'
]
=
TEST_REPO_ROOT
os
.
environ
[
'
KLAUS_SITE_NAME
'
]
=
TEST_SITE_NAME
from
klaus.contrib
import
wsgi_autoreload
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment