-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3077-get-otp-from-env' into develop
- Loading branch information
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
|
||
import pytest | ||
from tests.data_for_tests.otp import OTP | ||
|
||
from common.common_consts import AGENT_OTP_ENVIRONMENT_VARIABLE | ||
from infection_monkey.model import OTP_FLAG | ||
from infection_monkey.monkey import InfectionMonkey | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def configure_environment_variables(monkeypatch): | ||
monkeypatch.setenv(AGENT_OTP_ENVIRONMENT_VARIABLE, OTP) | ||
monkeypatch.setenv(OTP_FLAG, True) | ||
|
||
|
||
def test_get_otp(monkeypatch): | ||
assert InfectionMonkey._get_otp() == OTP | ||
assert AGENT_OTP_ENVIRONMENT_VARIABLE not in os.environ | ||
|
||
|
||
def test_get_otp__no_otp(monkeypatch): | ||
monkeypatch.delenv(AGENT_OTP_ENVIRONMENT_VARIABLE) | ||
with pytest.raises(Exception): | ||
InfectionMonkey._get_otp() | ||
|
||
|
||
def test_get_otp__feature_flag_disabled(monkeypatch): | ||
try: | ||
monkeypatch.delenv(OTP_FLAG) | ||
except KeyError: | ||
pass | ||
|
||
# No need for a constant, this code is testing a feature flag that will be removed. | ||
assert InfectionMonkey._get_otp() == "PLACEHOLDER_OTP" |