Spaces:
Running
Running
Upload 238 files
Browse files- app/core/enums.py +18 -0
- app/social/domain/enums.py +1 -1
- app/social/schemas/tiktok.py +2 -1
- app/social/schemas/youtube.py +2 -1
- tests/test_python310_compat.py +23 -0
app/core/enums.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Enum compatibility helpers for the supported Python 3.10+ runtimes."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from enum import Enum
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class StrEnum(str, Enum):
|
| 9 |
+
"""String-valued enum with the Python 3.11 ``enum.StrEnum`` behavior.
|
| 10 |
+
|
| 11 |
+
MediaRouter supports Python 3.10, where the standard-library StrEnum does
|
| 12 |
+
not exist. Keeping this small compatibility type in one place gives API,
|
| 13 |
+
database, and Pydantic serialization the same string behavior on every
|
| 14 |
+
supported runtime.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
__str__ = str.__str__
|
| 18 |
+
__format__ = str.__format__
|
app/social/domain/enums.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
from
|
| 4 |
|
| 5 |
|
| 6 |
class Provider(StrEnum):
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
from app.core.enums import StrEnum
|
| 4 |
|
| 5 |
|
| 6 |
class Provider(StrEnum):
|
app/social/schemas/tiktok.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
-
from enum import StrEnum
|
| 4 |
from typing import Literal
|
| 5 |
|
| 6 |
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class TikTokPrivacyLevel(StrEnum):
|
| 10 |
PUBLIC_TO_EVERYONE = "PUBLIC_TO_EVERYONE"
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
from typing import Literal
|
| 4 |
|
| 5 |
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
| 6 |
|
| 7 |
+
from app.core.enums import StrEnum
|
| 8 |
+
|
| 9 |
|
| 10 |
class TikTokPrivacyLevel(StrEnum):
|
| 11 |
PUBLIC_TO_EVERYONE = "PUBLIC_TO_EVERYONE"
|
app/social/schemas/youtube.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from datetime import datetime, timezone
|
| 4 |
-
from enum import StrEnum
|
| 5 |
|
| 6 |
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
class YouTubePrivacyStatus(StrEnum):
|
| 10 |
PRIVATE = "private"
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from datetime import datetime, timezone
|
|
|
|
| 4 |
|
| 5 |
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
| 6 |
|
| 7 |
+
from app.core.enums import StrEnum
|
| 8 |
+
|
| 9 |
|
| 10 |
class YouTubePrivacyStatus(StrEnum):
|
| 11 |
PRIVATE = "private"
|
tests/test_python310_compat.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regression tests for the Python 3.10 production runtime contract."""
|
| 2 |
+
|
| 3 |
+
from app.core.enums import StrEnum
|
| 4 |
+
from app.social.domain.enums import JobStatus, Provider
|
| 5 |
+
from app.social.schemas.tiktok import TikTokPrivacyLevel
|
| 6 |
+
from app.social.schemas.youtube import YouTubePrivacyStatus
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_string_enums_do_not_require_python_311_stdlib() -> None:
|
| 10 |
+
class Example(StrEnum):
|
| 11 |
+
VALUE = "value"
|
| 12 |
+
|
| 13 |
+
assert Example.VALUE == "value"
|
| 14 |
+
assert str(Example.VALUE) == "value"
|
| 15 |
+
assert f"{Example.VALUE}" == "value"
|
| 16 |
+
assert Example.VALUE.value == "value"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def test_social_schema_enums_keep_wire_values() -> None:
|
| 20 |
+
assert str(Provider.TIKTOK) == "tiktok"
|
| 21 |
+
assert str(JobStatus.PUBLISHED) == "published"
|
| 22 |
+
assert str(TikTokPrivacyLevel.SELF_ONLY) == "SELF_ONLY"
|
| 23 |
+
assert str(YouTubePrivacyStatus.PRIVATE) == "private"
|