Skip to content

Commit 0ba7029

Browse files
feat: add missing validation tests for SMS, MMS, RCS and WhatsApp models
Agent-Logs-Url: https://github.com/Vonage/vonage-python-sdk/sessions/50d9d0a2-7556-4233-8b65-abc9902d5b7f Co-authored-by: dragonmantank <108948+dragonmantank@users.noreply.github.com>
1 parent 294fe5a commit 0ba7029

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed

messages/tests/test_mms_models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,25 @@ def test_create_mms_content_with_invalid_content_item():
520520
],
521521
)
522522
assert "Input should be a valid dictionary or instance" in str(err.value)
523+
524+
525+
def test_create_mms_with_ttl_too_low():
526+
with pytest.raises(ValidationError) as err:
527+
MmsImage(
528+
to='1234567890',
529+
from_='1234567890',
530+
image=MmsResource(url='https://example.com/image.jpg'),
531+
ttl=299,
532+
)
533+
assert 'greater than or equal to 300' in str(err.value)
534+
535+
536+
def test_create_mms_with_ttl_too_high():
537+
with pytest.raises(ValidationError) as err:
538+
MmsImage(
539+
to='1234567890',
540+
from_='1234567890',
541+
image=MmsResource(url='https://example.com/image.jpg'),
542+
ttl=259201,
543+
)
544+
assert 'less than or equal to 259200' in str(err.value)

messages/tests/test_rcs_models.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,3 +1804,55 @@ def test_create_rcs_options_carousel_card_width_with_invalid_option():
18041804
card_width='INVALID_WIDTH',
18051805
)
18061806
assert "Input should be 'SMALL' or 'MEDIUM'" in str(err.value)
1807+
1808+
1809+
def test_create_rcs_text_too_short():
1810+
with pytest.raises(ValidationError) as err:
1811+
RcsText(
1812+
to='1234567890',
1813+
from_='asdf1234',
1814+
text='',
1815+
)
1816+
assert 'String should have at least 1 character' in str(err.value)
1817+
1818+
1819+
def test_create_rcs_text_too_long():
1820+
with pytest.raises(ValidationError) as err:
1821+
RcsText(
1822+
to='1234567890',
1823+
from_='asdf1234',
1824+
text='a' * 3073,
1825+
)
1826+
assert 'String should have at most 3072 characters' in str(err.value)
1827+
1828+
1829+
def test_create_rcs_with_ttl_too_low():
1830+
with pytest.raises(ValidationError) as err:
1831+
RcsText(
1832+
to='1234567890',
1833+
from_='asdf1234',
1834+
text='Hello, World!',
1835+
ttl=19,
1836+
)
1837+
assert 'greater than or equal to 20' in str(err.value)
1838+
1839+
1840+
def test_create_rcs_with_ttl_too_high():
1841+
with pytest.raises(ValidationError) as err:
1842+
RcsText(
1843+
to='1234567890',
1844+
from_='asdf1234',
1845+
text='Hello, World!',
1846+
ttl=259201,
1847+
)
1848+
assert 'less than or equal to 259200' in str(err.value)
1849+
1850+
1851+
def test_create_rcs_with_invalid_from_field():
1852+
with pytest.raises(ValidationError) as err:
1853+
RcsText(
1854+
to='1234567890',
1855+
from_='invalid from!',
1856+
text='Hello, World!',
1857+
)
1858+
assert 'String should match pattern' in str(err.value)

messages/tests/test_sms_models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
from pydantic import ValidationError
13
from vonage_messages.models import Sms, SmsOptions
24
from vonage_messages.models.enums import EncodingType, WebhookVersion
35

@@ -56,3 +58,24 @@ def test_create_sms_all_fields():
5658
}
5759

5860
assert sms_model.model_dump(by_alias=True) == sms_dict
61+
62+
63+
def test_create_sms_text_too_long():
64+
with pytest.raises(ValidationError) as err:
65+
Sms(
66+
to='1234567890',
67+
from_='1234567890',
68+
text='a' * 1001,
69+
)
70+
assert 'String should have at most 1000 characters' in str(err.value)
71+
72+
73+
def test_create_sms_with_invalid_encoding_type():
74+
with pytest.raises(ValidationError) as err:
75+
Sms(
76+
to='1234567890',
77+
from_='1234567890',
78+
text='Hello, World!',
79+
sms=SmsOptions(encoding_type='invalid'),
80+
)
81+
assert 'Input should be' in str(err.value)

messages/tests/test_whatsapp_models.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from copy import deepcopy
22

3+
import pytest
4+
from pydantic import ValidationError
35
from vonage_messages.models import (
46
ReplyingIndicatorText,
57
WhatsappAudio,
@@ -394,3 +396,55 @@ def test_create_replying_indicator():
394396
'type': 'text',
395397
}
396398
assert whatsapp_model.model_dump(by_alias=True, exclude_none=True) == whatsapp_dict
399+
400+
401+
def test_whatsapp_text_too_long():
402+
with pytest.raises(ValidationError) as err:
403+
WhatsappText(
404+
to='1234567890',
405+
from_='1234567890',
406+
text='a' * 4097,
407+
)
408+
assert 'String should have at most 4096 characters' in str(err.value)
409+
410+
411+
def test_whatsapp_audio_url_too_short():
412+
with pytest.raises(ValidationError) as err:
413+
WhatsappAudio(
414+
to='1234567890',
415+
from_='1234567890',
416+
audio=WhatsappAudioResource(url='short'),
417+
)
418+
assert 'String should have at least 10 characters' in str(err.value)
419+
420+
421+
def test_whatsapp_audio_url_too_long():
422+
with pytest.raises(ValidationError) as err:
423+
WhatsappAudio(
424+
to='1234567890',
425+
from_='1234567890',
426+
audio=WhatsappAudioResource(url='https://' + 'a' * 2000),
427+
)
428+
assert 'String should have at most 2000 characters' in str(err.value)
429+
430+
431+
def test_whatsapp_image_caption_too_short():
432+
with pytest.raises(ValidationError) as err:
433+
WhatsappImage(
434+
to='1234567890',
435+
from_='1234567890',
436+
image=WhatsappImageResource(url='https://example.com/image.jpg', caption=''),
437+
)
438+
assert 'String should have at least 1 character' in str(err.value)
439+
440+
441+
def test_whatsapp_image_caption_too_long():
442+
with pytest.raises(ValidationError) as err:
443+
WhatsappImage(
444+
to='1234567890',
445+
from_='1234567890',
446+
image=WhatsappImageResource(
447+
url='https://example.com/image.jpg', caption='a' * 3001
448+
),
449+
)
450+
assert 'String should have at most 3000 characters' in str(err.value)

0 commit comments

Comments
 (0)