diff --git a/CHANGELOG.md b/CHANGELOG.md index 154f8633..2b1a98c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Change Log +## [4.55.5](https://github.com/plivo/plivo-python/tree/v4.55.5) (2024-09-10) +**Feature - Adding validations for AudioStream XML creation** +- Added Validations for AudioStream XML creation + ## [4.55.4](https://github.com/plivo/plivo-python/tree/v4.55.4) (2024-09-06) **Feature - Adding more attribute on mdr object** - Added `message_sent_time`, `message_updated_time` and `error-message` on get and list Message API -- + ## [4.55.3](https://github.com/plivo/plivo-python/tree/v4.55.3) (2024-09-06) **Feature - Adding support for brand_name, code_length and app_hash in Create,Get and List Session** diff --git a/plivo/version.py b/plivo/version.py index aadaef61..23a5fcea 100644 --- a/plivo/version.py +++ b/plivo/version.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__version__ = '4.55.4' +__version__ = '4.55.5' diff --git a/plivo/xml/streamElement.py b/plivo/xml/streamElement.py index 3831c4e9..fadf43ce 100644 --- a/plivo/xml/streamElement.py +++ b/plivo/xml/streamElement.py @@ -1,14 +1,87 @@ +from plivo import exceptions from plivo.utils.validators import * -from plivo.xml import ( - PlivoXMLElement, - map_type -) +from plivo.xml import PlivoXMLElement, map_type +import six class StreamElement(PlivoXMLElement): _name = 'Stream' - _nestable = [ - ] + _nestable = [] + + ALLOWED_AUDIO_TRACKS = ['inbound', 'outbound', 'both'] + ALLOWED_CALLBACK_METHODS = ['GET', 'POST'] + + @property + def bidirectional(self): + return self.__bidirectional + + @bidirectional.setter + def bidirectional(self, value): + if value is not None: + if not isinstance(value, bool): + raise exceptions.ValidationError("bidirectional must be a boolean value.") + self.__bidirectional = value + + @validate_args( + value=[of_type(bool)] + ) + def set_bidirectional(self, value): + self.bidirectional = value + return self + + @property + def audioTrack(self): + return self.__audioTrack + + @audioTrack.setter + def audioTrack(self, value): + if value is not None: + if value not in self.ALLOWED_AUDIO_TRACKS: + raise exceptions.ValidationError(f"audioTrack must be one of {self.ALLOWED_AUDIO_TRACKS}.") + self.__audioTrack = value + + @validate_args( + value=[of_type(str)] + ) + def set_audioTrack(self, value): + self.audioTrack = value + return self + + @property + def statusCallbackMethod(self): + return self.__statusCallbackMethod + + @statusCallbackMethod.setter + def statusCallbackMethod(self, value): + if value is not None: + if value not in self.ALLOWED_CALLBACK_METHODS: + raise exceptions.ValidationError(f"statusCallbackMethod must be one of {self.ALLOWED_CALLBACK_METHODS}.") + self.__statusCallbackMethod = value + + @validate_args( + value=[of_type(str)] + ) + def set_statusCallbackMethod(self, value): + self.statusCallbackMethod = value + return self + + @property + def keepCallAlive(self): + return self.__keepCallAlive + + @keepCallAlive.setter + def keepCallAlive(self, value): + if value is not None: + if not isinstance(value, bool): + raise exceptions.ValidationError("keepCallAlive must be a boolean value.") + self.__keepCallAlive = value + + @validate_args( + value=[of_type(bool)] + ) + def set_keepCallAlive(self, value): + self.keepCallAlive = value + return self def __init__( self, diff --git a/setup.py b/setup.py index 9ba457f4..1188cca6 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='plivo', - version='4.55.4', + version='4.55.5', description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML', long_description=long_description, url='https://github.com/plivo/plivo-python', diff --git a/tests/xml/test_streamElement.py b/tests/xml/test_streamElement.py index e46b35d2..cbe41c7b 100644 --- a/tests/xml/test_streamElement.py +++ b/tests/xml/test_streamElement.py @@ -1,6 +1,7 @@ from unittest import TestCase from plivo import plivoxml +from plivo.exceptions import ValidationError from tests import PlivoXmlTestCase @@ -20,3 +21,16 @@ def test_set_methods(self): plivoxml.StreamElement(content, bidirectional=bidirectional, extraHeaders=extraHeaders, keepCallAlive=keepCallAlive) ).to_string(False) self.assertXmlEqual(response, expected_response) + + def test_validations_on_elements(self): + expected_error = 'bidirectional must be a boolean value.' + + actual_error = '' + content = 'wss://test.url' + bidirectional = "hello" + try: + plivoxml.StreamElement(content=content, bidirectional=bidirectional) + except ValidationError as e: + print("Error: ", str(e)) + actual_error = str(e) + self.assertXmlEqual(expected_error, actual_error)