Skip to content

Commit fe34e54

Browse files
committed
Add test cases and change os.environ setting
1 parent a3ae907 commit fe34e54

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

aikido_zen/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Aggregates from the different modules
33
"""
4+
45
import os
56

67
# Re-export functions :
@@ -26,12 +27,12 @@ def protect(mode="daemon", token=""):
2627
- daemon_disabled : This will import sinks/sources but won't start a background process
2728
Protect user's application
2829
"""
29-
if token:
30-
os.putenv("AIKIDO_TOKEN", token)
31-
3230
if aikido_disabled_flag_active():
3331
# Do not run any aikido code when the disabled flag is on
3432
return
33+
if token:
34+
os.environ["AIKIDO_TOKEN"] = token
35+
3536
if mode in ("daemon", "daemon_only"):
3637
start_background_process()
3738
if mode == "daemon_only":

aikido_zen/init_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import pytest
2+
3+
import aikido_zen
24
from aikido_zen import protect
35
from aikido_zen.background_process import get_comms, reset_comms
6+
from aikido_zen.helpers.token import get_token_from_env
47

58

69
def test_protect_with_django(monkeypatch, caplog):
@@ -9,3 +12,8 @@ def test_protect_with_django(monkeypatch, caplog):
912
assert "starting" in caplog.text
1013
reset_comms()
1114
assert get_comms() == None
15+
16+
17+
def test_protect_sets_token():
18+
aikido_zen.protect(token="MY_TOKEN_1")
19+
assert get_token_from_env().token == "MY_TOKEN_1"

0 commit comments

Comments
 (0)