-
-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing env support #288
testing env support #288
Changes from 5 commits
5c20131
2aeed3e
90e4221
abe8a2a
f2c974f
b6b2c55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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" + "\n" + "ROBYN_URL=127.0.1.1" | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
env_file.write_text(CONTENT) | ||
yield | ||
env_file.unlink() | ||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
os.unsetenv("PORT") | ||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 = "PORT=8080" | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
env_file.write_text(CONTENT) | ||
yield | ||
env_file.unlink() | ||
os.unsetenv("PORT") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be ROBYN_PORT and ROBYN_URL now |
||
|
||
def test_parser(env_file): | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
assert list(parser(config_path = env_file)) == [['PORT', '8080']] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
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['PORT'] == '8080' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use python multiline strings(https://www.w3schools.com/python/gloss_python_multi_line_strings.asp) here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done