-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Code0x58/test-isolation
Test isolation
- Loading branch information
Showing
9 changed files
with
139 additions
and
83 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
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
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 |
---|---|---|
@@ -1,37 +1,47 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from notebooker.web.app import setup_env_vars | ||
from notebooker.web.config import settings | ||
|
||
|
||
def test_setup_env_vars(): | ||
set_vars = setup_env_vars() | ||
try: | ||
assert os.getenv("PORT") == "11828" | ||
assert os.getenv("MONGO_HOST") == "localhost" | ||
finally: | ||
for var in set_vars: | ||
del os.environ[var] | ||
@pytest.fixture | ||
def dev_config(): | ||
return settings.DevConfig | ||
|
||
|
||
def test_setup_env_vars_override_default(): | ||
os.environ["MONGO_HOST"] = "override" | ||
set_vars = setup_env_vars() | ||
try: | ||
assert os.getenv("PORT") == "11828" | ||
assert os.getenv("MONGO_HOST") == "override" | ||
finally: | ||
for var in set_vars: | ||
del os.environ[var] | ||
del os.environ["MONGO_HOST"] | ||
@pytest.fixture | ||
def prod_config(): | ||
return settings.ProdConfig | ||
|
||
|
||
def safe_setup_env_vars(): | ||
"""Return a copy of the environment after running setup_env_vars.""" | ||
original_env = os.environ.copy() | ||
|
||
def test_setup_env_vars_prod(): | ||
os.environ["NOTEBOOKER_ENVIRONMENT"] = "Prod" | ||
set_vars = setup_env_vars() | ||
try: | ||
assert os.getenv("PORT") == "11828" | ||
assert os.getenv("MONGO_HOST") == "a-production-mongo-cluster" | ||
setup_env_vars() | ||
return os.environ.copy() | ||
finally: | ||
for var in set_vars: | ||
del os.environ[var] | ||
del os.environ["NOTEBOOKER_ENVIRONMENT"] | ||
os.environ.clear() | ||
os.environ.update(original_env) | ||
|
||
def test_setup_env_vars(dev_config): | ||
env = safe_setup_env_vars() | ||
assert env["PORT"] == str(dev_config.PORT) | ||
assert env["MONGO_HOST"] == str(dev_config.MONGO_HOST) | ||
|
||
|
||
def test_setup_env_vars_override_default(monkeypatch, dev_config): | ||
monkeypatch.setenv("MONGO_HOST","override") | ||
env = safe_setup_env_vars() | ||
assert env["PORT"] == str(dev_config.PORT) | ||
assert env["MONGO_HOST"] == "override" | ||
|
||
|
||
def test_setup_env_vars_prod(monkeypatch, prod_config): | ||
monkeypatch.setenv("NOTEBOOKER_ENVIRONMENT", "Prod") | ||
env = safe_setup_env_vars() | ||
assert env["PORT"] == str(prod_config.PORT) | ||
assert env["MONGO_HOST"] == str(prod_config.MONGO_HOST) |