From ab575791855c4eba34c2dfe90c3c1f1fd249aea8 Mon Sep 17 00:00:00 2001 From: Francis Date: Mon, 7 Feb 2022 19:24:33 +0900 Subject: [PATCH 1/2] UPDATE: readme --- README.md | 153 ++++++++++++++++++++++++++++++++----- rcs_pydantic/__init__.py | 4 + rcs_pydantic/exceptions.py | 15 ++++ rcs_pydantic/main.py | 4 + 4 files changed, 159 insertions(+), 17 deletions(-) create mode 100644 rcs_pydantic/exceptions.py diff --git a/README.md b/README.md index 4474f91..269b4ad 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,13 @@ - [Introduce](#introduce) - [Installation](#installation) - [Quick start](#quick-start) + - [제공되는 항목](#제공되는-항목) + - [제공되는 데이터 구조체](#제공되는-데이터-구조체) + - [제공되는 데이터 관련 Enum](#제공되는-데이터-관련-enum) + - [제공되는 에러 코드 Enum](#제공되는-에러-코드-enum) - [Features](#features) + - [RcsMessage](#rcsmessage) + - [MessageException](#messageexception) - [Contribution](#contribution) ## Introduce @@ -39,18 +45,17 @@ from rcs_pydantic import MessageInfo, RcsMessage message_info = { "replyId": "B01RDSFR.KcNNLk67ui.FDSAF432153214", - "eventType":"message", - "messageBody": {"textMessage": "안녕하세요?"}, + "eventType":"newUser", + "displayText": "안녕", "userContact":"01012341234", "chatbotId":"0212351235", - "timestamp": "2020-03-03T04:43:55.867+09" + "timeStamp": "2020-03-03T04:43:55.867+09" } rcs = { - "message_base_id": "SCS00000", + "message_base_id": "SS000000", "service_type": "RCSSMS", - "header": "0", - "cdr_id": "KT_rcsid", + "agency_id": "", "body": { "title": "타이틀", "description": "일반 RCSSMS 테스트 메시지 입니다." @@ -64,34 +69,148 @@ rcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs) ```sh >>> print(rcs_message.send_info) common=CommonInfo( - msgId='B01RDSFR.KcNNLk67ui.FDSAF432153214', + msgId='4be0072f-0f05-4b3a-adc8-90d7ef309c53', userContact='01012341234', scheduleType=, - msgGroupId=None, msgServiceType= ) rcs=RcsInfo( chatbotId='0212351235', - agencyId='ktbizrcs', - messagebaseId='SCS00000', + agencyId='', + messagebaseId='SS000000', serviceType=, expiryOption=, header=, - footer=None, - cdrId='KT_rcsid', copyAllowed=True, body=RcsSMSBody(title='타이틀', description='일반 RCSSMS 테스트 메시지 입니다.'), - buttons=None, - chipLists=None, - replyId=None ) >>> ``` +## 제공되는 항목 + +국내 통신사 RCS 문서에서 제공되는 모든 데이터 구조체를 지원합니다. + +### 제공되는 데이터 구조체 + +```python +RcsSMSBody +RcsLMSBody +RcsMMSBody +RcsCHATBody +RcsTMPLBody +RcsSMSCarouselBody +RcsLMSCarouselBody +RcsMMSCarouselBody +RcsCHATCarouselBody +LocationInfo +ShowLocationInfo +OpenUrlInfo +CreateCalendarEventInfo +CopyToClipboardInfo +ComposeTextMessageInfo +DialPhoneNumberInfo +UrlActionInfo +LocalBrowserActionInfo +MapActionInfo +CalendarActionInfo +ClipboardActionInfo +ComposeActionInfo +DialActionInfo +PostbackInfo +ActionInfo +SuggestionInfo +ButtonInfo +CommonInfo +RcsInfo +LegacyInfo +StatusInfo +QuerystatusInfo +ErrorInfo +ResponseErrorInfo +ResponseInfo +MessageInfo +SendInfo +TokenInfo +``` + +### 제공되는 데이터 관련 Enum + +```python +EventTypeEnum +RCSMessageEnum +MessageEnum +MessageStatusEnum +MnoInfoEnum +BillEnum +MessageServiceTypeEnum +ServiceTypeEnum +LegacyServiceTypeEnum +ScheduleTypeEnum +ExpiryOptionEnum +HeaderEnum +ActionEnum +``` + +### 제공되는 에러 코드 Enum + +```python +LegacyErrorCodeEnum +ErrorCodeEnum +MaaPErrorCodeEnum +RcsBizCenterErrorCodeEnum +KTErrorCodeEnum +RCSErrorCode +``` + ## Features -TODO +### RcsMessage + +`RcsMessage` 클래스는 메세지 전송을 위한 `SendInfo` 구조체를 만듭니다. + +```py +from rcs_pydantic import MessageInfo, RcsMessage + +message_info = { + "replyId": "B01RDSFR.KcNNLk67ui.FDSAF432153214", + "eventType":"newUser", + "displayText": "안녕", + "userContact":"01012341234", + "chatbotId":"0212351235", + "timeStamp": "2020-03-03T04:43:55.867+09" +} + +rcs = { + "message_base_id": "SS000000", + "service_type": "RCSSMS", + "agency_id": "", + "body": { + "title": "타이틀", + "description": "일반 RCSSMS 테스트 메시지 입니다." + } +} + + +rcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs) +``` + +### MessageException + +`MessageException` 예외 클래스는 여러 종류의 모든 error 코드를 포함하는 예외 클래스입니다. + +```python +from rcs_pydantic.exceptions import MessageException + +raise MessageException(40003) +``` ## Contribution -TODO +이 프로젝트는 기여를 환영합니다! + +패치를 제출하기 전에 issue 티켓을 먼저 제출해주세요. + +Pull request 는 `main` 브랜치로 머지되며 항상 사용 가능한 상태로 유지해야 합니다. + +모든 테스트 코드를 통과한 뒤 리뷰한 후 머지됩니다. diff --git a/rcs_pydantic/__init__.py b/rcs_pydantic/__init__.py index 5b4e217..b2aa6a3 100644 --- a/rcs_pydantic/__init__.py +++ b/rcs_pydantic/__init__.py @@ -24,6 +24,10 @@ "RcsMMSBody", "RcsCHATBody", "RcsTMPLBody", + "RcsSMSCarouselBody", + "RcsLMSCarouselBody", + "RcsMMSCarouselBody", + "RcsCHATCarouselBody", "LocationInfo", "ShowLocationInfo", "OpenUrlInfo", diff --git a/rcs_pydantic/exceptions.py b/rcs_pydantic/exceptions.py new file mode 100644 index 0000000..91825b4 --- /dev/null +++ b/rcs_pydantic/exceptions.py @@ -0,0 +1,15 @@ +from . import errors + + +class MessageException(Exception): + def __init__(self, message: int): + if errors.ErrorCodeEnum.has_value(message): + self.message = errors.ErrorCodeEnum(message).name.lower() + elif errors.MaaPErrorCodeEnum.has_value(message): + self.message = errors.MaaPErrorCodeEnum(message).name.lower() + elif errors.RcsBizCenterErrorCodeEnum.has_value(message): + self.message = errors.RcsBizCenterErrorCodeEnum(message).name.lower() + elif errors.KTErrorCodeEnum.has_value(message): + self.message = errors.KTErrorCodeEnum(message).name.lower() + else: + self.message = "unknown" diff --git a/rcs_pydantic/main.py b/rcs_pydantic/main.py index 9d9044c..f2894ba 100644 --- a/rcs_pydantic/main.py +++ b/rcs_pydantic/main.py @@ -16,6 +16,10 @@ def __init__( scheme.RcsMMSBody, scheme.RcsCHATBody, scheme.RcsTMPLBody, + scheme.RcsSMSCarouselBody, + scheme.RcsLMSCarouselBody, + scheme.RcsMMSCarouselBody, + scheme.RcsCHATCarouselBody, ], agency_id: Optional[str] = None, message_base_id: Union[enums.MessageEnum, enums.RCSMessageEnum] = enums.MessageEnum.SMS, From 53d3061e414d165555ede45c943227914d551e48 Mon Sep 17 00:00:00 2001 From: Francis Date: Mon, 7 Feb 2022 19:40:06 +0900 Subject: [PATCH 2/2] code coverage --- rcs_pydantic/errors.py | 1 - tests/test_rcs_pydantic.py | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/rcs_pydantic/errors.py b/rcs_pydantic/errors.py index f05e890..0dc10bd 100644 --- a/rcs_pydantic/errors.py +++ b/rcs_pydantic/errors.py @@ -7,7 +7,6 @@ def _missing_(cls, value): for item in cls: if item.value[0] == value: return item - return super()._missing_(value) @classmethod def has_value(cls, value): diff --git a/tests/test_rcs_pydantic.py b/tests/test_rcs_pydantic.py index dd29d30..57de51b 100644 --- a/tests/test_rcs_pydantic.py +++ b/tests/test_rcs_pydantic.py @@ -1,6 +1,8 @@ +import pytest from faker import Faker -from rcs_pydantic.errors import ErrorCodeEnum +from rcs_pydantic.errors import ErrorCodeEnum, KTErrorCodeEnum, MaaPErrorCodeEnum, RcsBizCenterErrorCodeEnum +from rcs_pydantic.exceptions import MessageException from rcs_pydantic.main import RcsMessage from . import factory @@ -12,11 +14,41 @@ def test_rcs_message(): rcs_message = RcsMessage( factory.MessageInfoFactory(), body=factory.RcsSMSBodyFactory(), - footer=None, buttons=[factory.ButtonInfoFactory()], + agency_id="abc", + expiry_option=2, + header="1", + footer="010-0000-0000", + cdr_id="abc", + copy_allowed=True, ) rcs_message.send() def test_tuple_enum_has_value(): assert ErrorCodeEnum.has_value(ErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0]) + + +def test_error_code_message_exception(): + with pytest.raises(MessageException): + raise MessageException(ErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0]) + + +def test_maap_error_code_message_exception(): + with pytest.raises(MessageException): + raise MessageException(MaaPErrorCodeEnum.ACTION_BUTTON_PERMISSION_ERROR.value[0]) + + +def test_rcsbiz_error_code_message_exception(): + with pytest.raises(MessageException): + raise MessageException(RcsBizCenterErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0]) + + +def test_kt_error_code_message_exception(): + with pytest.raises(MessageException): + raise MessageException(KTErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0]) + + +def test_unknown_error_code_message_exception(): + with pytest.raises(MessageException): + raise MessageException(123)