-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python SDK development for tollfree verification (#250)
* Python SDK development for tollfree verification * Adding _ in list API params * Correcting the error response of list API in error case * Adding another filter toll_free_sms_verification_order_status * Review changes * Change of variable name * Adding UTC and fixtures * Resolving failing UTC * Renaming fixture files * Renaming function names in UTCs * Resolving bugs in UTCs * version update --------- Co-authored-by: Kapil Patwa <[email protected]>
- Loading branch information
1 parent
489edb8
commit 045f6bc
Showing
13 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from ..utils.validators import * | ||
|
||
from ..base import PlivoResource, PlivoResourceInterface, ListTollfreeVerificationResponseObject | ||
from ..exceptions import * | ||
from ..utils import * | ||
|
||
|
||
class TollfreeVerification(PlivoResource): | ||
_name = 'TollfreeVerification' | ||
_identifier_string = 'uuid' | ||
|
||
def delete(self): | ||
return self.client.tollfree_verification.delete(tollfree_verification_uuid=self.uuid) | ||
|
||
def update(self, | ||
profile_uuid=None, | ||
usecase=None, | ||
usecase_summary=None, | ||
message_sample=None, | ||
optin_image_url=None, | ||
volume=None, | ||
additional_information=None, | ||
extra_data=None, | ||
optin_type=None, | ||
callback_url=None, | ||
callback_method=None): | ||
return self.client.tollfree_verification.update(self.uuid, profile_uuid=profile_uuid, usecase=usecase, | ||
usecase_summary=usecase_summary, message_sample=message_sample, | ||
optin_image_url=optin_image_url, volume=volume, | ||
additional_information=additional_information, | ||
extra_data=extra_data, optin_type=optin_type, | ||
callback_url=callback_url, callback_method=callback_method) | ||
|
||
class TollfreeVerifications(PlivoResourceInterface): | ||
def __init__(self, client): | ||
self._resource_type = TollfreeVerification | ||
super(TollfreeVerifications, self).__init__(client) | ||
|
||
def create(self, | ||
profile_uuid=None, | ||
usecase=None, | ||
usecase_summary=None, | ||
message_sample=None, | ||
optin_image_url=None, | ||
volume=None, | ||
number=None, | ||
additional_information=None, | ||
extra_data=None, | ||
optin_type=None, | ||
callback_url=None, | ||
callback_method=None): | ||
return self.client.request( | ||
'POST', ('TollfreeVerification',), to_param_dict(self.create, locals())) | ||
|
||
def get(self, tollfree_verification_uuid=None): | ||
return self.client.request( | ||
'GET', ('TollfreeVerification', tollfree_verification_uuid), response_type=TollfreeVerification) | ||
|
||
def list(self, | ||
number=None, | ||
status=None, | ||
profile_uuid=None, | ||
created__gt=None, | ||
created__gte=None, | ||
created__lt=None, | ||
created__lte=None, | ||
usecase=None, | ||
limit=20, | ||
offset=0): | ||
return self.client.request( | ||
'GET', ('TollfreeVerification',), to_param_dict(self.list, locals()), | ||
objects_type=TollfreeVerification, response_type=ListTollfreeVerificationResponseObject, ) | ||
|
||
def update(self, tollfree_verification_uuid=None, | ||
profile_uuid=None, | ||
usecase=None, | ||
usecase_summary=None, | ||
message_sample=None, | ||
optin_image_url=None, | ||
volume=None, | ||
additional_information=None, | ||
extra_data=None, | ||
optin_type=None, | ||
callback_url=None, | ||
callback_method=None): | ||
return self.client.request( | ||
'POST', ('TollfreeVerification', tollfree_verification_uuid), to_param_dict(self.update, locals())) | ||
|
||
def delete(self, tollfree_verification_uuid=None): | ||
return self.client.request('DELETE', ('TollfreeVerification', tollfree_verification_uuid)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
__version__ = '4.44.0' | ||
__version__ = '4.45.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/resources/fixtures/tollfreeVerificationCreateResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"api_id": "5a9fcb68-582d-11e1-86da-6ff39efcb949", | ||
"message": "Tollfree verification request for 18339404937 submitted succesfully", | ||
"uuid": "f19c4773-4ae6-4b75-92ea-9cf3ea4227d6" | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/resources/fixtures/tollfreeVerificationGetResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"api_id": "4e1f954c-baf3-11ec-bafe-0242ac110003", | ||
"additional_information": "", | ||
"callback_method": "POST", | ||
"callback_url": "http://plivobin-prod-usw1.plivops.com/1e4jvpt1", | ||
"created": "2023-10-12T15:28:10.216507Z", | ||
"extra_data": "", | ||
"message_sample": "1.Your Plivo verification code is xxxx. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"number": "18449605287", | ||
"optin_image_url": "https://www.plivo.com", | ||
"optin_type": "MOBILE_QR_CODE", | ||
"profile_uuid": "0ead82e0-fc80-4dc3-888b-7778932cf134", | ||
"error_message": "Demo Testing Sanity", | ||
"status": "REJECTED", | ||
"last_modified": "2023-10-13T08:24:26.619565Z", | ||
"usecase": "2FA", | ||
"usecase_summary": "1.We send 2FA codes to customers when they signup. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"uuid": "312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | ||
"volume": "100" | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/resources/fixtures/tollfreeVerificationListResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"api_id": "4e15f360-72fe-11ee-8538-e20bbbfb283e", | ||
"meta": { | ||
"count": 2, | ||
"limit": 10, | ||
"next": null, | ||
"offset": 10, | ||
"previous": "/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/?limit=10&offset=0" | ||
}, | ||
"objects": [ | ||
{ | ||
"additional_information": "", | ||
"callback_method": "POST", | ||
"callback_url": "http://plivobin-prod-usw1.plivops.com/1e4jvpt1", | ||
"created": "2023-10-12T15:28:10.216507Z", | ||
"extra_data": "", | ||
"message_sample": "1.Your Plivo verification code is xxxx. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"number": "18449605287", | ||
"optin_image_url": "https://www.plivo.com", | ||
"optin_type": "MOBILE_QR_CODE", | ||
"profile_uuid": "0ead82e0-fc80-4dc3-888b-7778932cf134", | ||
"error_message": "Demo Testing Sanity", | ||
"status": "REJECTED", | ||
"last_modified": "2023-10-13T08:24:26.619565Z", | ||
"usecase": "2FA", | ||
"usecase_summary": "1.We send 2FA codes to customers when they signup. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"uuid": "312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | ||
"volume": "100" | ||
}, | ||
{ | ||
"additional_information": "", | ||
"callback_method": "POST", | ||
"callback_url": "http://plivobin-prod-usw1.plivops.com/1e4jvpt1", | ||
"created": "2023-10-12T12:06:46.527653Z", | ||
"extra_data": "", | ||
"message_sample": "1.Your Plivo verification code is xxxx. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"number": "18449605287", | ||
"optin_image_url": "https://www.plivo.com", | ||
"optin_type": "MOBILE_QR_CODE", | ||
"profile_uuid": "0ead82e0-fc80-4dc3-888b-7778932cf134", | ||
"error_message": "Demo Testing Sanity", | ||
"status": "REJECTED", | ||
"last_modified": "2023-10-12T15:27:56.052433Z", | ||
"usecase": "2FA", | ||
"usecase_summary": "1.We send 2FA codes to customers when they signup. 2.Dear <customer name>, you have signed up on Plivo successfully.", | ||
"uuid": "96ec880d-b7ee-4eb5-7c9a-3ff28826e77c", | ||
"volume": "100" | ||
} | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/resources/fixtures/tollfreeVerificationUpdateResponse.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"api_id": "4e1f954c-baf3-11ec-bafe-0242ac110003", | ||
"message": "Tollfree verification request for 18339404937 updated succesfully" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import plivo | ||
from tests.base import PlivoResourceTestCase | ||
from tests.decorators import with_response | ||
|
||
|
||
class TollfreeVerificationTest(PlivoResourceTestCase): | ||
@with_response(200) | ||
def test_list(self): | ||
tollfree_verification = self.client.tollfree_verification.list(offset=10, limit=10) | ||
|
||
# Verifying the endpoint hit | ||
self.assertUrlEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/?limit=10&offset=10', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('GET', self.client.current_request.method) | ||
|
||
self.assertEqual('312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX', tollfree_verification.objects[0].uuid) | ||
|
||
# Test if ListResponseObject's __iter__ is working correctly | ||
self.assertEqual(len(list(tollfree_verification)), 2) | ||
|
||
|
||
@with_response(200) | ||
def test_get(self): | ||
tollfree_verficiation = self.client.tollfree_verification.get( | ||
tollfree_verification_uuid="312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX") | ||
|
||
self.assertResponseMatches(tollfree_verficiation) | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('GET', self.client.current_request.method) | ||
|
||
# Verifying the object type returned | ||
self.assertEqual(plivo.resources.tollfree_verification.TollfreeVerification, | ||
tollfree_verficiation.__class__) | ||
|
||
self.assertEqual('312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX', tollfree_verficiation.uuid) | ||
|
||
@with_response(202) | ||
def test_update(self): | ||
updated_app = self.client.tollfree_verification.update( | ||
tollfree_verification_uuid="312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | ||
extra_data='Testing the update of extra data in python-SDK') | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('POST', self.client.current_request.method) | ||
|
||
def test_delete(self): | ||
expected_response = {} | ||
|
||
self.client.set_expected_response( | ||
status_code=204, data_to_return=expected_response) | ||
|
||
response = self.client.tollfree_verification.delete( | ||
tollfree_verification_uuid="312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX") | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/312b3119-XXXX-XXXX-XXXX-XXXXXXXXXXXX/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('DELETE', self.client.current_request.method) | ||
|
||
@with_response(201) | ||
def test_create(self): | ||
response = self.client.tollfree_verification.create( | ||
usecase="2FA", | ||
number="18554950186", | ||
profile_uuid="42f92135-6ec2-4110-8da4-71171f6aad44", | ||
optin_type="VERBAL", | ||
volume="100", | ||
usecase_summary="hbv", | ||
message_sample="message_sample", | ||
callback_url="https://plivobin-prod-usw1.plivops.com/1pcfjrt1", | ||
callback_method="POST", | ||
optin_image_url="http://aaa.com", | ||
additional_information="this is additional_information", | ||
extra_data="this is extra_data", | ||
) | ||
|
||
# Verifying the endpoint hit | ||
self.assertEqual( | ||
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/', | ||
self.client.current_request.url) | ||
|
||
# Verifying the method used | ||
self.assertEqual('POST', self.client.current_request.method) |