Skip to content
Open
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
13 changes: 11 additions & 2 deletions testutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from .mock_auth import get_mock_api_key_auth, get_mock_jwt_auth
from .mock_auth import (
get_base64_encoded_api_key_and_secret,
get_mock_api_key_auth,
get_mock_jwt_auth,
)
from .testutils import build_response

__all__ = ['build_response', 'get_mock_api_key_auth', 'get_mock_jwt_auth']
__all__ = [
'build_response',
'get_mock_api_key_auth',
'get_mock_jwt_auth',
'get_base64_encoded_api_key_and_secret',
]
12 changes: 11 additions & 1 deletion testutils/mock_auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from base64 import b64encode
from os.path import dirname, join

from vonage_http_client.auth import Auth

test_api_key = 'test_api_key'
test_api_secret = 'test_api_secret'


def read_file(path):
"""Read a file from the testutils/data directory."""
Expand All @@ -10,10 +14,16 @@ def read_file(path):
return input_file.read()


def get_base64_encoded_api_key_and_secret():
"""Return a base64 encoded string of the API key and secret."""

return b64encode(f'{test_api_key}:{test_api_secret}'.encode('utf-8')).decode('ascii')


def get_mock_api_key_auth():
"""Return an Auth object with an API key and secret."""

return Auth(api_key='test_api_key', api_secret='test_api_secret')
return Auth(api_key=test_api_key, api_secret=test_api_secret)


def get_mock_jwt_auth():
Expand Down
2 changes: 1 addition & 1 deletion verify_legacy/src/vonage_verify_legacy/verify_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class VerifyLegacy:
def __init__(self, http_client: HttpClient) -> None:
self._http_client = http_client
self._sent_data_type = 'form'
self._auth_type = 'body'
self._auth_type = 'basic'

@property
def http_client(self) -> HttpClient:
Expand Down
60 changes: 59 additions & 1 deletion verify_legacy/tests/test_verify_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from vonage_verify_legacy.responses import NetworkUnblockStatus, VerifyControlStatus
from vonage_verify_legacy.verify_legacy import VerifyLegacy

from testutils import build_response, get_mock_api_key_auth
from testutils import (
build_response,
get_base64_encoded_api_key_and_secret,
get_mock_api_key_auth,
)

path = abspath(__file__)

Expand All @@ -32,6 +36,12 @@ def test_http_client_property():
assert isinstance(verify.http_client, HttpClient)


@responses.activate
def test_default_auth_type():
verify = VerifyLegacy(HttpClient(get_mock_api_key_auth()))
assert verify._auth_type == 'basic'


def test_create_verify_request_model():
params = {'brand': 'Acme Inc.', 'sender_id': 'Acme', 'lg': LanguageCode.en_us, **data}
request = VerifyRequest(**params)
Expand Down Expand Up @@ -67,6 +77,12 @@ def test_make_verify_request():
assert response.request_id == 'abcdef0123456789abcdef0123456789'
assert response.status == '0'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_make_psd2_request():
Expand All @@ -80,6 +96,12 @@ def test_make_psd2_request():
assert response.request_id == 'abcdef0123456789abcdef0123456789'
assert response.status == '0'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_verify_request_error():
Expand Down Expand Up @@ -129,6 +151,12 @@ def test_check_code():
assert response.currency == 'EUR'
assert response.estimated_price_messages_sent == '0.04675'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_check_code_error():
Expand Down Expand Up @@ -170,6 +198,12 @@ def test_search():
assert response.events[0].type == 'sms'
assert response.events[0].id == '23f3a13d-6d03-4262-8f4d-67f12a56e1c8'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_search_list_of_ids():
Expand All @@ -187,6 +221,12 @@ def test_search_list_of_ids():
assert response1.status == 'SUCCESS'
assert response1.checks[0].status == 'VALID'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_search_error():
Expand Down Expand Up @@ -217,6 +257,12 @@ def test_cancel_verification():
assert response.status == '0'
assert response.command == 'cancel'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_cancel_verification_error():
Expand Down Expand Up @@ -249,6 +295,12 @@ def test_trigger_next_event():
assert response.status == '0'
assert response.command == 'trigger_next_event'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_trigger_next_event_error():
Expand Down Expand Up @@ -283,6 +335,12 @@ def test_request_network_unblock():
assert response.network == '23410'
assert response.unblocked_until == '2024-04-22T08:34:58Z'

request_headers = responses.calls[0].request.headers
assert (
request_headers["Authorization"]
== "Basic " + get_base64_encoded_api_key_and_secret()
)


@responses.activate
def test_request_network_unblock_error():
Expand Down
Loading