|
| 1 | +import pytest |
| 2 | +from sinch.domains.conversation.models.v1.messages.categories.card.card_message import ( |
| 3 | + CardMessage, |
| 4 | +) |
| 5 | +from sinch.domains.conversation.models.v1.messages.categories.carousel.carousel_message import ( |
| 6 | + CarouselMessage, |
| 7 | +) |
| 8 | +from sinch.domains.conversation.models.v1.messages.categories.choice.choice_message import ( |
| 9 | + ChoiceMessage, |
| 10 | +) |
| 11 | +from sinch.domains.conversation.models.v1.messages.categories.choice.choice_options import ( |
| 12 | + TextChoiceMessage, |
| 13 | +) |
| 14 | +from sinch.domains.conversation.models.v1.messages.categories.location.location_message import ( |
| 15 | + LocationMessage, |
| 16 | +) |
| 17 | +from sinch.domains.conversation.models.v1.messages.categories.media import ( |
| 18 | + MediaProperties, |
| 19 | +) |
| 20 | +from sinch.domains.conversation.models.v1.messages.categories.template import ( |
| 21 | + TemplateMessage, |
| 22 | + TemplateReferenceOmniChannel, |
| 23 | +) |
| 24 | +from sinch.domains.conversation.models.v1.messages.categories.text import ( |
| 25 | + TextMessage, |
| 26 | +) |
| 27 | +from sinch.domains.conversation.models.v1.messages.internal.request import ( |
| 28 | + SendMessageRequestBody, |
| 29 | +) |
| 30 | +from sinch.domains.conversation.models.v1.messages.shared.coordinates import ( |
| 31 | + Coordinates, |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +def test_send_message_request_body_expects_accepts_text_message(): |
| 36 | + """ |
| 37 | + Test that the model accepts text_message with valid content. |
| 38 | + """ |
| 39 | + body = SendMessageRequestBody(text_message=TextMessage(text="Test message content")) |
| 40 | + |
| 41 | + assert body.text_message.text == "Test message content" |
| 42 | + |
| 43 | + |
| 44 | +def test_send_message_request_body_expects_accepts_card_message(): |
| 45 | + """ |
| 46 | + Test that the model accepts card_message. |
| 47 | + """ |
| 48 | + body = SendMessageRequestBody(card_message=CardMessage(title="Card title")) |
| 49 | + |
| 50 | + assert body.card_message is not None |
| 51 | + assert body.card_message.title == "Card title" |
| 52 | + |
| 53 | + |
| 54 | +def test_send_message_request_body_expects_accepts_carousel_message(): |
| 55 | + """ |
| 56 | + Test that the model accepts carousel_message with a list of cards. |
| 57 | + """ |
| 58 | + body = SendMessageRequestBody( |
| 59 | + carousel_message=CarouselMessage(cards=[CardMessage(title="Card 1")]) |
| 60 | + ) |
| 61 | + |
| 62 | + assert body.carousel_message is not None |
| 63 | + assert len(body.carousel_message.cards) == 1 |
| 64 | + assert body.carousel_message.cards[0].title == "Card 1" |
| 65 | + |
| 66 | + |
| 67 | +def test_send_message_request_body_expects_accepts_choice_message(): |
| 68 | + """ |
| 69 | + Test that the model accepts choice_message with choices. |
| 70 | + """ |
| 71 | + body = SendMessageRequestBody( |
| 72 | + choice_message=ChoiceMessage( |
| 73 | + choices=[TextChoiceMessage(text_message=TextMessage(text="Option 1"))] |
| 74 | + ) |
| 75 | + ) |
| 76 | + |
| 77 | + assert body.choice_message is not None |
| 78 | + assert len(body.choice_message.choices) == 1 |
| 79 | + assert body.choice_message.choices[0].text_message.text == "Option 1" |
| 80 | + |
| 81 | + |
| 82 | +def test_send_message_request_body_expects_accepts_location_message(): |
| 83 | + """ |
| 84 | + Test that the model accepts location_message with coordinates and title. |
| 85 | + """ |
| 86 | + body = SendMessageRequestBody( |
| 87 | + location_message=LocationMessage( |
| 88 | + coordinates=Coordinates(latitude=59.3293, longitude=18.0686), |
| 89 | + title="Stockholm", |
| 90 | + ) |
| 91 | + ) |
| 92 | + |
| 93 | + assert body.location_message is not None |
| 94 | + assert body.location_message.title == "Stockholm" |
| 95 | + assert body.location_message.coordinates.latitude == 59.3293 |
| 96 | + assert body.location_message.coordinates.longitude == 18.0686 |
| 97 | + |
| 98 | + |
| 99 | +def test_send_message_request_body_expects_accepts_media_message(): |
| 100 | + """ |
| 101 | + Test that the model accepts media_message with url. |
| 102 | + """ |
| 103 | + body = SendMessageRequestBody( |
| 104 | + media_message=MediaProperties(url="https://example.com/image.jpg") |
| 105 | + ) |
| 106 | + |
| 107 | + assert body.media_message is not None |
| 108 | + assert body.media_message.url == "https://example.com/image.jpg" |
| 109 | + |
| 110 | + |
| 111 | +def test_send_message_request_body_expects_accepts_template_message(): |
| 112 | + """ |
| 113 | + Test that the model accepts template_message with omni_template. |
| 114 | + """ |
| 115 | + body = SendMessageRequestBody( |
| 116 | + template_message=TemplateMessage( |
| 117 | + omni_template=TemplateReferenceOmniChannel( |
| 118 | + template_id="tpl_123", version="latest" |
| 119 | + ) |
| 120 | + ) |
| 121 | + ) |
| 122 | + |
| 123 | + assert body.template_message is not None |
| 124 | + assert body.template_message.omni_template is not None |
| 125 | + assert body.template_message.omni_template.template_id == "tpl_123" |
| 126 | + assert body.template_message.omni_template.version == "latest" |
| 127 | + |
| 128 | + |
| 129 | +def test_send_message_request_body_expects_accepts_choice_with_one_message_key(): |
| 130 | + """ |
| 131 | + Parsing from dict: each choice with exactly one message-type key is valid. |
| 132 | + Choices array can include Call, Location, Text, URL, Calendar, Request location |
| 133 | + (number limited to 10 per spec). |
| 134 | + """ |
| 135 | + choices = [ |
| 136 | + {"text_message": {"text": "Option 1"}}, |
| 137 | + {"call_message": {"title": "Call us", "phone_number": "+46732000000"}}, |
| 138 | + {"url_message": {"title": "Website", "url": "https://example.com"}}, |
| 139 | + { |
| 140 | + "location_message": { |
| 141 | + "title": "Show map", |
| 142 | + "coordinates": {"latitude": 59.33, "longitude": 18.07}, |
| 143 | + } |
| 144 | + }, |
| 145 | + { |
| 146 | + "share_location_message": { |
| 147 | + "title": "Share location", |
| 148 | + "fallback_url": "https://example.com", |
| 149 | + } |
| 150 | + }, |
| 151 | + ] |
| 152 | + body = SendMessageRequestBody( |
| 153 | + choice_message=ChoiceMessage(choices=choices) |
| 154 | + ) |
| 155 | + assert body.choice_message is not None |
| 156 | + assert len(body.choice_message.choices) == 5 |
| 157 | + assert body.choice_message.choices[0].text_message.text == "Option 1" |
| 158 | + assert body.choice_message.choices[1].call_message.phone_number == "+46732000000" |
| 159 | + assert body.choice_message.choices[2].url_message.url == "https://example.com" |
| 160 | + assert body.choice_message.choices[3].location_message.title == "Show map" |
| 161 | + assert ( |
| 162 | + body.choice_message.choices[4].share_location_message.title |
| 163 | + == "Share location" |
| 164 | + ) |
| 165 | + |
| 166 | + |
| 167 | +def test_send_message_request_body_expects_rejects_choice_with_zero_message_keys(): |
| 168 | + """ |
| 169 | + Parsing from dict: choice with no message-type key raises. |
| 170 | + """ |
| 171 | + with pytest.raises(ValueError, match="exactly one of"): |
| 172 | + SendMessageRequestBody( |
| 173 | + choice_message=ChoiceMessage(choices=[{"postback_data": "x"}]) |
| 174 | + ) |
| 175 | + |
| 176 | + |
| 177 | +def test_send_message_request_body_expects_rejects_choice_with_two_message_keys(): |
| 178 | + """ |
| 179 | + Parsing from dict: choice with two message-type keys raises. |
| 180 | + """ |
| 181 | + with pytest.raises(ValueError, match="exactly one of"): |
| 182 | + SendMessageRequestBody( |
| 183 | + choice_message=ChoiceMessage( |
| 184 | + choices=[ |
| 185 | + { |
| 186 | + "text_message": {"text": "A"}, |
| 187 | + "call_message": {"title": "Call", "phone_number": "1"}, |
| 188 | + } |
| 189 | + ] |
| 190 | + ) |
| 191 | + ) |
0 commit comments