-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c99fbe
commit 2268494
Showing
4 changed files
with
80 additions
and
14 deletions.
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
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,40 @@ | ||
""" | ||
Uvicorn settings | ||
""" | ||
|
||
from pydantic import IPvAnyAddress | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
|
||
class UvicornSettings(BaseSettings): | ||
"""Define UVICORN configuration model. | ||
Constructor will attempt to determine the values of any fields not passed | ||
as keyword arguments by reading from the environment. Default values will | ||
still be used if the matching environment variable is not set. | ||
Environment variables: | ||
* UVICORN_HOST | ||
* UVICORN_PORT | ||
* UVICORN_LOG_LEVEL | ||
* UVICORN_RELOAD | ||
Attributes: | ||
HOST (IPvAnyAddress): Host to run application on. | ||
PORT (int): Port to run application on. | ||
LOG_LEVEL (str): Logging level. | ||
RELOAD (bool): Enable/disable auto-reload. | ||
Resources: | ||
1. https://docs.pydantic.dev/latest/usage/pydantic_settings/ | ||
""" | ||
|
||
HOST: IPvAnyAddress = IPvAnyAddress("127.0.0.1") | ||
PORT: int = 8000 | ||
LOG_LEVEL: str = "info" | ||
RELOAD: bool = False | ||
|
||
model_config = SettingsConfigDict( | ||
case_sensitive=True, | ||
env_prefix="UVICORN_", | ||
) |
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,21 @@ | ||
""" | ||
Uvicorn settings tests. | ||
""" | ||
from template.settings.uvicorn_settings import UvicornSettings | ||
|
||
|
||
class TestUvicornSettings: | ||
""" | ||
Test suite for Uvicorn Settings | ||
""" | ||
|
||
def test_uvicorn_default_values(self): | ||
""" | ||
Test API default values | ||
""" | ||
settings = UvicornSettings() | ||
|
||
assert not settings.RELOAD | ||
assert settings.LOG_LEVEL | ||
assert settings.PORT | ||
assert settings.HOST |