Skip to content

Commit

Permalink
add simple settings read from .env test
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikmonsen committed Nov 21, 2023
1 parent 620fa99 commit 7fad687
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@


from functools import lru_cache

from pydantic import Extra
from pydantic import ConfigDict
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
"""Loads settings from .env file"""
model_config = ConfigDict(extra='allow')

UPLOAD_FOLDER: str = 'static'

# Should be defined in a .env file
Expand All @@ -25,13 +26,8 @@ class Settings(BaseSettings):
GIELLADETECT_LANGS: str = ""
CUSTOM_PATH: str = ""

class Config:
"""Specify name of settings file"""
env_file = '.env'
extra = Extra.allow


settings = Settings()
settings = Settings(_env_file='.env')


@lru_cache()
Expand Down
20 changes: 20 additions & 0 deletions test/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Test that settings are loaded correctly"""

from src.settings import Settings


def test_config():
settings = Settings(_env_file='.env.example')
"""Test that settings are loaded correctly"""
assert settings.MOUNT_FOLDER == "/tmp/pdf_dir"
assert settings.MAX_FILE_SIZE_MB == 123
assert settings.ENVIRONMENT == "local"
assert settings.LANGUAGES == "mul,eng,nob"
assert settings.REGISTRY_FILE == ""
assert settings.REGISTRY_HOST == ""
assert settings.REGISTRY_USER == ""
assert settings.REGISTRY_DATABASE == ""
assert settings.REGISTRY_PASSWORD == ""
assert settings.USE_GIELLADETECT is False
assert settings.GIELLADETECT_LANGS == ""
assert settings.CUSTOM_PATH == ""

0 comments on commit 7fad687

Please sign in to comment.