-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
Merged
Merged
testing env support #288
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c20131
testing env support
Shending-Help 2aeed3e
verify that a connection can be established with the port
Shending-Help 90e4221
moving unit tests to a seperate folder, reseting variables set during…
Shending-Help abe8a2a
auto importing robyn settings
Shending-Help f2c974f
deleting the test_session fixture not needed
Shending-Help b6b2c55
changing unit tests accordingly
Shending-Help File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
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 = "PORT=8080" | ||
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
|
||
|
||
def test_parser(env_file): | ||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
assert list(parser(config_path = env_file)) == [['PORT', '8080']] | ||
|
||
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' | ||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_get_request(test_session, env_file): | ||
sansyrox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dir = path / "test_dir" | ||
env_file = dir / "robyn.env" | ||
load_vars(variables = parser(config_path = env_file)) | ||
port = os.environ['PORT'] | ||
BASE_URL = f"http://127.0.0.1:{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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Try setting
ROBYN_URL
andROBYN_PORT
directly throughload_vars()
?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.
but shouldn't that be left to the user, it won't always be the case that a user will provide a PORT and a URL in robyn.env but even if he did those vars will be loaded automatically and he can just assign them to a variable and use them
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.
@Shending-Help , actually the way the env file is supposed to behave in my mind is that if the user sets a config then they don't have to worry about altering the code.
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.
but that wouldn't be the case for other variables such as a token or db credentials so should we just auto invoke the variables that are relevant for robyn and other variables get left for the user to decide what to do with them?
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.
No no. What I mean is if you set
ROBYN_PORT
in the test then it will be automatically present in the environment. That way you don't need to set that variable in the fixture.If that still doesn't make sense then we can hop on a quick call.
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.
i think i understand what you mean i will get on it and check with you afterwards
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.
Perfect!
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.
i think this should be it, I changed the content written in robyn.env to include
ROBYN_PORT
andROBYN_URL
and it worked, i also deleted the fixture i created in conftest.py since it is of no use now.