Skip to content

Conversation

@dlozina
Copy link
Contributor

@dlozina dlozina commented May 2, 2022

  • Added SMS channel

  • Added Integration tests for SMS channel

  • Added model tests for SMS channel

@dlozina dlozina requested a review from kilicluka May 2, 2022 10:18

if date_time_format > datetime.now() + timedelta(days=cls._MAX_TIME_LIMIT):
raise ValueError(
"Scheduled message must me sooner than 180 days from today"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Scheduled message must me sooner than 180 days from today"
"Scheduled message must be sooner than 180 days from today"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

raise ValueError(
"Scheduled message must me sooner than 180 days from today"
)
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

def convert_time_to_correct_format(cls, value) -> str:
date_time_format = cls.convert_to_date_time_format(value)

return date_time_format.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move "%Y-%m-%dT%H:%M:%S.%fZ" into a class variable and use it here and in the convert_time_to_correct_format_validate_limit method.

class DateTimeValidator:
    _MAX_TIME_LIMIT = 180
    _EXPECTED_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

SMS_URL_TEMPLATE_VERSION_2 = "/sms/2/"

@staticmethod
def validate_query_parameter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is the same here and in the MMSChannel, best to extract it into the Channel class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

**kwargs
) -> Type[ResponseBase]:

if raw_response.status_code in (HTTPStatus.OK,):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if raw_response.status_code in (HTTPStatus.OK,):
if raw_response.status_code == HTTPStatus.OK:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, this was bad 😞


def get_inbound_sms_messages(
self,
query_parameters: Union[GetInboundSMSMessagesQueryParameters, Dict] = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default mutable argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚔️

response = self._client.put(
self.SMS_URL_TEMPLATE_VERSION_1 + "bulks/status",
message.dict(by_alias=True),
PutHeaders(authorization=self._client.auth.api_key),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for the PostHeaders, this should already be present in the default ones, so you can probably omit this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

DAY = "DAY"


class DaysEnum(str, Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this exact enum in mms channel also, might be good to move it into a core models file and reuse it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

to: Optional[Time] = None

@root_validator
def validate_from_and_to(cls, values):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the same method as we have in the mms channel. We can extract it (along with _validate_time_differences) into a FromAndToTimeValidator and reuse it in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, good chunk of code is gone

send_at: Optional[Union[datetime, str]] = None

@validator("send_at")
def convert_send_at_to_correct_format(cls, value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to the convert_send_at_to_correct_format method we use in the mms channel. We could extract the common logic into a Validator class and change this version to:

class RescheduleSMSMessagesMessageBody(Validator, MessageBodyBase):
    ...
    @validator("send_at")
    def convert_send_at_to_correct_format(cls, value):
            if value > datetime.now() + timedelta(days=180):
                raise ValueError(
                    "Scheduled message must me sooner than 180 days from today"
                )
            return super().convert_send_at_to_correct_format(value)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done done, thanks

@dlozina dlozina merged commit baea017 into main May 2, 2022
@dlozina dlozina deleted the add-sms-channel branch May 2, 2022 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants