From b96b684b71a29b5b6d292e5da3236b933e30b32a Mon Sep 17 00:00:00 2001 From: Francis Date: Fri, 4 Feb 2022 12:21:30 +0900 Subject: [PATCH] 0.1.19 --- pyproject.toml | 2 +- rcs_pydantic/enums.py | 2 +- rcs_pydantic/errors.py | 4 ++++ rcs_pydantic/scheme.py | 2 +- tests/factory.py | 2 +- tests/test_rcs_pydantic.py | 5 +++++ 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 623b631..ef5fe58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "rcs-pydantic" -version = "0.1.18" +version = "0.1.19" description = "" authors = ["xncbf "] keywords = ["pydantic", "rcs", "fastapi"] diff --git a/rcs_pydantic/enums.py b/rcs_pydantic/enums.py index d41da74..eeaddee 100644 --- a/rcs_pydantic/enums.py +++ b/rcs_pydantic/enums.py @@ -68,7 +68,7 @@ class BillEnum(IntEnum): class EventTypeEnum(Enum): MESSAGE: str = "message" RESPONSE: str = "response" - NEW_USER: str = "newuser" + NEW_USER: str = "newUser" class RCSMessageEnum(Enum): diff --git a/rcs_pydantic/errors.py b/rcs_pydantic/errors.py index 4e1696a..f05e890 100644 --- a/rcs_pydantic/errors.py +++ b/rcs_pydantic/errors.py @@ -9,6 +9,10 @@ def _missing_(cls, value): return item return super()._missing_(value) + @classmethod + def has_value(cls, value): + return value in [x[0] for x in cls._value2member_map_] + class LegacyErrorCodeEnum(str, TupleEnum): pass diff --git a/rcs_pydantic/scheme.py b/rcs_pydantic/scheme.py index dd9bac0..63e818b 100644 --- a/rcs_pydantic/scheme.py +++ b/rcs_pydantic/scheme.py @@ -539,7 +539,7 @@ def check_message_body(cls, v, values, **kwargs): userContact: str = Field(max_length=40) chatbotId: str = Field(max_length=40) - timestamp: str = Field(regex=r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{2}$") + timeStamp: str = Field(regex=r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}\+\d{2}$") class SendInfo(BaseModel): diff --git a/tests/factory.py b/tests/factory.py index e8b0da9..34cbb68 100644 --- a/tests/factory.py +++ b/tests/factory.py @@ -290,7 +290,7 @@ class Meta: chatbotId: str = factory.LazyAttribute(lambda n: fake.sentence(nb_words=10)[:40]) @factory.lazy_attribute - def timestamp(self) -> str: + def timeStamp(self) -> str: t = datetime.now() s: str = t.strftime("%Y-%m-%dT%H:%M:%S.%f") s = s[:-3] diff --git a/tests/test_rcs_pydantic.py b/tests/test_rcs_pydantic.py index 02b836b..dd29d30 100644 --- a/tests/test_rcs_pydantic.py +++ b/tests/test_rcs_pydantic.py @@ -1,5 +1,6 @@ from faker import Faker +from rcs_pydantic.errors import ErrorCodeEnum from rcs_pydantic.main import RcsMessage from . import factory @@ -15,3 +16,7 @@ def test_rcs_message(): buttons=[factory.ButtonInfoFactory()], ) rcs_message.send() + + +def test_tuple_enum_has_value(): + assert ErrorCodeEnum.has_value(ErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0])