feat: move timezone preference to config file (#2096)
BREAKING CHANGE: The timezone preference moved to the configuration file.
This commit is contained in:
parent
8ef82d798e
commit
9b3207b8a4
15 changed files with 73 additions and 15 deletions
|
@ -5,6 +5,11 @@ from typing import TYPE_CHECKING, Any, List, Optional, Sequence, Union
|
|||
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, validator
|
||||
from typing_extensions import Annotated, Literal
|
||||
|
||||
try:
|
||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||
except ImportError:
|
||||
from backports.zoneinfo import ZoneInfo, ZoneInfoNotFoundError # type: ignore
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pydantic.typing import AnyClassMethod
|
||||
|
||||
|
@ -38,9 +43,21 @@ class GeneralConfig(BaseModel):
|
|||
public_url: AnyHttpUrl
|
||||
api_key: str
|
||||
|
||||
timezone: str = "UTC"
|
||||
|
||||
# Validators
|
||||
_public_url_no_trailing_slash = no_trailing_slash_validator("public_url")
|
||||
|
||||
@validator("timezone")
|
||||
@classmethod
|
||||
def _validate_timezone(cls, value: str) -> str:
|
||||
try:
|
||||
ZoneInfo(value)
|
||||
except ZoneInfoNotFoundError as exception:
|
||||
raise ValueError(f"invalid timezone '{value}'") from exception
|
||||
|
||||
return value
|
||||
|
||||
|
||||
# StorageConfig
|
||||
########################################################################################
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Please do not edit this file, edit the setup.py file!
|
||||
# This file is auto-generated by tools/extract_requirements.py.
|
||||
backports.zoneinfo>=0.2.1,<0.3;python_version<'3.9'
|
||||
click~=8.0.4
|
||||
loguru==0.6.0
|
||||
pydantic>=1.7.4,<1.11
|
||||
|
|
|
@ -10,6 +10,7 @@ setup(
|
|||
packages=find_packages(exclude=["*tests*", "*fixtures*"]),
|
||||
package_data={"": ["py.typed"]},
|
||||
install_requires=[
|
||||
"backports.zoneinfo>=0.2.1,<0.3;python_version<'3.9'",
|
||||
"click~=8.0.4",
|
||||
"loguru==0.6.0",
|
||||
"pydantic>=1.7.4,<1.11",
|
||||
|
@ -17,6 +18,7 @@ setup(
|
|||
],
|
||||
extras_require={
|
||||
"dev": [
|
||||
"types-backports",
|
||||
"types-pyyaml",
|
||||
],
|
||||
},
|
||||
|
|
|
@ -6,10 +6,22 @@ from libretime_shared.config._models import (
|
|||
AudioMP3,
|
||||
AudioOGG,
|
||||
AudioOpus,
|
||||
GeneralConfig,
|
||||
StreamConfig,
|
||||
)
|
||||
|
||||
|
||||
def test_general_config_timezone():
|
||||
defaults = {
|
||||
"public_url": "http://localhost:8080",
|
||||
"api_key": "api_key",
|
||||
}
|
||||
GeneralConfig(**defaults, timezone="UTC")
|
||||
GeneralConfig(**defaults, timezone="Europe/Berlin")
|
||||
with pytest.raises(ValidationError):
|
||||
GeneralConfig(**defaults, timezone="Europe/Invalid")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"audio",
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue