diff --git a/src/vonage/account.py b/src/vonage/account.py index 4185decd..32968dcc 100644 --- a/src/vonage/account.py +++ b/src/vonage/account.py @@ -1,6 +1,8 @@ from .errors import PricingTypeError from deprecated import deprecated + + class Account: account_auth_type = 'params' pricing_auth_type = 'params' @@ -12,13 +14,15 @@ def __init__(self, client): self._client = client def get_balance(self): - return self._client.get(self._client.host(), "/account/get-balance", auth_type=Account.account_auth_type) + return self._client.get( + self._client.host(), "/account/get-balance", auth_type=Account.account_auth_type + ) def topup(self, params=None, **kwargs): return self._client.post( - self._client.host(), + self._client.host(), "/account/top-up", - params or kwargs, + params or kwargs, auth_type=Account.account_auth_type, body_is_json=False, ) @@ -26,22 +30,24 @@ def topup(self, params=None, **kwargs): def get_country_pricing(self, country_code: str, type: str = 'sms'): self._check_allowed_pricing_type(type) return self._client.get( - self._client.host(), - f"/account/get-pricing/outbound/{type}", + self._client.host(), + f"/account/get-pricing/outbound/{type}", {"country": country_code}, - auth_type=Account.pricing_auth_type + auth_type=Account.pricing_auth_type, ) def get_all_countries_pricing(self, type: str = 'sms'): self._check_allowed_pricing_type(type) return self._client.get( - self._client.host(), f"/account/get-full-pricing/outbound/{type}", auth_type=Account.pricing_auth_type + self._client.host(), + f"/account/get-full-pricing/outbound/{type}", + auth_type=Account.pricing_auth_type, ) def get_prefix_pricing(self, prefix: str, type: str = 'sms'): self._check_allowed_pricing_type(type) return self._client.get( - self._client.host(), + self._client.host(), f"/account/get-prefix-pricing/outbound/{type}", {"prefix": prefix}, auth_type=Account.pricing_auth_type, @@ -50,8 +56,8 @@ def get_prefix_pricing(self, prefix: str, type: str = 'sms'): @deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.') def get_sms_pricing(self, number: str): return self._client.get( - self._client.host(), - "/account/get-phone-pricing/outbound/sms", + self._client.host(), + "/account/get-phone-pricing/outbound/sms", {"phone": number}, auth_type=Account.pricing_auth_type, ) @@ -59,16 +65,16 @@ def get_sms_pricing(self, number: str): @deprecated(version='3.0.0', reason='The "account/get-phone-pricing" endpoint is deprecated.') def get_voice_pricing(self, number: str): return self._client.get( - self._client.host(), - "/account/get-phone-pricing/outbound/voice", + self._client.host(), + "/account/get-phone-pricing/outbound/voice", {"phone": number}, auth_type=Account.pricing_auth_type, ) def update_default_sms_webhook(self, params=None, **kwargs): return self._client.post( - self._client.host(), - "/account/settings", + self._client.host(), + "/account/settings", params or kwargs, auth_type=Account.account_auth_type, body_is_json=False, @@ -91,7 +97,7 @@ def get_secret(self, api_key, secret_id): def create_secret(self, api_key, secret): body = {"secret": secret} return self._client.post( - self._client.api_host(), + self._client.api_host(), f"/accounts/{api_key}/secrets", body, auth_type=Account.secrets_auth_type, diff --git a/src/vonage/application.py b/src/vonage/application.py index 68997e25..c5398a76 100644 --- a/src/vonage/application.py +++ b/src/vonage/application.py @@ -1,7 +1,11 @@ from deprecated import deprecated -@deprecated(version='3.0.0', reason='Renamed to Application as V1 is out of support and this new \ - naming is in line with other APIs. Please use Application instead.') + +@deprecated( + version='3.0.0', + reason='Renamed to Application as V1 is out of support and this new \ + naming is in line with other APIs. Please use Application instead.', +) class ApplicationV2: auth_type = 'header' @@ -83,6 +87,7 @@ def list_applications(self, page_size=None, page=None): auth_type=ApplicationV2.auth_type, ) + class Application: auth_type = 'header' diff --git a/src/vonage/ncco_builder/ncco.py b/src/vonage/ncco_builder/ncco.py index 2a5698e9..de630129 100644 --- a/src/vonage/ncco_builder/ncco.py +++ b/src/vonage/ncco_builder/ncco.py @@ -107,9 +107,13 @@ def ensure_url_in_list(cls, v): @validator('advancedMachineDetection') def validate_advancedMachineDetection(cls, v): if 'behavior' in v and v['behavior'] not in ('continue', 'hangup'): - raise ValueError('advancedMachineDetection["behavior"] must be one of: "continue", "hangup".') + raise ValueError( + 'advancedMachineDetection["behavior"] must be one of: "continue", "hangup".' + ) if 'mode' in v and v['mode'] not in ('detect, detect_beep'): - raise ValueError('advancedMachineDetection["mode"] must be one of: "detect", "detect_beep".') + raise ValueError( + 'advancedMachineDetection["mode"] must be one of: "detect", "detect_beep".' + ) return v class Config: @@ -145,7 +149,10 @@ class Input(Action): action = Field('input', const=True) type: Union[ - Literal['dtmf', 'speech'], List[Literal['dtmf']], List[Literal['speech']], List[Literal['dtmf', 'speech']] + Literal['dtmf', 'speech'], + List[Literal['dtmf']], + List[Literal['speech']], + List[Literal['dtmf', 'speech']], ] dtmf: Optional[Union[InputTypes.Dtmf, dict]] speech: Optional[Union[InputTypes.Speech, dict]] diff --git a/src/vonage/ncco_builder/pay_prompts.py b/src/vonage/ncco_builder/pay_prompts.py index 4463a7f8..11ecb404 100644 --- a/src/vonage/ncco_builder/pay_prompts.py +++ b/src/vonage/ncco_builder/pay_prompts.py @@ -12,7 +12,13 @@ class TextPrompt(BaseModel): type: Literal['CardNumber', 'ExpirationDate', 'SecurityCode'] text: str errors: Dict[ - Literal['InvalidCardType', 'InvalidCardNumber', 'InvalidExpirationDate', 'InvalidSecurityCode', 'Timeout'], + Literal[ + 'InvalidCardType', + 'InvalidCardNumber', + 'InvalidExpirationDate', + 'InvalidSecurityCode', + 'Timeout', + ], Dict[Literal['text'], str], ] @@ -32,7 +38,9 @@ def check_valid_error_format(cls, v, values): def check_allowed_values(errors, allowed_values, prompt_type): for key in errors: if key not in allowed_values: - raise ValueError(f'Value "{key}" is not a valid error for the "{prompt_type}" prompt type.') + raise ValueError( + f'Value "{key}" is not a valid error for the "{prompt_type}" prompt type.' + ) @classmethod def create_voice_model(cls, dict) -> VoicePrompt: diff --git a/src/vonage/number_insight.py b/src/vonage/number_insight.py index b63dde13..2b57dfb3 100644 --- a/src/vonage/number_insight.py +++ b/src/vonage/number_insight.py @@ -1,28 +1,48 @@ from .errors import CallbackRequiredError + class NumberInsight: auth_type = 'params' - + def __init__(self, client): self._client = client def get_basic_number_insight(self, params=None, **kwargs): - return self._client.get(self._client.api_host(), "/ni/basic/json", params or kwargs, auth_type=NumberInsight.auth_type) + return self._client.get( + self._client.api_host(), + "/ni/basic/json", + params or kwargs, + auth_type=NumberInsight.auth_type, + ) def get_standard_number_insight(self, params=None, **kwargs): - return self._client.get(self._client.api_host(), "/ni/standard/json", params or kwargs, auth_type=NumberInsight.auth_type) + return self._client.get( + self._client.api_host(), + "/ni/standard/json", + params or kwargs, + auth_type=NumberInsight.auth_type, + ) def get_advanced_number_insight(self, params=None, **kwargs): - return self._client.get(self._client.api_host(), "/ni/advanced/json", params or kwargs, auth_type=NumberInsight.auth_type) + return self._client.get( + self._client.api_host(), + "/ni/advanced/json", + params or kwargs, + auth_type=NumberInsight.auth_type, + ) def get_async_advanced_number_insight(self, params=None, **kwargs): argoparams = params or kwargs - if "callback" in argoparams and type(argoparams["callback"]) == str and argoparams["callback"] != "": + if ( + "callback" in argoparams + and type(argoparams["callback"]) == str + and argoparams["callback"] != "" + ): return self._client.get( - self._client.api_host(), "/ni/advanced/async/json", params or kwargs, auth_type=NumberInsight.auth_type + self._client.api_host(), + "/ni/advanced/async/json", + params or kwargs, + auth_type=NumberInsight.auth_type, ) else: - raise CallbackRequiredError( - "A callback is needed for async advanced number insight" - ) - \ No newline at end of file + raise CallbackRequiredError("A callback is needed for async advanced number insight") diff --git a/src/vonage/number_management.py b/src/vonage/number_management.py index 65f04ae3..41645372 100644 --- a/src/vonage/number_management.py +++ b/src/vonage/number_management.py @@ -6,7 +6,9 @@ def __init__(self, client): self._client = client def get_account_numbers(self, params=None, **kwargs): - return self._client.get(self._client.host(), "/account/numbers", params or kwargs, auth_type=Numbers.auth_type) + return self._client.get( + self._client.host(), "/account/numbers", params or kwargs, auth_type=Numbers.auth_type + ) def get_available_numbers(self, country_code, params=None, **kwargs): return self._client.get( @@ -17,10 +19,16 @@ def get_available_numbers(self, country_code, params=None, **kwargs): ) def buy_number(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/number/buy", params or kwargs, **Numbers.defaults) + return self._client.post( + self._client.host(), "/number/buy", params or kwargs, **Numbers.defaults + ) def cancel_number(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/number/cancel", params or kwargs, **Numbers.defaults) + return self._client.post( + self._client.host(), "/number/cancel", params or kwargs, **Numbers.defaults + ) def update_number(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/number/update", params or kwargs, **Numbers.defaults) + return self._client.post( + self._client.host(), "/number/update", params or kwargs, **Numbers.defaults + ) diff --git a/src/vonage/redact.py b/src/vonage/redact.py index 1e1fb5f4..c1ec18f5 100644 --- a/src/vonage/redact.py +++ b/src/vonage/redact.py @@ -2,7 +2,11 @@ from deprecated import deprecated -@deprecated(version='3.0.0', reason='This is a dev preview product and as such is not supported in this SDK.') + +@deprecated( + version='3.0.0', + reason='This is a dev preview product and as such is not supported in this SDK.', +) class Redact: auth_type = 'header' @@ -16,10 +20,12 @@ def redact_transaction(self, id: str, product: str, type=None): params = {"id": id, "product": product} if type is not None: params["type"] = type - return self._client.post(self._client.api_host(), "/v1/redact/transaction", params, auth_type=Redact.auth_type) + return self._client.post( + self._client.api_host(), "/v1/redact/transaction", params, auth_type=Redact.auth_type + ) def _check_allowed_product_name(self, product): if product not in self.allowed_product_names: raise RedactError( f'Invalid product name in redact request. Must be one of {self.allowed_product_names}.' - ) \ No newline at end of file + ) diff --git a/src/vonage/short_codes.py b/src/vonage/short_codes.py index 43464b6b..03150804 100644 --- a/src/vonage/short_codes.py +++ b/src/vonage/short_codes.py @@ -6,18 +6,29 @@ def __init__(self, client): self._client = client def send_2fa_message(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/sc/us/2fa/json", params or kwargs, **ShortCodes.defaults) + return self._client.post( + self._client.host(), "/sc/us/2fa/json", params or kwargs, **ShortCodes.defaults + ) def send_event_alert_message(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/sc/us/alert/json", params or kwargs, **ShortCodes.defaults) + return self._client.post( + self._client.host(), "/sc/us/alert/json", params or kwargs, **ShortCodes.defaults + ) def send_marketing_message(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/sc/us/marketing/json", params or kwargs, **ShortCodes.defaults) + return self._client.post( + self._client.host(), "/sc/us/marketing/json", params or kwargs, **ShortCodes.defaults + ) def get_event_alert_numbers(self): - return self._client.get(self._client.host(), "/sc/us/alert/opt-in/query/json", auth_type=ShortCodes.auth_type) + return self._client.get( + self._client.host(), "/sc/us/alert/opt-in/query/json", auth_type=ShortCodes.auth_type + ) def resubscribe_event_alert_number(self, params=None, **kwargs): return self._client.post( - self._client.host(), "/sc/us/alert/opt-in/manage/json", params or kwargs, **ShortCodes.defaults) - \ No newline at end of file + self._client.host(), + "/sc/us/alert/opt-in/manage/json", + params or kwargs, + **ShortCodes.defaults, + ) diff --git a/src/vonage/sms.py b/src/vonage/sms.py index ab676fc2..1eee72ac 100644 --- a/src/vonage/sms.py +++ b/src/vonage/sms.py @@ -2,12 +2,13 @@ from datetime import datetime from ._internal import _format_date_param + class Sms: defaults = {'auth_type': 'params', 'body_is_json': False} def __init__(self, client): self._client = client - + def send_message(self, params): """ Send an SMS message. @@ -15,13 +16,13 @@ def send_message(self, params): :param dict params: A dict of values described at `Send an SMS `_ """ return self._client.post( - self._client.host(), - "/sms/json", - params, + self._client.host(), + "/sms/json", + params, supports_signature_auth=True, **Sms.defaults, ) - + def submit_sms_conversion(self, message_id, delivered=True, timestamp=None): """ Notify Vonage that an SMS was successfully received. @@ -37,8 +38,10 @@ def submit_sms_conversion(self, message_id, delivered=True, timestamp=None): params = { "message-id": message_id, "delivered": delivered, - "timestamp": timestamp or datetime.now(pytz.utc) + "timestamp": timestamp or datetime.now(pytz.utc), } # Ensure timestamp is a string: _format_date_param(params, "timestamp") - return self._client.post(self._client.api_host(), "/conversions/sms", params, **Sms.defaults) + return self._client.post( + self._client.api_host(), "/conversions/sms", params, **Sms.defaults + ) diff --git a/src/vonage/ussd.py b/src/vonage/ussd.py index addde45e..98ade213 100644 --- a/src/vonage/ussd.py +++ b/src/vonage/ussd.py @@ -1,11 +1,15 @@ class Ussd: defaults = {'auth_type': 'params', 'body_is_json': False} - + def __init__(self, client): self._client = client def send_ussd_push_message(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/ussd/json", params or kwargs, **Ussd.defaults) + return self._client.post( + self._client.host(), "/ussd/json", params or kwargs, **Ussd.defaults + ) def send_ussd_prompt_message(self, params=None, **kwargs): - return self._client.post(self._client.host(), "/ussd-prompt/json", params or kwargs, **Ussd.defaults) + return self._client.post( + self._client.host(), "/ussd-prompt/json", params or kwargs, **Ussd.defaults + ) diff --git a/src/vonage/verify.py b/src/vonage/verify.py index 76d5d05e..1c7168b7 100644 --- a/src/vonage/verify.py +++ b/src/vonage/verify.py @@ -23,7 +23,10 @@ def check(self, request_id, params=None, **kwargs): def search(self, request_id): return self._client.get( - self._client.api_host(), "/verify/search/json", {"request_id": request_id}, auth_type=Verify.auth_type + self._client.api_host(), + "/verify/search/json", + {"request_id": request_id}, + auth_type=Verify.auth_type, ) def cancel(self, request_id): diff --git a/src/vonage/voice.py b/src/vonage/voice.py index e138f3b3..74a9f2b5 100644 --- a/src/vonage/voice.py +++ b/src/vonage/voice.py @@ -1,5 +1,6 @@ from urllib.parse import urlparse + class Voice: auth_type = 'jwt' @@ -9,13 +10,13 @@ def __init__(self, client): # Creates a new call session def create_call(self, params, **kwargs): """ - Adding Random From Number Feature for the Voice API, - if set to `True`, the from number will be randomly selected - from the pool of numbers available to the application making - the call. + Adding Random From Number Feature for the Voice API, + if set to `True`, the from number will be randomly selected + from the pool of numbers available to the application making + the call. + + :param params is a dictionary that holds the 'from' and 'random_from_number' - :param params is a dictionary that holds the 'from' and 'random_from_number' - """ if not params: params = kwargs @@ -24,74 +25,68 @@ def create_call(self, params, **kwargs): if key not in params: params['random_from_number'] = True + return self._client.post( + self._client.api_host(), "/v1/calls", params or kwargs, auth_type=Voice.auth_type + ) - return self._client.post(self._client.api_host(), "/v1/calls", params or kwargs, auth_type=Voice.auth_type) - # Get call history paginated. Pass start and end dates to filter the retrieved information def get_calls(self, params=None, **kwargs): return self._client.get( - self._client.api_host(), - "/v1/calls", - params or kwargs, - auth_type=Voice.auth_type + self._client.api_host(), "/v1/calls", params or kwargs, auth_type=Voice.auth_type ) - + # Get a single call record by identifier def get_call(self, uuid): return self._client.get( - self._client.api_host(), - f"/v1/calls/{uuid}", - auth_type=Voice.auth_type + self._client.api_host(), f"/v1/calls/{uuid}", auth_type=Voice.auth_type ) - + # Update call data using custom ncco def update_call(self, uuid, params=None, **kwargs): return self._client.put( self._client.api_host(), - f"/v1/calls/{uuid}", - params or kwargs, - auth_type=Voice.auth_type + f"/v1/calls/{uuid}", + params or kwargs, + auth_type=Voice.auth_type, ) - + # Plays audio streaming into call in progress - stream_url parameter is required def send_audio(self, uuid, params=None, **kwargs): return self._client.put( self._client.api_host(), - f"/v1/calls/{uuid}/stream", + f"/v1/calls/{uuid}/stream", params or kwargs, - auth_type=Voice.auth_type + auth_type=Voice.auth_type, ) - + # Play an speech into specified call - text parameter (text to speech) is required def send_speech(self, uuid, params=None, **kwargs): return self._client.put( self._client.api_host(), - f"/v1/calls/{uuid}/talk", + f"/v1/calls/{uuid}/talk", params or kwargs, - auth_type=Voice.auth_type + auth_type=Voice.auth_type, ) - + # plays DTMF tones into the specified call def send_dtmf(self, uuid, params=None, **kwargs): return self._client.put( self._client.api_host(), - f"/v1/calls/{uuid}/dtmf", + f"/v1/calls/{uuid}/dtmf", params or kwargs, - auth_type=Voice.auth_type + auth_type=Voice.auth_type, ) - + # Stops audio recently played into specified call def stop_audio(self, uuid): - return self._client.delete(self._client.api_host(), - f"/v1/calls/{uuid}/stream", - auth_type=Voice.auth_type + return self._client.delete( + self._client.api_host(), f"/v1/calls/{uuid}/stream", auth_type=Voice.auth_type ) - + # Stop a speech recently played into specified call def stop_speech(self, uuid): - return self._client.delete(self._client.api_host(), - f"/v1/calls/{uuid}/talk", - auth_type=Voice.auth_type + return self._client.delete( + self._client.api_host(), f"/v1/calls/{uuid}/talk", auth_type=Voice.auth_type ) def get_recording(self, url): diff --git a/tests/test_account.py b/tests/test_account.py index 191d9357..142bbbcf 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -70,9 +70,7 @@ def test_get_sms_pricing(account, dummy_data): @responses.activate def test_get_voice_pricing(account, dummy_data): - stub( - responses.GET, "https://rest.nexmo.com/account/get-phone-pricing/outbound/voice" - ) + stub(responses.GET, "https://rest.nexmo.com/account/get-phone-pricing/outbound/voice") assert isinstance(account.get_voice_pricing("447525856424"), dict) assert request_user_agent() == dummy_data.user_agent @@ -132,7 +130,8 @@ def test_list_secrets_missing(account): account.list_secrets("myaccountid") assert_basic_auth() assert ( - str(ce.value) == """Invalid API Key: API key 'ABC123' does not exist, or you do not have access (https://developer.nexmo.com/api-errors#invalid-api-key)""" + str(ce.value) + == """Invalid API Key: API key 'ABC123' does not exist, or you do not have access (https://developer.nexmo.com/api-errors#invalid-api-key)""" ) @@ -175,7 +174,8 @@ def test_create_secret_max_secrets(account): account.create_secret("meaccountid", "mahsecret") assert_basic_auth() assert ( - str(ce.value) == """Maxmimum number of secrets already met: This account has reached maximum number of '2' allowed secrets (https://developer.nexmo.com/api-errors/account/secret-management#maximum-secrets-allowed)""" + str(ce.value) + == """Maxmimum number of secrets already met: This account has reached maximum number of '2' allowed secrets (https://developer.nexmo.com/api-errors/account/secret-management#maximum-secrets-allowed)""" ) @@ -192,15 +192,14 @@ def test_create_secret_validation(account): account.create_secret("meaccountid", "mahsecret") assert_basic_auth() assert ( - str(ce.value) == """Bad Request: The request failed due to validation errors (https://developer.nexmo.com/api-errors/account/secret-management#validation)""" + str(ce.value) + == """Bad Request: The request failed due to validation errors (https://developer.nexmo.com/api-errors/account/secret-management#validation)""" ) @responses.activate def test_delete_secret(account): - stub( - responses.DELETE, "https://api.nexmo.com/accounts/meaccountid/secrets/mahsecret" - ) + stub(responses.DELETE, "https://api.nexmo.com/accounts/meaccountid/secrets/mahsecret") account.revoke_secret("meaccountid", "mahsecret") assert_basic_auth() @@ -218,5 +217,6 @@ def test_delete_secret_last_secret(account): account.revoke_secret("meaccountid", "mahsecret") assert_basic_auth() assert ( - str(ce.value) == """Secret Deletion Forbidden: Can not delete the last secret. The account must always have at least 1 secret active at any time (https://developer.nexmo.com/api-errors/account/secret-management#delete-last-secret)""" + str(ce.value) + == """Secret Deletion Forbidden: Can not delete the last secret. The account must always have at least 1 secret active at any time (https://developer.nexmo.com/api-errors/account/secret-management#delete-last-secret)""" ) diff --git a/tests/test_application.py b/tests/test_application.py index 7fe168be..101f0513 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -3,6 +3,7 @@ import vonage + @responses.activate def test_deprecated_list_applications(application_v2, dummy_data): stub( @@ -112,9 +113,7 @@ def test_deprecated_client_error(application_v2): ) with pytest.raises(vonage.ClientError) as exc_info: application_v2.delete_application("xx-xx-xx-xx") - assert ( - str(exc_info.value) == "Nope: You really shouldn't have done that (nope_error)" - ) + assert str(exc_info.value) == "Nope: You really shouldn't have done that (nope_error)" @responses.activate @@ -141,7 +140,6 @@ def test_deprecated_server_error(application_v2): application_v2.delete_application("xx-xx-xx-xx") - @responses.activate def test_list_applications(client, dummy_data): stub( @@ -251,9 +249,7 @@ def test_client_error(client): ) with pytest.raises(vonage.ClientError) as exc_info: client.application.delete_application("xx-xx-xx-xx") - assert ( - str(exc_info.value) == "Nope: You really shouldn't have done that (nope_error)" - ) + assert str(exc_info.value) == "Nope: You really shouldn't have done that (nope_error)" @responses.activate diff --git a/tests/test_client.py b/tests/test_client.py index bdedbf62..cb73ea44 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -23,6 +23,7 @@ def test_invalid_auth_type_raises_error(client): with pytest.raises(InvalidAuthenticationTypeError): client.get(client.host(), 'my/request/uri', auth_type='magic') + @responses.activate def test_timeout_is_set_on_client_calls(dummy_data): stub(responses.POST, "https://api.nexmo.com/v1/calls") diff --git a/tests/test_getters_setters.py b/tests/test_getters_setters.py index f1edfe3e..d11caa3b 100644 --- a/tests/test_getters_setters.py +++ b/tests/test_getters_setters.py @@ -2,6 +2,7 @@ def test_getters(client, dummy_data): assert client.host() == dummy_data.host assert client.api_host() == dummy_data.api_host + def test_setters(client, dummy_data): try: client.host('host.vonage.com') diff --git a/tests/test_jwt.py b/tests/test_jwt.py index d1c34451..fc51336d 100644 --- a/tests/test_jwt.py +++ b/tests/test_jwt.py @@ -45,7 +45,10 @@ def test_create_jwt_auth_string(client): def test_create_jwt_error_no_application_id_or_private_key(): empty_client = Client() - + with raises(ClientError) as err: empty_client._generate_application_jwt() - assert str(err.value) == 'JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".' + assert ( + str(err.value) + == 'JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".' + ) diff --git a/tests/test_messages_send_message.py b/tests/test_messages_send_message.py index a993eaa2..242ccbc7 100644 --- a/tests/test_messages_send_message.py +++ b/tests/test_messages_send_message.py @@ -36,4 +36,7 @@ def test_send_whatsapp_image_with_messages_api(messages, dummy_data): assert request_user_agent() == dummy_data.user_agent assert b'"from": "440123456789"' in request_body() assert b'"to": "447123456789"' in request_body() - assert b'"image": {"url": "https://example.com/image.jpg", "caption": "fake test image"}' in request_body() + assert ( + b'"image": {"url": "https://example.com/image.jpg", "caption": "fake test image"}' + in request_body() + ) diff --git a/tests/test_messages_validate_input.py b/tests/test_messages_validate_input.py index 9b346fd0..6ee2810d 100644 --- a/tests/test_messages_validate_input.py +++ b/tests/test_messages_validate_input.py @@ -5,7 +5,9 @@ def test_invalid_send_message_params_object(messages): with pytest.raises(MessagesError) as err: messages.send_message('hi') - assert str(err.value) == 'Parameters to the send_message method must be specified as a dictionary.' + assert ( + str(err.value) == 'Parameters to the send_message method must be specified as a dictionary.' + ) def test_invalid_message_channel(messages): @@ -25,7 +27,13 @@ def test_invalid_message_channel(messages): def test_invalid_message_type(messages): with pytest.raises(MessagesError) as err: messages.send_message( - {'channel': 'sms', 'message_type': 'video', 'to': '12345678', 'from': 'vonage', 'video': 'my_url.com'} + { + 'channel': 'sms', + 'message_type': 'video', + 'to': '12345678', + 'from': 'vonage', + 'video': 'my_url.com', + } ) assert '"video" is not a valid message type for channel "sms".' in str(err.value) @@ -33,7 +41,13 @@ def test_invalid_message_type(messages): def test_invalid_recipient_not_string(messages): with pytest.raises(MessagesError) as err: messages.send_message( - {'channel': 'sms', 'message_type': 'text', 'to': 12345678, 'from': 'vonage', 'text': 'my important message'} + { + 'channel': 'sms', + 'message_type': 'text', + 'to': 12345678, + 'from': 'vonage', + 'text': 'my important message', + } ) assert str(err.value) == 'Message recipient ("to=12345678") not in a valid format.' @@ -55,7 +69,13 @@ def test_invalid_recipient_number(messages): def test_invalid_messenger_recipient(messages): with pytest.raises(MessagesError) as err: messages.send_message( - {'channel': 'messenger', 'message_type': 'text', 'to': '', 'from': 'vonage', 'text': 'my important message'} + { + 'channel': 'messenger', + 'message_type': 'text', + 'to': '', + 'from': 'vonage', + 'text': 'my important message', + } ) assert str(err.value) == 'Message recipient ID ("to=") not in a valid format.' @@ -71,7 +91,10 @@ def test_invalid_sender(messages): 'text': 'my important message', } ) - assert str(err.value) == 'Message sender ("frm=1234") set incorrectly. Set a valid name or number for the sender.' + assert ( + str(err.value) + == 'Message sender ("frm=1234") set incorrectly. Set a valid name or number for the sender.' + ) def test_set_client_ref(messages): @@ -154,7 +177,12 @@ def test_viber_service_video(messages): 'caption': 'Look at this video', 'thumb_url': 'https://example.com/thumbnail.jpg', }, - 'viber_service': {'category': 'transaction', 'duration': '120', 'ttl': 30, 'type': 'string'}, + 'viber_service': { + 'category': 'transaction', + 'duration': '120', + 'ttl': 30, + 'type': 'string', + }, } ) @@ -197,7 +225,10 @@ def test_viber_service_image_action_button(messages): 'message_type': 'image', 'to': '44123456789', 'from': 'vonage', - 'image': {'url': 'https://example.com/image.jpg', 'caption': 'Check out this new promotion'}, + 'image': { + 'url': 'https://example.com/image.jpg', + 'caption': 'Check out this new promotion', + }, 'viber_service': { 'category': 'transaction', 'ttl': 30, @@ -219,7 +250,10 @@ def test_incomplete_input(messages): 'text': 'my important message', } ) - assert str(err.value) == 'You must specify all required properties for message channel "viber_service".' + assert ( + str(err.value) + == 'You must specify all required properties for message channel "viber_service".' + ) def test_whatsapp_sticker_id(messages): @@ -257,7 +291,9 @@ def test_whatsapp_sticker_invalid_input_error(messages): 'from': 'vonage', } ) - assert str(err.value) == 'Must specify one, and only one, of "id" or "url" in the "sticker" field.' + assert ( + str(err.value) == 'Must specify one, and only one, of "id" or "url" in the "sticker" field.' + ) def test_whatsapp_sticker_exclusive_keys_error(messages): @@ -266,9 +302,14 @@ def test_whatsapp_sticker_exclusive_keys_error(messages): { 'channel': 'whatsapp', 'message_type': 'sticker', - 'sticker': {'id': '13aaecab-2485-4255-a0a7-97a2be6906b9', 'url': 'https://example.com/sticker1.webp'}, + 'sticker': { + 'id': '13aaecab-2485-4255-a0a7-97a2be6906b9', + 'url': 'https://example.com/sticker1.webp', + }, 'to': '44123456789', 'from': 'vonage', } ) - assert str(err.value) == 'Must specify one, and only one, of "id" or "url" in the "sticker" field.' + assert ( + str(err.value) == 'Must specify one, and only one, of "id" or "url" in the "sticker" field.' + ) diff --git a/tests/test_ncco_builder/ncco_samples/ncco_action_samples.py b/tests/test_ncco_builder/ncco_samples/ncco_action_samples.py index ddf73411..85a11568 100644 --- a/tests/test_ncco_builder/ncco_samples/ncco_action_samples.py +++ b/tests/test_ncco_builder/ncco_samples/ncco_action_samples.py @@ -38,12 +38,12 @@ input_dtmf_and_speech_full = '{"action": "input", "type": ["dtmf", "speech"], "dtmf": {"timeOut": 5, "maxDigits": 12, "submitOnHash": true}, "speech": {"uuid": "my-uuid", "endOnSilence": 2.5, "language": "en-GB", "context": ["sales", "billing"], "startTimeout": 20, "maxDuration": 30, "saveAudio": true}, "eventUrl": ["http://example.com/speech"], "eventMethod": "PUT"}' -notify_basic = '{"action": "notify", "payload": {"message": "hello"}, "eventUrl": ["http://example.com"]}' - -notify_full = ( - '{"action": "notify", "payload": {"message": "hello"}, "eventUrl": ["http://example.com"], "eventMethod": "POST"}' +notify_basic = ( + '{"action": "notify", "payload": {"message": "hello"}, "eventUrl": ["http://example.com"]}' ) +notify_full = '{"action": "notify", "payload": {"message": "hello"}, "eventUrl": ["http://example.com"], "eventMethod": "POST"}' + pay_basic = '{"action": "pay", "amount": 10.0}' pay_voice_full = '{"action": "pay", "amount": 99.99, "currency": "gbp", "eventUrl": ["https://example.com/payment"], "voice": {"language": "en-GB", "style": 1}}' diff --git a/tests/test_ncco_builder/ncco_samples/ncco_builder_samples.py b/tests/test_ncco_builder/ncco_samples/ncco_builder_samples.py index 07559aef..85177fc4 100644 --- a/tests/test_ncco_builder/ncco_samples/ncco_builder_samples.py +++ b/tests/test_ncco_builder/ncco_samples/ncco_builder_samples.py @@ -25,9 +25,13 @@ talk_minimal = Ncco.Talk(text='hello') -talk = Ncco.Talk(text='hello', bargeIn=True, loop=3, level=0.5, language='en-GB', style=1, premium=True) +talk = Ncco.Talk( + text='hello', bargeIn=True, loop=3, level=0.5, language='en-GB', style=1, premium=True +) -stream = Ncco.Stream(streamUrl='https://example.com/stream/music.mp3', level=0.1, bargeIn=True, loop=10) +stream = Ncco.Stream( + streamUrl='https://example.com/stream/music.mp3', level=0.1, bargeIn=True, loop=10 +) input = Ncco.Input( type=['dtmf', 'speech'], @@ -45,7 +49,9 @@ eventMethod='put', ) -notify = Ncco.Notify(payload={"message": "world"}, eventUrl=["http://example.com"], eventMethod='PUT') +notify = Ncco.Notify( + payload={"message": "world"}, eventUrl=["http://example.com"], eventMethod='PUT' +) pay_voice_prompt = Ncco.Pay( amount=99.99, @@ -61,7 +67,11 @@ prompts=PayPrompts.TextPrompt( type='CardNumber', text='Enter your card number.', - errors={'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + errors={ + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, ), ) @@ -134,7 +144,12 @@ }, 'type': ['dtmf', 'speech'], }, - {'action': 'notify', 'eventMethod': 'PUT', 'eventUrl': ['http://example.com'], 'payload': {'message': 'world'}}, + { + 'action': 'notify', + 'eventMethod': 'PUT', + 'eventUrl': ['http://example.com'], + 'payload': {'message': 'world'}, + }, { 'action': 'pay', 'amount': 99.99, @@ -149,7 +164,9 @@ 'eventUrl': ['https://example.com/payment'], 'prompts': { 'errors': { - 'InvalidCardType': {'text': 'The card you are trying ' 'to use is not valid for ' 'this purchase.'} + 'InvalidCardType': { + 'text': 'The card you are trying ' 'to use is not valid for ' 'this purchase.' + } }, 'text': 'Enter your card number.', 'type': 'CardNumber', diff --git a/tests/test_ncco_builder/test_connect_endpoints.py b/tests/test_ncco_builder/test_connect_endpoints.py index c263d92c..44cc608a 100644 --- a/tests/test_ncco_builder/test_connect_endpoints.py +++ b/tests/test_ncco_builder/test_connect_endpoints.py @@ -14,7 +14,10 @@ def test_connect_all_endpoints_from_model(): phone = ConnectEndpoints.PhoneEndpoint( number='447000000000', dtmfAnswer='1p2p3p#**903#', - onAnswer={"url": "https://example.com/answer", "ringbackTone": "http://example.com/ringbackTone.wav"}, + onAnswer={ + "url": "https://example.com/answer", + "ringbackTone": "http://example.com/ringbackTone.wav", + }, ) connect_phone = Ncco.Connect(endpoint=phone) assert json.dumps(_action_as_dict(connect_phone)) == nas.connect_phone @@ -24,13 +27,16 @@ def test_connect_all_endpoints_from_model(): assert json.dumps(_action_as_dict(connect_app)) == nas.connect_app websocket = ConnectEndpoints.WebsocketEndpoint( - uri='ws://example.com/socket', contentType='audio/l16;rate=8000', headers={"language": "en-GB"} + uri='ws://example.com/socket', + contentType='audio/l16;rate=8000', + headers={"language": "en-GB"}, ) connect_websocket = Ncco.Connect(endpoint=websocket) assert json.dumps(_action_as_dict(connect_websocket)) == nas.connect_websocket sip = ConnectEndpoints.SipEndpoint( - uri='sip:rebekka@sip.mcrussell.com', headers={"location": "New York City", "occupation": "developer"} + uri='sip:rebekka@sip.mcrussell.com', + headers={"location": "New York City", "occupation": "developer"}, ) connect_sip = Ncco.Connect(endpoint=sip) assert json.dumps(_action_as_dict(connect_sip)) == nas.connect_sip diff --git a/tests/test_ncco_builder/test_input_types.py b/tests/test_ncco_builder/test_input_types.py index f32d4016..7572ae1a 100644 --- a/tests/test_ncco_builder/test_input_types.py +++ b/tests/test_ncco_builder/test_input_types.py @@ -40,4 +40,8 @@ def test_create_speech_model_from_dict(): speech_dict = {'uuid': 'my-uuid', 'endOnSilence': 2.5, 'maxDuration': 30} speech_model = InputTypes.create_speech_model(speech_dict) assert type(speech_model) == InputTypes.Speech - assert speech_model.dict(exclude_none=True) == {'uuid': 'my-uuid', 'endOnSilence': 2.5, 'maxDuration': 30} + assert speech_model.dict(exclude_none=True) == { + 'uuid': 'my-uuid', + 'endOnSilence': 2.5, + 'maxDuration': 30, + } diff --git a/tests/test_ncco_builder/test_ncco_actions.py b/tests/test_ncco_builder/test_ncco_actions.py index c0379e85..b7bd028a 100644 --- a/tests/test_ncco_builder/test_ncco_actions.py +++ b/tests/test_ncco_builder/test_ncco_actions.py @@ -84,7 +84,10 @@ def test_connect_phone_endpoint_from_dict(): "type": "phone", "number": "447000000000", "dtmfAnswer": "1p2p3p#**903#", - "onAnswer": {"url": "https://example.com/answer", "ringbackTone": "http://example.com/ringbackTone.wav"}, + "onAnswer": { + "url": "https://example.com/answer", + "ringbackTone": "http://example.com/ringbackTone.wav", + }, } ) assert type(connect) is Ncco.Connect @@ -142,7 +145,10 @@ def test_connect_random_from_number_error(): with pytest.raises(ValueError) as err: Ncco.Connect(endpoint=endpoint, from_='447400000000', randomFromNumber=True) - assert 'Cannot set a "from" ("from_") field and also the "randomFromNumber" = True option' in str(err.value) + assert ( + 'Cannot set a "from" ("from_") field and also the "randomFromNumber" = True option' + in str(err.value) + ) def test_connect_validation_errors(): @@ -168,7 +174,9 @@ def test_talk_basic(): def test_talk_optional_params(): - talk = Ncco.Talk(text='hello', bargeIn=True, loop=3, level=0.5, language='en-GB', style=1, premium=True) + talk = Ncco.Talk( + text='hello', bargeIn=True, loop=3, level=0.5, language='en-GB', style=1, premium=True + ) assert json.dumps(_action_as_dict(talk)) == nas.talk_full @@ -184,7 +192,9 @@ def test_stream_basic(): def test_stream_full(): - stream = Ncco.Stream(streamUrl='https://example.com/stream/music.mp3', level=0.1, bargeIn=True, loop=10) + stream = Ncco.Stream( + streamUrl='https://example.com/stream/music.mp3', level=0.1, bargeIn=True, loop=10 + ) assert json.dumps(_action_as_dict(stream)) == nas.stream_full @@ -211,7 +221,11 @@ def test_input_dtmf_and_speech_options(): saveAudio=True, ) input = Ncco.Input( - type=['dtmf', 'speech'], dtmf=dtmf, speech=speech, eventUrl='http://example.com/speech', eventMethod='put' + type=['dtmf', 'speech'], + dtmf=dtmf, + speech=speech, + eventUrl='http://example.com/speech', + eventMethod='put', ) assert json.dumps(_action_as_dict(input)) == nas.input_dtmf_and_speech_full @@ -234,7 +248,9 @@ def test_notify_basic_str_in_event_url(): def test_notify_full(): - notify = Ncco.Notify(payload={'message': 'hello'}, eventUrl=['http://example.com'], eventMethod='POST') + notify = Ncco.Notify( + payload={'message': 'hello'}, eventUrl=['http://example.com'], eventMethod='POST' + ) assert type(notify) == Ncco.Notify assert json.dumps(_action_as_dict(notify)) == nas.notify_full @@ -252,7 +268,9 @@ def test_pay_voice_basic(): def test_pay_voice_full(): voice_settings = PayPrompts.VoicePrompt(language='en-GB', style=1) - pay = Ncco.Pay(amount=99.99, currency='gbp', eventUrl='https://example.com/payment', voice=voice_settings) + pay = Ncco.Pay( + amount=99.99, currency='gbp', eventUrl='https://example.com/payment', voice=voice_settings + ) assert json.dumps(_action_as_dict(pay)) == nas.pay_voice_full @@ -260,9 +278,15 @@ def test_pay_text(): text_prompts = PayPrompts.TextPrompt( type='CardNumber', text='Enter your card number.', - errors={'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + errors={ + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, + ) + pay = Ncco.Pay( + amount=12.345, currency='gbp', eventUrl='https://example.com/payment', prompts=text_prompts ) - pay = Ncco.Pay(amount=12.345, currency='gbp', eventUrl='https://example.com/payment', prompts=text_prompts) assert json.dumps(_action_as_dict(pay)) == nas.pay_text @@ -270,7 +294,11 @@ def test_pay_text_multiple_prompts(): card_prompt = PayPrompts.TextPrompt( type='CardNumber', text='Enter your card number.', - errors={'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + errors={ + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, ) expiration_date_prompt = PayPrompts.TextPrompt( type='ExpirationDate', diff --git a/tests/test_ncco_builder/test_pay_prompts.py b/tests/test_ncco_builder/test_pay_prompts.py index c5628bd7..abb949ce 100644 --- a/tests/test_ncco_builder/test_pay_prompts.py +++ b/tests/test_ncco_builder/test_pay_prompts.py @@ -19,7 +19,11 @@ def test_create_text_model(): text_prompt = PayPrompts.TextPrompt( type='CardNumber', text='Enter your card number.', - errors={'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + errors={ + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, ) assert type(text_prompt) == PayPrompts.TextPrompt @@ -28,7 +32,11 @@ def test_create_text_model_from_dict(): text_dict = { 'type': 'CardNumber', 'text': 'Enter your card number.', - 'errors': {'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + 'errors': { + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, } text_prompt = PayPrompts.create_text_model(text_dict) assert type(text_prompt) == PayPrompts.TextPrompt @@ -39,7 +47,9 @@ def test_error_message_not_in_subdictionary(): PayPrompts.TextPrompt( type='CardNumber', text='Enter your card number.', - errors={'InvalidCardType': 'The card you are trying to use is not valid for this purchase.'}, + errors={ + 'InvalidCardType': 'The card you are trying to use is not valid for this purchase.' + }, ) @@ -48,7 +58,14 @@ def test_invalid_error_type_for_prompt(): PayPrompts.TextPrompt( type='SecurityCode', text='Enter your card number.', - errors={'InvalidCardType': {'text': 'The card you are trying to use is not valid for this purchase.'}}, + errors={ + 'InvalidCardType': { + 'text': 'The card you are trying to use is not valid for this purchase.' + } + }, ) - assert 'Value "InvalidCardType" is not a valid error for the "SecurityCode" prompt type.' in str(err.value) + assert ( + 'Value "InvalidCardType" is not a valid error for the "SecurityCode" prompt type.' + in str(err.value) + ) diff --git a/tests/test_number_insight.py b/tests/test_number_insight.py index 75cedc88..40ab9d19 100644 --- a/tests/test_number_insight.py +++ b/tests/test_number_insight.py @@ -40,6 +40,7 @@ def test_get_async_advanced_number_insight(number_insight, dummy_data): assert "number=447525856424" in request_query() assert "callback=https%3A%2F%2Fexample.com" in request_query() + def test_callback_required_error_async_advanced_number_insight(number_insight, dummy_data): stub(responses.GET, "https://api.nexmo.com/ni/advanced/async/json") diff --git a/tests/test_packages.py b/tests/test_packages.py index d9cbceb6..49d5dbcf 100644 --- a/tests/test_packages.py +++ b/tests/test_packages.py @@ -3,7 +3,9 @@ def test_subdirectories_are_python_packages(): subdirs = [ - os.path.join('src/vonage', o) for o in os.listdir('src/vonage') if os.path.isdir(os.path.join('src/vonage', o)) + os.path.join('src/vonage', o) + for o in os.listdir('src/vonage') + if os.path.isdir(os.path.join('src/vonage', o)) ] for subdir in subdirs: if '__pycache__' in subdir or os.path.isfile(f'{subdir}/__init__.py'): diff --git a/tests/test_redact.py b/tests/test_redact.py index 834f89f6..609e5d9e 100644 --- a/tests/test_redact.py +++ b/tests/test_redact.py @@ -6,6 +6,7 @@ def test_redact_invalid_product_name(redact): with pytest.raises(RedactError): redact.redact_transaction(id='not-a-real-id', product='fake-product') + @responses.activate def test_redact_transaction(redact, dummy_data): responses.add( diff --git a/tests/test_short_codes.py b/tests/test_short_codes.py index 1a6b04ea..212dfcf6 100644 --- a/tests/test_short_codes.py +++ b/tests/test_short_codes.py @@ -61,4 +61,4 @@ def test_resubscribe_event_alert_number(short_codes, dummy_data): assert isinstance(short_codes.resubscribe_event_alert_number(params), dict) assert request_user_agent() == dummy_data.user_agent - assert "msisdn=441632960960" in request_body() \ No newline at end of file + assert "msisdn=441632960960" in request_body() diff --git a/tests/test_sms.py b/tests/test_sms.py index b02a651a..cdb8cb36 100644 --- a/tests/test_sms.py +++ b/tests/test_sms.py @@ -43,9 +43,7 @@ def test_server_error(sms): @responses.activate def test_submit_sms_conversion(sms): - responses.add( - responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK" - ) + responses.add(responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK") sms.submit_sms_conversion("a-message-id") assert "message-id=a-message-id" in request_body() diff --git a/tests/test_ussd.py b/tests/test_ussd.py index 9eb4db00..27fb41a7 100644 --- a/tests/test_ussd.py +++ b/tests/test_ussd.py @@ -1,5 +1,6 @@ from util import * + @responses.activate def test_send_ussd_push_message(ussd, dummy_data): stub(responses.POST, "https://rest.nexmo.com/ussd/json") @@ -12,6 +13,7 @@ def test_send_ussd_push_message(ussd, dummy_data): assert "to=447525856424" in request_body() assert "text=Hello" in request_body() + @responses.activate def test_send_ussd_prompt_message(ussd, dummy_data): stub(responses.POST, "https://rest.nexmo.com/ussd-prompt/json") @@ -22,4 +24,4 @@ def test_send_ussd_prompt_message(ussd, dummy_data): assert request_user_agent() == dummy_data.user_agent assert "from=long-virtual-number" in request_body() assert "to=447525856424" in request_body() - assert "text=Hello" in request_body() \ No newline at end of file + assert "text=Hello" in request_body() diff --git a/tests/test_verify.py b/tests/test_verify.py index adb7ec27..576dbf62 100644 --- a/tests/test_verify.py +++ b/tests/test_verify.py @@ -1,5 +1,6 @@ from util import * + @responses.activate def test_start_verification(verify, dummy_data): stub(responses.POST, "https://api.nexmo.com/verify/json") @@ -65,8 +66,10 @@ def test_start_psd2_verification(verify, dummy_data): @responses.activate def test_start_verification_blacklisted_error_with_network(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/json", - fixture_path="verify/blocked_with_network.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/json", + fixture_path="verify/blocked_with_network.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -78,13 +81,18 @@ def test_start_verification_blacklisted_error_with_network(client, dummy_data): assert "brand=MyApp" in request_body() assert response["status"] == "7" assert response["network"] == "25503" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) @responses.activate def test_start_verification_blacklisted_error_with_request_id(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/json", - fixture_path="verify/blocked_with_request_id.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/json", + fixture_path="verify/blocked_with_request_id.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -96,13 +104,18 @@ def test_start_verification_blacklisted_error_with_request_id(client, dummy_data assert "brand=MyApp" in request_body() assert response["status"] == "7" assert response["request_id"] == "12345678" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) @responses.activate def test_start_verification_blacklisted_error_with_network_and_request_id(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/json", - fixture_path="verify/blocked_with_network_and_request_id.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/json", + fixture_path="verify/blocked_with_network_and_request_id.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -115,12 +128,18 @@ def test_start_verification_blacklisted_error_with_network_and_request_id(client assert response["status"] == "7" assert response["network"] == "25503" assert response["request_id"] == "12345678" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) + @responses.activate def test_start_psd2_verification_blacklisted_error_with_network(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/psd2/json", - fixture_path="verify/blocked_with_network.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/psd2/json", + fixture_path="verify/blocked_with_network.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -132,13 +151,18 @@ def test_start_psd2_verification_blacklisted_error_with_network(client, dummy_da assert "brand=MyApp" in request_body() assert response["status"] == "7" assert response["network"] == "25503" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) @responses.activate def test_start_psd2_verification_blacklisted_error_with_request_id(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/psd2/json", - fixture_path="verify/blocked_with_request_id.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/psd2/json", + fixture_path="verify/blocked_with_request_id.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -150,13 +174,18 @@ def test_start_psd2_verification_blacklisted_error_with_request_id(client, dummy assert "brand=MyApp" in request_body() assert response["status"] == "7" assert response["request_id"] == "12345678" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) @responses.activate def test_start_psd2_verification_blacklisted_error_with_network_and_request_id(client, dummy_data): - stub(responses.POST, "https://api.nexmo.com/verify/psd2/json", - fixture_path="verify/blocked_with_network_and_request_id.json" + stub( + responses.POST, + "https://api.nexmo.com/verify/psd2/json", + fixture_path="verify/blocked_with_network_and_request_id.json", ) params = {"number": "447525856424", "brand": "MyApp"} @@ -169,4 +198,7 @@ def test_start_psd2_verification_blacklisted_error_with_network_and_request_id(c assert response["status"] == "7" assert response["network"] == "25503" assert response["request_id"] == "12345678" - assert response["error_text"] == "The number you are trying to verify is blacklisted for verification" + assert ( + response["error_text"] + == "The number you are trying to verify is blacklisted for verification" + ) diff --git a/tests/test_voice.py b/tests/test_voice.py index 25aba2b5..a81cb847 100644 --- a/tests/test_voice.py +++ b/tests/test_voice.py @@ -43,7 +43,13 @@ def test_create_call_with_ncco_builder(voice, dummy_data): stub(responses.POST, "https://api.nexmo.com/v1/calls") talk = Ncco.Talk( - text='Hello from Vonage!', bargeIn=True, loop=3, level=0.5, language='en-GB', style=1, premium=True + text='Hello from Vonage!', + bargeIn=True, + loop=3, + level=0.5, + language='en-GB', + style=1, + premium=True, ) ncco = Ncco.build_ncco(talk) voice.create_call( @@ -147,7 +153,7 @@ def test_user_provided_authorization(dummy_data): nbf = int(time.time()) exp = nbf + 3600 - + client.auth(nbf=nbf, exp=exp) client.voice.get_call("xx-xx-xx-xx") @@ -175,7 +181,9 @@ def test_authorization_with_private_key_path(dummy_data): voice = vonage.Voice(client) voice.get_call("xx-xx-xx-xx") - token = jwt.decode(request_authorization().split()[1], dummy_data.public_key, algorithms="RS256") + token = jwt.decode( + request_authorization().split()[1], dummy_data.public_key, algorithms="RS256" + ) assert token["application_id"] == dummy_data.application_id @@ -185,14 +193,18 @@ def test_authorization_with_private_key_object(voice, dummy_data): voice.get_call("xx-xx-xx-xx") - token = jwt.decode(request_authorization().split()[1], dummy_data.public_key, algorithms="RS256") + token = jwt.decode( + request_authorization().split()[1], dummy_data.public_key, algorithms="RS256" + ) assert token["application_id"] == dummy_data.application_id @responses.activate def test_get_recording(voice, dummy_data): stub_bytes( - responses.GET, "https://api.nexmo.com/v1/files/d6e47a2e-3414-11e8-8c2c-2f8b643ed957", body=b'THISISANMP3' + responses.GET, + "https://api.nexmo.com/v1/files/d6e47a2e-3414-11e8-8c2c-2f8b643ed957", + body=b'THISISANMP3', ) assert isinstance(