Skip to content
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

PTFE-693: unit test for settings class #309

Merged
merged 22 commits into from
Aug 4, 2023
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/unit/models/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import tempfile
from pathlib import Path

from pytest import fixture

from runner_manager.models.settings import (
ConfigFile,
Settings,
yaml_config_settings_source,
)


def test_settings_default_values():
settings = Settings()
assert settings.name == "runner-manager"
assert settings.redis_om_url == os.getenv("REDIS_OM_URL")
tcarmet marked this conversation as resolved.
Show resolved Hide resolved
tcarmet marked this conversation as resolved.
Show resolved Hide resolved
assert settings.github_base_url == os.getenv("GITHUB_BASE_URL")


@fixture
Abubakarr99 marked this conversation as resolved.
Show resolved Hide resolved
def temp_yaml_file():
yaml_data = """
name: test-runner-manager
redis_om_url: redis://localhost:6379/0
github_base_url: https://github.com
"""
yaml_file = tempfile.NamedTemporaryFile(mode="w", delete=False)
yaml_file.write(yaml_data)
return yaml_file.name


def test_yaml_config(temp_yaml_file):
os.environ['CONFIG_FILE'] = temp_yaml_file
# settings should automatically look for the config file
# environment variable and load the file if it exists
settings = Settings()
yaml_file = yaml.load(temp_yaml_file)

Check failure on line 38 in tests/unit/models/test_settings.py

View workflow job for this annotation

GitHub Actions / Trunk Check

pyright(reportUndefinedVariable)

[new] "yaml" is not defined
assert settings["name"] == yaml_file["name"]

Check failure on line 39 in tests/unit/models/test_settings.py

View workflow job for this annotation

GitHub Actions / Trunk Check

pyright(reportGeneralTypeIssues)

[new] "__getitem__" method not defined on type "Settings"
assert settings["redis_om_url"] == yaml_file["redis_om_url"]

Check failure on line 40 in tests/unit/models/test_settings.py

View workflow job for this annotation

GitHub Actions / Trunk Check

pyright(reportGeneralTypeIssues)

[new] "__getitem__" method not defined on type "Settings"
assert settings["github_base_url"] == yaml_file["github_base_url"]

Check failure on line 41 in tests/unit/models/test_settings.py

View workflow job for this annotation

GitHub Actions / Trunk Check

pyright(reportGeneralTypeIssues)

[new] "__getitem__" method not defined on type "Settings"
tcarmet marked this conversation as resolved.
Show resolved Hide resolved



def test_env_file():
os.environ["REDIS_OM_URL"] = "redis://localhost:6379/0"
os.environ["GITHUB_BASE_URL"] = "https://github.com"
os.environ["NAME"] = "test-runner-manager"
settings = Settings()
assert settings.name == os.getenv("NAME")
assert settings.redis_om_url == os.getenv("REDIS_OM_URL")
assert settings.github_base_url == os.getenv("GITHUB_BASE_URL")
Loading