Skip to content

Commit e3c2acd

Browse files
Merge pull request #277 from plivo/VT-8147
VT-8147: Add validations for AudioStream XML creation
2 parents 2cc25fe + 0864885 commit e3c2acd

File tree

5 files changed

+100
-9
lines changed

5 files changed

+100
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Change Log
2+
## [4.55.5](https://github.com/plivo/plivo-python/tree/v4.55.5) (2024-09-10)
3+
**Feature - Adding validations for AudioStream XML creation**
4+
- Added Validations for AudioStream XML creation
5+
26
## [4.55.4](https://github.com/plivo/plivo-python/tree/v4.55.4) (2024-09-06)
37
**Feature - Adding more attribute on mdr object**
48
- Added `message_sent_time`, `message_updated_time` and `error-message` on get and list Message API
5-
-
9+
610

711
## [4.55.3](https://github.com/plivo/plivo-python/tree/v4.55.3) (2024-09-06)
812
**Feature - Adding support for brand_name, code_length and app_hash in Create,Get and List Session**

plivo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '4.55.4'
2+
__version__ = '4.55.5'

plivo/xml/streamElement.py

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,87 @@
1+
from plivo import exceptions
12
from plivo.utils.validators import *
2-
from plivo.xml import (
3-
PlivoXMLElement,
4-
map_type
5-
)
3+
from plivo.xml import PlivoXMLElement, map_type
4+
import six
65

76

87
class StreamElement(PlivoXMLElement):
98
_name = 'Stream'
10-
_nestable = [
11-
]
9+
_nestable = []
10+
11+
ALLOWED_AUDIO_TRACKS = ['inbound', 'outbound', 'both']
12+
ALLOWED_CALLBACK_METHODS = ['GET', 'POST']
13+
14+
@property
15+
def bidirectional(self):
16+
return self.__bidirectional
17+
18+
@bidirectional.setter
19+
def bidirectional(self, value):
20+
if value is not None:
21+
if not isinstance(value, bool):
22+
raise exceptions.ValidationError("bidirectional must be a boolean value.")
23+
self.__bidirectional = value
24+
25+
@validate_args(
26+
value=[of_type(bool)]
27+
)
28+
def set_bidirectional(self, value):
29+
self.bidirectional = value
30+
return self
31+
32+
@property
33+
def audioTrack(self):
34+
return self.__audioTrack
35+
36+
@audioTrack.setter
37+
def audioTrack(self, value):
38+
if value is not None:
39+
if value not in self.ALLOWED_AUDIO_TRACKS:
40+
raise exceptions.ValidationError(f"audioTrack must be one of {self.ALLOWED_AUDIO_TRACKS}.")
41+
self.__audioTrack = value
42+
43+
@validate_args(
44+
value=[of_type(str)]
45+
)
46+
def set_audioTrack(self, value):
47+
self.audioTrack = value
48+
return self
49+
50+
@property
51+
def statusCallbackMethod(self):
52+
return self.__statusCallbackMethod
53+
54+
@statusCallbackMethod.setter
55+
def statusCallbackMethod(self, value):
56+
if value is not None:
57+
if value not in self.ALLOWED_CALLBACK_METHODS:
58+
raise exceptions.ValidationError(f"statusCallbackMethod must be one of {self.ALLOWED_CALLBACK_METHODS}.")
59+
self.__statusCallbackMethod = value
60+
61+
@validate_args(
62+
value=[of_type(str)]
63+
)
64+
def set_statusCallbackMethod(self, value):
65+
self.statusCallbackMethod = value
66+
return self
67+
68+
@property
69+
def keepCallAlive(self):
70+
return self.__keepCallAlive
71+
72+
@keepCallAlive.setter
73+
def keepCallAlive(self, value):
74+
if value is not None:
75+
if not isinstance(value, bool):
76+
raise exceptions.ValidationError("keepCallAlive must be a boolean value.")
77+
self.__keepCallAlive = value
78+
79+
@validate_args(
80+
value=[of_type(bool)]
81+
)
82+
def set_keepCallAlive(self, value):
83+
self.keepCallAlive = value
84+
return self
1285

1386
def __init__(
1487
self,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='plivo',
13-
version='4.55.4',
13+
version='4.55.5',
1414
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
1515
long_description=long_description,
1616
url='https://github.com/plivo/plivo-python',

tests/xml/test_streamElement.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import TestCase
22

33
from plivo import plivoxml
4+
from plivo.exceptions import ValidationError
45
from tests import PlivoXmlTestCase
56

67

@@ -20,3 +21,16 @@ def test_set_methods(self):
2021
plivoxml.StreamElement(content, bidirectional=bidirectional, extraHeaders=extraHeaders, keepCallAlive=keepCallAlive)
2122
).to_string(False)
2223
self.assertXmlEqual(response, expected_response)
24+
25+
def test_validations_on_elements(self):
26+
expected_error = 'bidirectional must be a boolean value.'
27+
28+
actual_error = ''
29+
content = 'wss://test.url'
30+
bidirectional = "hello"
31+
try:
32+
plivoxml.StreamElement(content=content, bidirectional=bidirectional)
33+
except ValidationError as e:
34+
print("Error: ", str(e))
35+
actual_error = str(e)
36+
self.assertXmlEqual(expected_error, actual_error)

0 commit comments

Comments
 (0)