Browse Source

Add tests for variants of `settings/app3`, fix config and add pv1 version

pull/14413/head
Yurii Motov 8 months ago
parent
commit
c9cffa27de
  1. 5
      docs_src/settings/app03/config.py
  2. 10
      docs_src/settings/app03/config_pv1.py
  3. 5
      docs_src/settings/app03_an_py39/config.py
  4. 10
      docs_src/settings/app03_an_py39/config_pv1.py
  5. 45
      tests/test_tutorial/test_settings/test_app03.py

5
docs_src/settings/app03/config.py

@ -1,4 +1,4 @@
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
@ -6,5 +6,4 @@ class Settings(BaseSettings):
admin_email: str
items_per_user: int = 50
class Config:
env_file = ".env"
model_config = SettingsConfigDict(env_file=".env")

10
docs_src/settings/app03/config_pv1.py

@ -0,0 +1,10 @@
from pydantic import BaseSettings
class Settings(BaseSettings):
app_name: str = "Awesome API"
admin_email: str
items_per_user: int = 50
class Config:
env_file = ".env"

5
docs_src/settings/app03_an_py39/config.py

@ -1,4 +1,4 @@
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
@ -6,5 +6,4 @@ class Settings(BaseSettings):
admin_email: str
items_per_user: int = 50
class Config:
env_file = ".env"
model_config = SettingsConfigDict(env_file=".env")

10
docs_src/settings/app03_an_py39/config_pv1.py

@ -0,0 +1,10 @@
from pydantic import BaseSettings
class Settings(BaseSettings):
app_name: str = "Awesome API"
admin_email: str
items_per_user: int = 50
class Config:
env_file = ".env"

45
tests/test_tutorial/test_settings/test_app03.py

@ -0,0 +1,45 @@
import importlib
from types import ModuleType
import pytest
from pytest import MonkeyPatch
from ...utils import needs_py39, needs_pydanticv1, needs_pydanticv2
@pytest.fixture(
name="mod_path",
params=[
pytest.param("app03"),
pytest.param("app03_an"),
pytest.param("app03_an_py39", marks=needs_py39),
],
)
def get_mod_path(request: pytest.FixtureRequest):
mod_path = f"docs_src.settings.{request.param}"
return mod_path
@pytest.fixture(name="main_mod")
def get_main_mod(mod_path: str) -> ModuleType:
main_mod = importlib.import_module(f"{mod_path}.main")
return main_mod
@needs_pydanticv2
def test_settings(main_mod: ModuleType, monkeypatch: MonkeyPatch):
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]")
settings = main_mod.get_settings()
assert settings.app_name == "Awesome API"
assert settings.admin_email == "[email protected]"
assert settings.items_per_user == 50
@needs_pydanticv1
def test_settings_pv1(mod_path: str, monkeypatch: MonkeyPatch):
monkeypatch.setenv("ADMIN_EMAIL", "[email protected]")
config_mod = importlib.import_module(f"{mod_path}.config_pv1")
settings = config_mod.Settings()
assert settings.app_name == "Awesome API"
assert settings.admin_email == "[email protected]"
assert settings.items_per_user == 50
Loading…
Cancel
Save