Skip to content

Commit 84faadb

Browse files
author
MousumiMohanty
committed
created OmniVerify class and added retrieve functionality
1 parent 9142f6f commit 84faadb

File tree

8 files changed

+201
-13
lines changed

8 files changed

+201
-13
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,11 @@ If you use a Telesign SDK to make your request, authentication is handled behind
3535

3636
* Learn to send a request to Telesign with code with one of our [tutorials](https://developer.telesign.com/enterprise/docs/tutorials).
3737
* Browse our [Developer Portal](https://developer.telesign.com) for tutorials, how-to guides, reference content, and more.
38-
* Check out our [sample code](https://github.com/TeleSign/sample_code) on GitHub.
38+
* Check out our [sample code](https://github.com/TeleSign/sample_code) on GitHub.
39+
40+
3. Testing: Install pytest
41+
42+
`pip install pytest`
43+
44+
* Unit: pytest test_omniverify.py
45+
* Integration: pytest test_integration_omniverify.py

RELEASE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.3.0
2+
- Created OmniVerify class for adding retrieve verification process functionality
3+
- Updated the VerifyClient class
4+
- Added Unit and Integration tests to telesignenterpise.test folder
5+
16
2.2.2
27
- Added tracking to requests
38

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import print_function
2+
from telesignenterprise.omniverify import OmniVerify
3+
import json
4+
5+
customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
6+
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
7+
8+
phone_number = input("Please enter the phone number (with country code, digits only): ").strip()
9+
if not phone_number.isdigit():
10+
print("Error: phone number must contain digits only.")
11+
else:
12+
omniverify = OmniVerify(customer_id, api_key)
13+
14+
create_params = {
15+
"verification_policy": [{"method": "sms"}]
16+
}
17+
18+
create_response = omniverify.createVerificationProcess(phone_number, create_params)
19+
20+
if create_response.ok:
21+
reference_id = create_response.json.get("reference_id")
22+
print("Verification process created successfully.")
23+
print("Reference ID:", reference_id)
24+
else:
25+
print("Failed to create verification process.")
26+
print("Status code:", create_response.status_code)
27+
print("Response:", create_response.json)
28+
exit(1)
29+
30+
retrieve = input("Do you want to retrieve the verification process details now? (y/n): ").strip().lower()
31+
if retrieve == 'y':
32+
retrieve_response = omniverify.getVerificationProcess(reference_id)
33+
if retrieve_response.ok:
34+
print("Verification process details:")
35+
print(json.dumps(retrieve_response.json, indent=4))
36+
else:
37+
print("Failed to retrieve verification process.")
38+
print("Status code:", retrieve_response.status_code)
39+
print("Response:", retrieve_response.json)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from telesignenterprise.omniverify import OmniVerify
3+
4+
# Replace with actual credentials for successful test response
5+
CUSTOMER_ID = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
6+
API_KEY = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
7+
8+
@pytest.fixture(scope="module")
9+
def omniverify():
10+
if not CUSTOMER_ID or not API_KEY:
11+
pytest.skip("TELESIGN_CUSTOMER_ID and TELESIGN_API_KEY environment variables are required for integration tests.")
12+
return OmniVerify(CUSTOMER_ID, API_KEY)
13+
14+
def test_create_and_retrieve_verification_process(omniverify):
15+
phone_number = "11234567890" # Replace with a valid test phone number including country code
16+
17+
# Create verification process
18+
create_params = {
19+
"verification_policy": [{"method": "sms"}]
20+
}
21+
create_response = omniverify.createVerificationProcess(phone_number, create_params)
22+
23+
assert create_response.ok, f"Failed to create verification process: {create_response.json}"
24+
reference_id = create_response.json.get("reference_id")
25+
assert reference_id and len(reference_id) == 32, "Invalid reference_id returned"
26+
27+
# Retrieve verification process details
28+
retrieve_response = omniverify.getVerificationProcess(reference_id)
29+
assert retrieve_response.ok, f"Failed to retrieve verification process: {retrieve_response.json}"
30+
31+
data = retrieve_response.json
32+
assert "reference_id" in data and data["reference_id"] == reference_id
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
from unittest.mock import patch, MagicMock
3+
from telesignenterprise.omniverify import OmniVerify
4+
5+
@pytest.fixture
6+
def omniverify():
7+
customer_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
8+
api_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
9+
return OmniVerify(customer_id, api_key)
10+
11+
def test_create_verification_process_success(omniverify):
12+
phone_number = "11234567890"
13+
reference_id = "a" * 32
14+
15+
with patch.object(OmniVerify, 'post') as mock_post:
16+
mock_response = MagicMock()
17+
mock_response.ok = True
18+
mock_response.json = {"reference_id": reference_id}
19+
mock_post.return_value = mock_response
20+
21+
params = {"verification_policy": [{"method": "sms"}]}
22+
response = omniverify.createVerificationProcess(phone_number, params)
23+
24+
mock_post.assert_called_once()
25+
called_url = mock_post.call_args[0][0]
26+
called_json = mock_post.call_args[1]['json_fields']
27+
28+
assert called_url == "/verification"
29+
assert "recipient" in called_json
30+
assert called_json["recipient"]["phone_number"] == phone_number
31+
assert response.ok
32+
assert response.json["reference_id"] == reference_id
33+
34+
def test_get_verification_process_success(omniverify):
35+
reference_id = "a" * 32
36+
37+
with patch.object(OmniVerify, 'get') as mock_get:
38+
mock_response = MagicMock()
39+
mock_response.ok = True
40+
mock_response.json = {"status": "completed"}
41+
mock_get.return_value = mock_response
42+
43+
response = omniverify.getVerificationProcess(reference_id)
44+
45+
mock_get.assert_called_once()
46+
called_url = mock_get.call_args[0][0]
47+
48+
assert called_url == f"/verification/{reference_id}"
49+
assert response.ok
50+
assert response.json["status"] == "completed"
51+
52+
def test_get_verification_process_invalid_reference_id(omniverify):
53+
invalid_reference_id = "invalid_id"
54+
with pytest.raises(AssertionError):
55+
omniverify.getVerificationProcess(invalid_reference_id)

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
version = "2.2.2"
3+
version = "2.3.0"
44

55
try:
66
with open("README") as f:
@@ -25,12 +25,13 @@
2525
"Programming Language :: Python :: 3.4",
2626
"Programming Language :: Python :: 3.5",
2727
"Programming Language :: Python :: 3.6",
28+
"Programming Language :: Python :: 3.7",
2829
],
2930
long_description=readme_content,
3031
keywords='telesign, sms, voice, mobile, authentication, identity, messaging',
3132
author='TeleSign Corp.',
3233
author_email='support@telesign.com',
3334
url="https://github.com/telesign/python_telesign",
34-
install_requires=['telesign >=2.2.1, <2.3'],
35+
install_requires=['telesign >=2.2.1, <=2.3'],
3536
packages=find_packages(exclude=['test', 'test.*', 'examples', 'examples.*']),
3637
)

telesignenterprise/omniverify.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from __future__ import unicode_literals
2+
3+
from telesign.rest import RestClient
4+
from telesignenterprise.constants import SOURCE_SDK
5+
import telesignenterprise
6+
import telesign
7+
8+
BASE_URL_VERIFY_API = "https://verify.telesign.com"
9+
PATH_VERIFICATION_CREATE = "/verification"
10+
PATH_VERIFICATION_RETRIEVE = "/verification/{reference_id}"
11+
12+
class OmniVerify(RestClient):
13+
"""
14+
OmniVerify class to handle omnichannel verification API calls.
15+
"""
16+
17+
def __init__(self, customer_id, api_key, rest_endpoint=BASE_URL_VERIFY_API, **kwargs):
18+
super(OmniVerify, self).__init__(
19+
customer_id,
20+
api_key,
21+
rest_endpoint=rest_endpoint,
22+
**kwargs
23+
)
24+
self.rest_endpoint = rest_endpoint
25+
26+
def createVerificationProcess(self, phone_number, params={}):
27+
"""
28+
Use this action to create a verification process for the specified phone number.
29+
30+
See https://developer.telesign.com/enterprise/reference/createverificationprocess for detailed API documentation.
31+
"""
32+
params["recipient"] = {"phone_number": phone_number}
33+
34+
if "verification_policy" not in params:
35+
params["verification_policy"] = [{"method": "sms"}]
36+
37+
self.set_endpoint(BASE_URL_VERIFY_API)
38+
return self.post(PATH_VERIFICATION_CREATE, json_fields=params)
39+
40+
def getVerificationProcess(self, reference_id, params={}):
41+
"""
42+
Retrieve details about the specified verification process.
43+
44+
:param reference_id: The unique identifier of the verification process.
45+
:param params: Optional query parameters as a dictionary.
46+
:return: Response object from the GET request.
47+
"""
48+
assert isinstance(reference_id, str) and len(reference_id) == 32, "reference_id must be a 32-character string"
49+
50+
endpoint = PATH_VERIFICATION_RETRIEVE.format(reference_id=reference_id)
51+
self.set_endpoint(self.rest_endpoint)
52+
headers = {"Content-Type": "application/json", "Accept": "application/json"}
53+
54+
return self.get(endpoint, params=params, headers=headers)

telesignenterprise/verify.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from telesignenterprise.constants import SOURCE_SDK
55
import telesignenterprise
66
import telesign
7+
from telesignenterprise.omniverify import OmniVerify
78

89
VERIFY_SMS_RESOURCE = "/v1/verify/sms"
910
VERIFY_VOICE_RESOURCE = "/v1/verify/call"
@@ -35,20 +36,14 @@ def __init__(
3536
sdk_version_dependency=sdk_version_dependency,
3637
**kwargs
3738
)
39+
# Instantiate OmniVerify for omnichannel methods
40+
self.omniverify = OmniVerify(customer_id, api_key)
3841

3942
def createVerificationProcess(self, phone_number, params={}):
4043
"""
41-
Use this action to create a verification process for the specified phone number.
42-
43-
See https://developer.telesign.com/enterprise/reference/createverificationprocess for detailed API documentation.
44+
Proxy method to OmniVerify.createVerificationProcess for streamlined integration.
4445
"""
45-
params["recipient"] = {"phone_number": phone_number}
46-
47-
if "verification_policy" not in params:
48-
params["verification_policy"] = [{"method": "sms"}]
49-
50-
self.set_endpoint(BASE_URL_VERIFY_API)
51-
return self.post(PATH_VERIFICATION, json_fields=params)
46+
return self.omniverify.createVerificationProcess(phone_number, params)
5247

5348
def sms(self, phone_number, **params):
5449
"""

0 commit comments

Comments
 (0)