diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml new file mode 100644 index 00000000..f7f09b59 --- /dev/null +++ b/.github/workflows/unitTests.yml @@ -0,0 +1,32 @@ +name: UnitTests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + name: UnitTests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [2.7, 3.5, 3.6, 3.7] + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Dependencies Installation + run: | + pip install tox + - name: Run Tests + run: | + python --version + tox -e py diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a2c879..1cf72418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [4.18.1](https://github.com/plivo/plivo-python/tree/v4.18.1) (2021-07-16) +- Updates to [add a member a multi-party call API](https://www.plivo.com/docs/voice/api/multiparty-call/participants#add-a-participant). + - Remove validation range for `delay` and `ringtimeout` parameters. + - Add appropriate error message for multiple `ringtimeout` and `delaydial` values. + - Fix the agent limit validation bug so that it only checks when multiple `to` param values are supplied. + - Fix the multiparty call and other voice API UT's. + ## [4.18.0](https://github.com/plivo/plivo-python/tree/v4.18.0) (2021-07-13) - Power pack ID has been included to the response for the [list all messages API](https://www.plivo.com/docs/sms/api/message/list-all-messages/) and the [get message details API](https://www.plivo.com/docs/sms/api/message#retrieve-a-message). - Support for filtering messages by Power pack ID has been added to the [list all messages API](https://www.plivo.com/docs/sms/api/message#list-all-messages). diff --git a/README.md b/README.md index 493b147c..7b3aa6a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # plivo-python -[![Build Status](https://travis-ci.org/plivo/plivo-python.svg?branch=master)](https://travis-ci.org/plivo/plivo-python) +[![UnitTests](https://github.com/plivo/plivo-python/actions/workflows/unitTests.yml/badge.svg?branch=master)](https://github.com/plivo/plivo-python/actions/workflows/unitTests.yml) [![PyPI](https://img.shields.io/pypi/v/plivo.svg)](https://pypi.python.org/pypi/plivo) [![PyPI](https://img.shields.io/pypi/pyversions/plivo.svg)](https://pypi.python.org/pypi/plivo) [![PyPI](https://img.shields.io/pypi/l/plivo.svg)](https://pypi.python.org/pypi/plivo) diff --git a/plivo/resources/multipartycall.py b/plivo/resources/multipartycall.py index a0dfb91d..2413cacb 100644 --- a/plivo/resources/multipartycall.py +++ b/plivo/resources/multipartycall.py @@ -228,8 +228,8 @@ def get(self, uuid=None, friendly_name=None): of_type_exact(str), one_of(is_url(), is_in(('real', 'none'), case_sensitive=False, case_type='lower')), )], - ring_timeout=[optional(one_of(of_type_exact(str), of_type_exact(int)), multiple_valid_integers(15, 120))], - delay_dial=[optional(one_of(of_type_exact(str), of_type_exact(int)), multiple_valid_integers(0, 120))], + ring_timeout=[optional(one_of(of_type_exact(str), of_type_exact(int)), multiple_valid_integers())], + delay_dial=[optional(one_of(of_type_exact(str), of_type_exact(int)), multiple_valid_integers())], max_duration=[optional( of_type_exact(int), check(lambda max_duration: 300 <= max_duration <= 28800, '300 < max_duration <= 28800'))], @@ -331,10 +331,14 @@ def add_participant(self, raise ValidationError('specify either call_uuid or (from, to)') if call_uuid is None and (not from_ or not to_): raise ValidationError('specify (from, to) when not adding an existing call_uuid to multi party participant') - if len(to_.split('<')) > 1 and role.lower() != "agent": + if to_ and len(to_.split('<')) > 1 and role.lower() != "agent": raise ValidationError('Multiple to_ values given for role ' + role) - elif len(to_.split('<')) > 20: + elif to_ and len(to_.split('<')) > 20: raise ValidationError('No of to_ values provided should be lesser than 20') + if to_ and len(str(ring_timeout).split('<')) > len(to_.split('<')): + raise ValidationError("RingTimeout:number of ring_timeout(s) should be same as number of destination(s)") + if to_ and len(str(delay_dial).split('<')) > len(to_.split('<')): + raise ValidationError("DelayDial:number of delay_dial(s) should be same as number of destination(s)") return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Participant'), self.__clean_identifiers(to_param_dict(self.add_participant, locals())), is_voice_request=True) diff --git a/plivo/utils/jwt.py b/plivo/utils/jwt.py index 7eb69964..824bfd63 100644 --- a/plivo/utils/jwt.py +++ b/plivo/utils/jwt.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import jwt, time from plivo.utils.validators import * diff --git a/plivo/utils/validators.py b/plivo/utils/validators.py index 80eb7d5c..11459f89 100644 --- a/plivo/utils/validators.py +++ b/plivo/utils/validators.py @@ -180,27 +180,17 @@ def f(name, value): return required(f) -def multiple_valid_integers(lowerbound, upperbound): +def multiple_valid_integers(): def f(name, value): - if isinstance(value, int): - if value >= lowerbound and value <= upperbound: - return value, [] - else: - return None, {name + ' value must be in range ' + str(lowerbound) + ' to ' + str(upperbound)} - else: + if isinstance(value, str): values = value.split('<') for i in values: - is_int = True try: int(i) except ValueError: - is_int = False - if is_int: - if int(i) > upperbound or int(i) < lowerbound: - return None, [name + ' destination value must be in range ' + str(lowerbound) + ' to ' + str(upperbound)] - else: return None, ['{} destination value must be integer'.format(name)] return value, [] + return value, [] return f diff --git a/plivo/version.py b/plivo/version.py index ef313e95..cff6adf9 100644 --- a/plivo/version.py +++ b/plivo/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -__version__ = '4.18.0' +__version__ = '4.18.1' diff --git a/setup.py b/setup.py index 3d6618ab..d044464b 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='plivo', - version='4.18.0', + version='4.18.1', 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', @@ -39,6 +39,7 @@ 'six >= 1, < 2', 'decorator >= 4, < 5', 'lxml >= 3, < 5', + 'PyJWT==1.7.1' ], keywords=['plivo', 'plivo xml', 'voice calls', 'sms'], include_package_data=True, diff --git a/tests/base.py b/tests/base.py index 2c2a505c..92358d5c 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from unittest import TestCase +from doctest import Example +from lxml.doctestcompare import LXMLOutputChecker from httmock import HTTMock, all_requests @@ -172,3 +174,12 @@ def get_url(self, *args, **kwargs): self.client.session.auth[0] + \ '/' + '/'.join([quote_plus(arg) for arg in args]) + '/?' + urlencode(kwargs) + + +class PlivoXmlTestCase: + + def assertXmlEqual(self, got, want): + checker = LXMLOutputChecker() + if not checker.check_output(want, got, 0): + message = checker.output_difference(Example("", want), got, 0) + raise AssertionError(message) diff --git a/tests/decorators.py b/tests/decorators.py index 2520a49c..43588ab8 100644 --- a/tests/decorators.py +++ b/tests/decorators.py @@ -20,7 +20,7 @@ def decorator(self, *args, **kwargs): name + '.json')) try: - with io.open(path) as f: + with io.open(path, encoding='utf-8') as f: self.expected_response = json.load(f) self.client.set_expected_response( status_code=status_code, diff --git a/tests/resources/test_conferences.py b/tests/resources/test_conferences.py index 6640dffa..8443de3c 100644 --- a/tests/resources/test_conferences.py +++ b/tests/resources/test_conferences.py @@ -149,7 +149,7 @@ def test_play_delete(self): conference_name=conference_name, member_id=member_id) self.assertEqual(self.client.current_request.method, 'DELETE') self.assertUrlEqual( - self.get_url('Conference', conference_name, 'Member', member_id, + self.get_voice_url('Conference', conference_name, 'Member', member_id, 'Play'), self.client.current_request.url) @with_response(202) diff --git a/tests/resources/test_jwt.py b/tests/resources/test_jwt.py index f3529991..9d45d78d 100644 --- a/tests/resources/test_jwt.py +++ b/tests/resources/test_jwt.py @@ -8,26 +8,25 @@ class AccessTokenTest(PlivoResourceTestCase): def test_jwt_constructor(self): - self.assertRaisesRegex(TypeError, "", jwt.AccessToken.__init__, - jwt.AccessToken, 'ADADADADADADADADADA', + self.assertRaisesRegexp(TypeError, "", jwt.AccessToken, + 'ADADADADADADADADADA', 'qwerty') def test_jwt_constructor_auth_id(self): - self.assertRaisesRegex(plivo.exceptions.ValidationError, + self.assertRaisesRegexp(plivo.exceptions.ValidationError, "auth_id should match format .*", - jwt.AccessToken.__init__, jwt.AccessToken, + jwt.AccessToken, 'ADADADADADADADADADA', 'qwerty', 'username') def test_jwt_constructor_auth_id(self): - self.assertRaisesRegex(plivo.exceptions.ValidationError, + self.assertRaisesRegexp(plivo.exceptions.ValidationError, "auth_id should match format .*", - jwt.AccessToken.__init__, jwt.AccessToken, + jwt.AccessToken, 'ADADADADADADADADADA', 'qwerty', 'username') def test_jwt_constructor_lifetime(self): - self.assertRaisesRegex(plivo.exceptions.ValidationError, + self.assertRaisesRegexp(plivo.exceptions.ValidationError, ".* lifetime .*", - jwt.AccessToken.__init__, jwt.AccessToken, 'MADADADADADADADADADA', 'qwerty', @@ -36,9 +35,8 @@ def test_jwt_constructor_lifetime(self): lifetime=123) def test_jwt_constructor_validity(self): - self.assertRaisesRegex(plivo.exceptions.ValidationError, + self.assertRaisesRegexp(plivo.exceptions.ValidationError, "use either lifetime or valid_till", - jwt.AccessToken.__init__, jwt.AccessToken, 'MADADADADADADADADADA', 'qwerty', @@ -46,9 +44,8 @@ def test_jwt_constructor_validity(self): valid_from=int(time.time()), valid_till=int(time.time()) - 100, lifetime=1200) - self.assertRaisesRegex(plivo.exceptions.ValidationError, + self.assertRaisesRegexp(plivo.exceptions.ValidationError, "validity expires .* seconds before it starts", - jwt.AccessToken.__init__, jwt.AccessToken, 'MADADADADADADADADADA', 'qwerty', @@ -61,4 +58,3 @@ def test_jwt(self): token.add_voice_grants(True, True) self.assertEqual(True, token.grants['voice']['incoming_allow']) self.assertNotEqual(False, token.grants['voice']['outgoing_allow']) - self.assertEqual('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSJ9.eyJqdGkiOiJ1c2VybmFtZS0xMjM0NSIsImlzcyI6Ik1BREFEQURBREFEQURBREFEQURBIiwic3ViIjoidXNlcm5hbWUiLCJuYmYiOjEyMTIxMjEyLCJleHAiOjEyMTIxNTEyLCJncmFudHMiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOnRydWUsIm91dGdvaW5nX2FsbG93Ijp0cnVlfX19.khM99-sYP2AylLo9y6bwNnJbVPjjtOMAimiFvNo7FGA', token.to_jwt()) diff --git a/tests/resources/test_multipartycalls.py b/tests/resources/test_multipartycalls.py index e8e67088..5eb6a3b3 100644 --- a/tests/resources/test_multipartycalls.py +++ b/tests/resources/test_multipartycalls.py @@ -80,6 +80,12 @@ def test_add_participant_validations(self): error_message = str(e) self.assertEqual(error_message, "[\"uuid should be of type: ['str']\"]") + try: + self.client.multi_party_calls.add_participant(role='supervisor', caller_name=1234) + except ValidationError as e: + error_message = str(e) + self.assertEqual(error_message, "[\"caller_name should be of type: ['str']\"]") + try: self.client.multi_party_calls.add_participant(role='supervisor', call_status_callback_url='callback_python') except ValidationError as e: @@ -106,7 +112,19 @@ def test_add_participant_validations(self): self.client.multi_party_calls.add_participant(role='supervisor', ring_timeout='2500') except ValidationError as e: error_message = str(e) - self.assertEqual(error_message, "[\"ring_timeout should be of type: ['int']\"]") + self.assertEqual(error_message, "specify either multi party call friendly name or uuid") + + try: + self.client.multi_party_calls.add_participant(role='supervisor', ring_timeout='1aq') + except ValidationError as e: + error_message = str(e) + self.assertEqual(error_message, "[\'ring_timeout destination value must be integer\']") + + try: + self.client.multi_party_calls.add_participant(role='supervisor', delay_dial='2<2.3') + except ValidationError as e: + error_message = str(e) + self.assertEqual(error_message, "[\'delay_dial destination value must be integer\']") try: self.client.multi_party_calls.add_participant(role='supervisor', max_duration=29867) @@ -161,6 +179,7 @@ def test_add_participant(self): 'max_participants': 10, 'max_duration': 14400, 'ring_timeout': 45, + 'delay_dial': 0, 'dial_music': 'real', 'confirm_key_sound_method': 'GET', 'call_status_callback_method': 'POST', @@ -170,7 +189,6 @@ def test_add_participant(self): add_participant_response = self.client.multi_party_calls.add_participant(friendly_name='Voice', role='agent', call_uuid='1234-5678-4321-0987') - self.__assert_requests(actual_response=add_participant_response, expected_method='POST', expected_url='https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/' 'MultiPartyCall/name_Voice/Participant/', @@ -192,6 +210,7 @@ def test_add_participant(self): request_body['customer_hold_music_method'] = 'POST' request_body['exit_sound_method'] = 'POST' request_body['record_file_format'] = 'wav' + request_body['caller_name'] = '918888888888' add_participant_response = self.client.multi_party_calls.add_participant( uuid='12345678-90123456', role='supervisor', to_='180012341234', from_='918888888888', diff --git a/tests/xml/test_MultiPartyCallElement.py b/tests/xml/test_MultiPartyCallElement.py index 5c09fe5f..c1c48999 100644 --- a/tests/xml/test_MultiPartyCallElement.py +++ b/tests/xml/test_MultiPartyCallElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml from plivo.exceptions import ValidationError +from tests import PlivoXmlTestCase -class MultiPartyCallElementTest(TestCase): +class MultiPartyCallElementTest(TestCase, PlivoXmlTestCase): def test_default_xml(self): @@ -18,7 +19,7 @@ def test_default_xml(self): 'waitMusicMethod="GET">Nairobi' element = plivoxml.MultiPartyCallElement(content='Nairobi', role='Agent') - self.assertEqual(element.to_string(False), expected_response) + self.assertXmlEqual(element.to_string(False), expected_response) def test_setting_optional_fields(self): expected_response = 'Tokyo' element = plivoxml.MultiPartyCallElement(content='Tokyo', role='supervisor', exit_sound='beep:1') - self.assertEqual(element.to_string(False), expected_response) + self.assertXmlEqual(element.to_string(False), expected_response) def test_validation_on_init(self): expected_error = '["status_callback_events should be among (\'mpc-state-changes\', ' \ - '\'participant-state-changes\', \'participant-speak-events\'). ' \ + '\'participant-state-changes\', \'participant-speak-events\', ' \ + '\'participant-digit-input-events\', \'add-participant-api-events\'). ' \ 'multiple values should be COMMA(,) separated (actual value: hostages-move)"]' actual_error = '' @@ -44,7 +46,7 @@ def test_validation_on_init(self): plivoxml.MultiPartyCallElement(content='Rio', role='agent', status_callback_events='hostages-move') except ValidationError as e: actual_error = str(e) - self.assertEqual(expected_error, actual_error) + self.assertXmlEqual(expected_error, actual_error) def test_validation_on_set(self): expected_error = "['300 <= max_duration <= 28800 (actual value: 255)']" @@ -55,7 +57,7 @@ def test_validation_on_set(self): element.set_max_duration(255) except ValidationError as e: actual_error = str(e) - self.assertEqual(expected_error, actual_error) + self.assertXmlEqual(expected_error, actual_error) def test_builder_setting(self): @@ -72,4 +74,4 @@ def test_builder_setting(self): set_customer_hold_music_url('http://plivo.com/voice.mp3').set_coach_mode(False).\ set_on_exit_action_url('http://plivo.com/api.mp3').set_on_exit_action_method('GET') - self.assertEqual(expected_xml, element.to_string(False)) + self.assertXmlEqual(expected_xml, element.to_string(False)) diff --git a/tests/xml/test_breakElement.py b/tests/xml/test_breakElement.py index 54fe0993..12a7760c 100644 --- a/tests/xml/test_breakElement.py +++ b/tests/xml/test_breakElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class BreakElementTest(TestCase): +class BreakElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): time = "1000ms" strength = "x-strong" @@ -14,4 +15,4 @@ def test_set_methods(self): plivoxml.BreakElement().set_strength(strength).set_time(time) ).add_cont("one second or same as paragraph") ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_conferenceElement.py b/tests/xml/test_conferenceElement.py index 1d9ab88d..f4599675 100644 --- a/tests/xml/test_conferenceElement.py +++ b/tests/xml/test_conferenceElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class ConferenceElementTest(TestCase): +class ConferenceElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is Test' \ @@ -89,4 +90,4 @@ def test_set_methods(self): content_cont ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_emphasisElement.py b/tests/xml/test_emphasisElement.py index 8ad2004f..a7d47cf3 100644 --- a/tests/xml/test_emphasisElement.py +++ b/tests/xml/test_emphasisElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class EmphasisElementTest(TestCase): +class EmphasisElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '' \ 'This is Test' \ @@ -73,4 +74,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_getDigitsElement.py b/tests/xml/test_getDigitsElement.py index a7c84ec1..b863abcd 100644 --- a/tests/xml/test_getDigitsElement.py +++ b/tests/xml/test_getDigitsElement.py @@ -1,8 +1,9 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class GetDigitsElementTest(TestCase): +class GetDigitsElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is Test' \ @@ -84,4 +85,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_messageElement.py b/tests/xml/test_messageElement.py index 50bc9d46..293e4323 100644 --- a/tests/xml/test_messageElement.py +++ b/tests/xml/test_messageElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class MessageElementTest(TestCase): +class MessageElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is Test' @@ -23,4 +24,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_pElement.py b/tests/xml/test_pElement.py index 9086e256..7037d692 100644 --- a/tests/xml/test_pElement.py +++ b/tests/xml/test_pElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class PElementTest(TestCase): +class PElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '

' \ 'This is Test' \ @@ -80,4 +81,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_phonemeElement.py b/tests/xml/test_phonemeElement.py index fc0af8c5..efa92a64 100644 --- a/tests/xml/test_phonemeElement.py +++ b/tests/xml/test_phonemeElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class ElementTest(TestCase): +class ElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): alphabet = "ipa" ph = "təmei̥ɾou̥" @@ -16,4 +17,4 @@ def test_set_methods(self): plivoxml.PhonemeElement("Well").set_alphabet(alphabet).set_ph(ph) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_playElement.py b/tests/xml/test_playElement.py index 6f432a03..7b503860 100644 --- a/tests/xml/test_playElement.py +++ b/tests/xml/test_playElement.py @@ -1,17 +1,18 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class PlayElementTest(TestCase): +class PlayElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is test' - + loop = 1 content = 'This is test' element = plivoxml.ResponseElement() - + response = element.add( plivoxml.PlayElement(content).set_loop(loop) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_preAnswerElement.py b/tests/xml/test_preAnswerElement.py index 9d1cdc86..ab1017c9 100644 --- a/tests/xml/test_preAnswerElement.py +++ b/tests/xml/test_preAnswerElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class PreAnswerElementTest(TestCase): +class PreAnswerElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is test' \ 'This is test' \ @@ -89,4 +90,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_recordElement.py b/tests/xml/test_recordElement.py index 94c325f5..9d384e11 100644 --- a/tests/xml/test_recordElement.py +++ b/tests/xml/test_recordElement.py @@ -1,8 +1,9 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class RecordElementTest(TestCase): +class RecordElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '') def test_add_conference(self): content = 'test' elem = plivoxml.ResponseElement().add_conference( content=content).to_string(False) - self.assertEqual( + self.assertXmlEqual( elem, 'test') def test_add_dial(self): time = 2 elem = plivoxml.ResponseElement().add_dial(time_limit=time).to_string(False) - self.assertEqual(elem, + self.assertXmlEqual(elem, '') def test_add_dtmf(self): content = 'dummy' elem = plivoxml.ResponseElement().add_dtmf(content=content).to_string(False) - self.assertEqual(elem, 'dummy') + self.assertXmlEqual(elem, 'dummy') def test_add_get_digits(self): content = 2 elem = plivoxml.ResponseElement().add_get_digits( timeout=content).to_string(False) - self.assertEqual( + self.assertXmlEqual( elem, '') def test_add_get_input(self): content = 2 elem = plivoxml.ResponseElement().add_get_input( execution_timeout=content).to_string(False) - self.assertEqual( + self.assertXmlEqual( elem, '') def test_add_hangup(self): content = 'dummy' elem = plivoxml.ResponseElement().add_hangup( reason=content).to_string(False) - self.assertEqual( + self.assertXmlEqual( elem, '') def test_add_message(self): content = 'dummy' elem = plivoxml.ResponseElement().add_message( content=content).to_string(False) - self.assertEqual(elem, + self.assertXmlEqual(elem, 'dummy') def test_add_play(self): content = 'dummy' elem = plivoxml.ResponseElement().add_play(content=content).to_string(False) - self.assertEqual(elem, 'dummy') + self.assertXmlEqual(elem, 'dummy') def test_add_pre_answer(self): elem = plivoxml.ResponseElement().add_pre_answer().to_string(False) - self.assertEqual(elem, + self.assertXmlEqual(elem, '') def test_add_record(self): action = 'https://foo.example.com' elem = plivoxml.ResponseElement().add_record(action=action).to_string(False) expected_response = '' - self.assertEqual(elem, expected_response) + self.assertXmlEqual(elem, expected_response) def test_add_redirect(self): content = 'dummy' elem = plivoxml.ResponseElement().add_redirect( content=content).to_string(False) - self.assertEqual(elem, + self.assertXmlEqual(elem, 'dummy') def test_add_speak(self): @@ -92,7 +93,7 @@ def test_add_speak(self): finish_on_key='*')) response.add(plivoxml.SpeakElement('Recording not received.')) elem = response.to_string(False) - self.assertEqual( + self.assertXmlEqual( elem, 'Please leave a message after the beep. Press the star key when done.Recording not received.' ) @@ -100,7 +101,7 @@ def test_add_speak(self): def test_add_wait(self): content = 2 elem = plivoxml.ResponseElement().add_wait(length=content).to_string(False) - self.assertEqual(elem, + self.assertXmlEqual(elem, '') def test_add_mpc(self): @@ -123,4 +124,4 @@ def test_add_mpc(self): record=True, record_file_format='wav', mute=True, enter_sound='beep:2', exit_sound='beep:1', hold=True, on_exit_action_url='https://plivo.com/exitAction') - self.assertEqual(expected_xml, elem.to_string(False)) + self.assertXmlEqual(expected_xml, elem.to_string(False)) diff --git a/tests/xml/test_sElement.py b/tests/xml/test_sElement.py index 7f6b7df2..6eaf858f 100644 --- a/tests/xml/test_sElement.py +++ b/tests/xml/test_sElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class SElementTest(TestCase): +class SElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '' \ 'This is TestThis is ' \ @@ -76,4 +77,4 @@ def test_set_methods(self): ) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_sayAsElement.py b/tests/xml/test_sayAsElement.py index ad7b2ad9..d7da9b98 100644 --- a/tests/xml/test_sayAsElement.py +++ b/tests/xml/test_sayAsElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class SayAsElementTest(TestCase): +class SayAsElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '' \ 'This is Test' @@ -19,4 +20,4 @@ def test_set_methods(self): ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_speakElement.py b/tests/xml/test_speakElement.py index ef3f6ef8..2a3eeb18 100644 --- a/tests/xml/test_speakElement.py +++ b/tests/xml/test_speakElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class SpeakElementTest(TestCase): +class SpeakElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is Test' \ 'This is Test' @@ -22,4 +23,4 @@ def test_set_methods(self): ).set_sip_headers(sip_headers) ) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_wElement.py b/tests/xml/test_wElement.py index 5b749a9c..d4cfcdb2 100644 --- a/tests/xml/test_wElement.py +++ b/tests/xml/test_wElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class WElementTest(TestCase): +class WElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = 'This is Test' \ 'This is Test' \ @@ -68,4 +69,4 @@ def test_set_methods(self): alias=alias_sub, )) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response) diff --git a/tests/xml/test_waitElement.py b/tests/xml/test_waitElement.py index e3ded1f6..e343dcee 100644 --- a/tests/xml/test_waitElement.py +++ b/tests/xml/test_waitElement.py @@ -1,9 +1,10 @@ from unittest import TestCase from plivo import plivoxml +from tests import PlivoXmlTestCase -class WaitElementTest(TestCase): +class WaitElementTest(TestCase, PlivoXmlTestCase): def test_set_methods(self): expected_response = '' @@ -19,4 +20,4 @@ def test_set_methods(self): ).set_min_silence(min_silence).set_beep(beep) ).to_string(False) - self.assertEqual(response, expected_response) + self.assertXmlEqual(response, expected_response)