Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VT-8147: Add validations for AudioStream XML creation #277

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
2 changes: 1 addition & 1 deletion plivo/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '4.55.4'
__version__ = '4.55.5'
85 changes: 79 additions & 6 deletions plivo/xml/streamElement.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions tests/xml/test_streamElement.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase

from plivo import plivoxml
from plivo.exceptions import ValidationError
from tests import PlivoXmlTestCase


Expand All @@ -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)
Loading