first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
|
||||
from packages.config.settings import get_settings
|
||||
|
||||
|
||||
def _with_env(**kwargs):
|
||||
old = {}
|
||||
for k, v in kwargs.items():
|
||||
old[k] = os.environ.get(k)
|
||||
os.environ[k] = v
|
||||
get_settings.cache_clear()
|
||||
return old
|
||||
|
||||
|
||||
def _restore(old: dict):
|
||||
for k, v in old.items():
|
||||
if v is None:
|
||||
os.environ.pop(k, None)
|
||||
else:
|
||||
os.environ[k] = v
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_issue_token_ok():
|
||||
from apps.api.auth import expected_token, issue_token
|
||||
|
||||
old = _with_env(AUTH_SECRET="unit-secret", ADMIN_PASSWORD="pass123")
|
||||
try:
|
||||
tok = issue_token("pass123")
|
||||
assert tok is not None
|
||||
assert tok == expected_token()
|
||||
assert issue_token("wrong") is None
|
||||
finally:
|
||||
_restore(old)
|
||||
|
||||
|
||||
def test_auth_disabled():
|
||||
from apps.api.auth import auth_disabled
|
||||
|
||||
old = _with_env(AUTH_SECRET="disabled")
|
||||
try:
|
||||
assert auth_disabled() is True
|
||||
finally:
|
||||
_restore(old)
|
||||
Reference in New Issue
Block a user