22
33import responses
44from pytest import raises
5+ from vonage_http_client .auth import Auth
56from vonage_http_client .errors import HttpRequestError
67from vonage_http_client .http_client import HttpClient
78from vonage_verify .requests import *
89from vonage_verify .verify import Verify
910
10- from testutils import build_response , get_mock_jwt_auth
11+ from testutils import build_response , get_mock_api_key_auth , get_mock_jwt_auth
1112
1213path = abspath (__file__ )
1314
1415
1516verify = Verify (HttpClient (get_mock_jwt_auth ()))
1617
1718
19+ @responses .activate
20+ def test_default_auth_type ():
21+ verify = Verify (
22+ HttpClient (
23+ Auth (
24+ api_key = 'asdf' ,
25+ api_secret = 'asdf' ,
26+ application_id = 'asdf' ,
27+ private_key = '-----BEGIN PRIVATE KEY-----\n MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDZz9Zz\n -----END PRIVATE-KEY----' ,
28+ )
29+ )
30+ )
31+ assert verify ._auth_type == 'jwt'
32+
33+
1834@responses .activate
1935def test_make_verify_request ():
2036 build_response (
@@ -37,6 +53,27 @@ def test_make_verify_request():
3753 == 'https://api-eu-3.vonage.com/v2/verify/cfbc9a3b-27a2-40d4-a4e0-0c59b3b41901/silent-auth/redirect'
3854 )
3955 assert verify ._http_client .last_response .status_code == 202
56+ assert verify ._auth_type == 'jwt'
57+
58+
59+ @responses .activate
60+ def test_make_verify_request_basic_auth ():
61+ build_response (
62+ path , 'POST' , 'https://api.nexmo.com/v2/verify' , 'verify_request.json' , 202
63+ )
64+ sms_channel = SmsChannel (channel = ChannelType .SMS , to = '1234567890' , from_ = 'Vonage' )
65+ params = {
66+ 'brand' : 'Vonage' ,
67+ 'workflow' : [sms_channel ],
68+ }
69+ request = VerifyRequest (** params )
70+
71+ verify = Verify (HttpClient (get_mock_api_key_auth ()))
72+
73+ response = verify .start_verification (request )
74+ assert response .request_id == '2c59e3f4-a047-499f-a14f-819cd1989d2e'
75+ assert verify ._http_client .last_response .status_code == 202
76+ assert verify ._auth_type == 'basic'
4077
4178
4279@responses .activate
@@ -108,6 +145,23 @@ def test_check_code():
108145 assert response .status == 'completed'
109146
110147
148+ @responses .activate
149+ def test_check_code_basic_auth ():
150+ build_response (
151+ path ,
152+ 'POST' ,
153+ 'https://api.nexmo.com/v2/verify/36e7060d-2b23-4257-bad0-773ab47f85ef' ,
154+ 'check_code.json' ,
155+ )
156+ verify = Verify (HttpClient (get_mock_api_key_auth ()))
157+ response = verify .check_code (
158+ request_id = '36e7060d-2b23-4257-bad0-773ab47f85ef' , code = '1234'
159+ )
160+ assert response .request_id == '36e7060d-2b23-4257-bad0-773ab47f85ef'
161+ assert response .status == 'completed'
162+ assert verify ._auth_type == 'basic'
163+
164+
111165@responses .activate
112166def test_check_code_invalid_code_error ():
113167 build_response (
@@ -153,6 +207,20 @@ def test_cancel_verification():
153207 assert verify ._http_client .last_response .status_code == 204
154208
155209
210+ @responses .activate
211+ def test_cancel_verification_basic_auth ():
212+ responses .add (
213+ responses .DELETE ,
214+ 'https://api.nexmo.com/v2/verify/36e7060d-2b23-4257-bad0-773ab47f85ef' ,
215+ status = 204 ,
216+ )
217+
218+ verify = Verify (HttpClient (get_mock_api_key_auth ()))
219+ assert verify .cancel_verification ('36e7060d-2b23-4257-bad0-773ab47f85ef' ) is None
220+ assert verify ._http_client .last_response .status_code == 204
221+ assert verify ._auth_type == 'basic'
222+
223+
156224@responses .activate
157225def test_trigger_next_workflow ():
158226 responses .add (
@@ -164,6 +232,20 @@ def test_trigger_next_workflow():
164232 assert verify ._http_client .last_response .status_code == 200
165233
166234
235+ @responses .activate
236+ def test_trigger_next_workflow_basic_auth ():
237+ responses .add (
238+ responses .POST ,
239+ 'https://api.nexmo.com/v2/verify/36e7060d-2b23-4257-bad0-773ab47f85ef/next_workflow' ,
240+ status = 200 ,
241+ )
242+
243+ verify = Verify (HttpClient (get_mock_api_key_auth ()))
244+ assert verify .trigger_next_workflow ('36e7060d-2b23-4257-bad0-773ab47f85ef' ) is None
245+ assert verify ._http_client .last_response .status_code == 200
246+ assert verify ._auth_type == 'basic'
247+
248+
167249@responses .activate
168250def test_trigger_next_event_error ():
169251 build_response (
0 commit comments