Skip to content

Commit

Permalink
adding fraud_check parameter to verify v2 request
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed May 15, 2023
1 parent a4aa709 commit 31a4054
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/vonage/verify2.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class VerifyRequest(BaseModel):
channel_timeout: Optional[conint(ge=60, le=900)]
client_ref: Optional[str]
code_length: Optional[conint(ge=4, le=10)]
fraud_check: Optional[bool]
code: Optional[constr(min_length=4, max_length=10, regex='^(?=[a-zA-Z0-9]{4,10}$)[a-zA-Z0-9]*$')]

@validator('workflow')
Expand Down
1 change: 0 additions & 1 deletion tests/data/null.json

This file was deleted.

6 changes: 6 additions & 0 deletions tests/data/verify2/already_verified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "https://developer.nexmo.com/api-errors#not-found",
"title": "Not Found",
"detail": "Request '5fcc26ef-1e54-48a6-83ab-c47546a19824' was not found or it has been verified already.",
"instance": "02cabfcc-2e09-4b5d-b098-1fa7ccef4607"
}
4 changes: 4 additions & 0 deletions tests/data/verify2/check_code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"request_id": "e043d872-459b-4750-a20c-d33f91d6959f",
"status": "completed"
}
6 changes: 6 additions & 0 deletions tests/data/verify2/fraud_check_invalid_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "https://developer.nexmo.com/api-errors#forbidden",
"title": "Forbidden",
"detail": "Your account does not have permission to perform this action.",
"instance": "1995bc0d-c850-4bf0-aa1e-6c40da43d3bf"
}
46 changes: 44 additions & 2 deletions tests/test_verify2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_new_request_sms_full():
'channel_timeout': 120,
'client_ref': 'my client ref',
'code_length': 8,
'fraud_check': False,
'brand': 'ACME, Inc',
'workflow': [{'channel': 'sms', 'to': '447700900000', 'app_hash': 'asdfghjklqw'}],
}
Expand All @@ -48,6 +49,25 @@ def test_new_request_sms_custom_code(dummy_data):
assert verify_request['request_id'] == 'c11236f4-00bf-4b89-84ba-88b25df97315'


@responses.activate
def test_new_request_error_fraud_check_invalid_account(dummy_data):
stub(
responses.POST,
'https://api.nexmo.com/v2/verify',
fixture_path='verify2/fraud_check_invalid_account.json',
status_code=403,
)

params = {'brand': 'ACME, Inc', 'fraud_check': False, 'workflow': [{'channel': 'sms', 'to': '447700900000'}]}

with raises(ClientError) as err:
verify2.new_request(params)
assert (
str(err.value)
== 'Forbidden: Your account does not have permission to perform this action. (https://developer.nexmo.com/api-errors#forbidden)'
)


def test_new_request_sms_custom_code_length_error():
params = {
'code_length': 4,
Expand Down Expand Up @@ -306,10 +326,14 @@ def test_new_request_rate_limit():
@responses.activate
def test_check_code():
stub(
responses.POST, 'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315', fixture_path='null.json'
responses.POST,
'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315',
fixture_path='verify2/check_code.json',
)

assert verify2.check_code('c11236f4-00bf-4b89-84ba-88b25df97315', '1234') == None
response = verify2.check_code('c11236f4-00bf-4b89-84ba-88b25df97315', '1234')
assert response['request_id'] == 'e043d872-459b-4750-a20c-d33f91d6959f'
assert response['status'] == 'completed'


@responses.activate
Expand All @@ -330,6 +354,24 @@ def test_check_code_invalid_code():
)


@responses.activate
def test_check_code_already_verified():
stub(
responses.POST,
'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315',
fixture_path='verify2/already_verified.json',
status_code=404,
)

with pytest.raises(ClientError) as err:
verify2.check_code('c11236f4-00bf-4b89-84ba-88b25df97315', '5678')

assert (
str(err.value)
== "Not Found: Request '5fcc26ef-1e54-48a6-83ab-c47546a19824' was not found or it has been verified already. (https://developer.nexmo.com/api-errors#not-found)"
)


@responses.activate
def test_check_code_workflow_not_supported():
stub(
Expand Down

0 comments on commit 31a4054

Please sign in to comment.