-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement testing env support (#288)
* testing env support * verify that a connection can be established with the port * moving unit tests to a seperate folder, reseting variables set during testing * auto importing robyn settings * deleting the test_session fixture not needed * changing unit tests accordingly
- Loading branch information
1 parent
549723a
commit 7d35952
Showing
4 changed files
with
71 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# from integration_tests.conftest import test_session | ||
from robyn.env_populator import load_vars, parser | ||
import pathlib | ||
import os | ||
import pytest | ||
import requests | ||
|
||
|
||
|
||
path = pathlib.Path(__file__).parent | ||
|
||
#create robyn.env before test and delete it after test | ||
@pytest.fixture | ||
def env_file(): | ||
CONTENT = """ROBYN_PORT=8080 | ||
ROBYN_URL=127.0.1.1""" | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
env_file.write_text(CONTENT) | ||
yield | ||
env_file.unlink() | ||
os.unsetenv("PORT") | ||
|
||
# this tests if a connection can be made to the server with the correct port imported from the env file | ||
def test_env_population(dev_session, env_file): | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
load_vars(variables = parser(config_path = env_file)) | ||
PORT = os.environ['ROBYN_PORT'] | ||
HOST = os.environ['ROBYN_URL'] | ||
BASE_URL = f"http://{HOST}:{PORT}" | ||
res = requests.get(f"{BASE_URL}") | ||
assert res.status_code == 200 |
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,34 @@ | ||
from robyn.env_populator import load_vars, parser | ||
import pathlib | ||
import os | ||
import pytest | ||
|
||
|
||
|
||
|
||
path = pathlib.Path(__file__).parent | ||
|
||
#create robyn.env before test and delete it after test | ||
@pytest.fixture | ||
def env_file(): | ||
CONTENT = """ROBYN_PORT=8080 | ||
ROBYN_URL=127.0.1.1""" | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
env_file.write_text(CONTENT) | ||
yield | ||
env_file.unlink() | ||
os.unsetenv("ROBYN_PORT") | ||
os.unsetenv("ROBYN_URL") | ||
|
||
def test_parser(env_file): | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
assert list(parser(config_path = env_file)) == [['ROBYN_PORT', '8080'], ['ROBYN_URL', '127.0.1.1']] | ||
|
||
def test_load_vars(env_file): | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
load_vars(variables = parser(config_path = env_file)) | ||
assert os.environ['ROBYN_PORT'] == '8080' | ||
assert os.environ['ROBYN_URL'] == '127.0.1.1' |