Skip to content

Commit

Permalink
feat: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Oct 11, 2023
1 parent 1e1b6f8 commit 52e04f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Dict
from pydantic import TypeAdapter

from pydantic_settings import BaseSettings, SettingsConfigDict
Expand All @@ -22,6 +23,7 @@ class Settings(BaseSettings):
kc_admin_client_id: str = ""
kc_admin_client_secret: str = ""
kc_realm_url: str = ""
jwt_opts: Dict[str, bool | int] = {}

def __init__(self, **data):
super().__init__(**data)
Expand Down
23 changes: 23 additions & 0 deletions tests/app/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest
from config import Settings


def test_jwt_opts_valid_values():
mock_config = {
"jwt_opts_test1": "true",
"jwt_opts_test2": "true",
"jwt_opts_test3": "12",
}
settings = Settings(**mock_config)
assert settings.jwt_opts == {"test1": True, "test2": True, "test3": 12}


def test_jwt_opts_invalid_values():
mock_config = {
"jwt_opts_test1": "not a bool or int",
"jwt_opts_test2": "true",
"jwt_opts_test3": "12",
}
with pytest.raises(Exception) as e:
settings = Settings(**mock_config)

Check failure on line 22 in tests/app/test_config.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

tests/app/test_config.py:22:9: F841 Local variable `settings` is assigned to but never used
assert "validation error" in str(e.value)

0 comments on commit 52e04f8

Please sign in to comment.