diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c9efe107..2dbc23df 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,8 @@ jobs: BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }} BW_USERNAME: ${{ secrets.BW_USERNAME }} BW_PASSWORD: ${{ secrets.BW_PASSWORD }} + BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }} + BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }} BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }} BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }} BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }} diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 0c9ba8f6..ee6c5ab9 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -13,6 +13,8 @@ env: BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }} BW_USERNAME: ${{ secrets.BW_USERNAME }} BW_PASSWORD: ${{ secrets.BW_PASSWORD }} + BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }} + BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }} BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }} BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }} BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }} diff --git a/.github/workflows/test-smoke.yml b/.github/workflows/test-smoke.yml index 07a37573..53673f93 100644 --- a/.github/workflows/test-smoke.yml +++ b/.github/workflows/test-smoke.yml @@ -27,6 +27,8 @@ env: OPERATING_SYSTEM: ubuntu BW_USERNAME: ${{ secrets.BW_USERNAME }} BW_PASSWORD: ${{ secrets.BW_PASSWORD }} + BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }} + BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }} BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }} BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }} USER_NUMBER: ${{ secrets.USER_NUMBER }} diff --git a/README.md b/README.md index 13a914a2..8ee7e5c5 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: @@ -337,6 +343,14 @@ Authentication schemes defined for the API: - **Type**: HTTP basic authentication + +### OAuth2 + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + ## Author diff --git a/bandwidth.yml b/bandwidth.yml index 6ee15ae1..866e5280 100644 --- a/bandwidth.yml +++ b/bandwidth.yml @@ -8,6 +8,7 @@ info: email: letstalk@bandwidth.com version: 1.0.0 security: + - OAuth2: [] - Basic: [] tags: - name: Messages @@ -8427,6 +8428,12 @@ components: - Example: `Authorization: Basic ZGVtbZpwQDU1dzByZA==` + OAuth2: + type: oauth2 + flows: + clientCredentials: + tokenUrl: https://api.bandwidth.com/api/v1/oauth2/token + scopes: {} callbacks: inboundCallback: '{inboundCallbackUrl}': diff --git a/bandwidth/api/calls_api.py b/bandwidth/api/calls_api.py index f9d754dd..1fe7b9e6 100644 --- a/bandwidth/api/calls_api.py +++ b/bandwidth/api/calls_api.py @@ -338,7 +338,8 @@ def _create_call_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -641,7 +642,8 @@ def _get_call_state_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1048,7 +1050,8 @@ def _list_calls_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1382,7 +1385,8 @@ def _update_call_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1716,7 +1720,8 @@ def _update_call_bxml_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/conferences_api.py b/bandwidth/api/conferences_api.py index a3817228..3fde1cbb 100644 --- a/bandwidth/api/conferences_api.py +++ b/bandwidth/api/conferences_api.py @@ -343,7 +343,8 @@ def _download_conference_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -646,7 +647,8 @@ def _get_conference_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -964,7 +966,8 @@ def _get_conference_member_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1282,7 +1285,8 @@ def _get_conference_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1585,7 +1589,8 @@ def _list_conference_recordings_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1958,7 +1963,8 @@ def _list_conferences_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2289,7 +2295,8 @@ def _update_conference_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2620,7 +2627,8 @@ def _update_conference_bxml_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2966,7 +2974,8 @@ def _update_conference_member_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/media_api.py b/bandwidth/api/media_api.py index 571a3c8a..525e51fa 100644 --- a/bandwidth/api/media_api.py +++ b/bandwidth/api/media_api.py @@ -322,7 +322,8 @@ def _delete_media_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -626,7 +627,8 @@ def _get_media_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -929,7 +931,8 @@ def _list_media_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1345,7 +1348,8 @@ def _upload_media_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/messages_api.py b/bandwidth/api/messages_api.py index 1b89537b..a19d5ae9 100644 --- a/bandwidth/api/messages_api.py +++ b/bandwidth/api/messages_api.py @@ -344,7 +344,8 @@ def _create_message_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1088,7 +1089,8 @@ def _list_messages_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/mfa_api.py b/bandwidth/api/mfa_api.py index 5b10228b..92698d4e 100644 --- a/bandwidth/api/mfa_api.py +++ b/bandwidth/api/mfa_api.py @@ -326,7 +326,8 @@ def _generate_messaging_code_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -630,7 +631,8 @@ def _generate_voice_code_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -937,7 +939,8 @@ def _verify_code_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/multi_channel_api.py b/bandwidth/api/multi_channel_api.py index 703d1a2e..7f929796 100644 --- a/bandwidth/api/multi_channel_api.py +++ b/bandwidth/api/multi_channel_api.py @@ -338,7 +338,8 @@ def _create_multi_channel_message_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/phone_number_lookup_api.py b/bandwidth/api/phone_number_lookup_api.py index 7a18ca86..07f3e6fd 100644 --- a/bandwidth/api/phone_number_lookup_api.py +++ b/bandwidth/api/phone_number_lookup_api.py @@ -315,7 +315,8 @@ def _create_async_bulk_lookup_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -607,7 +608,8 @@ def _create_sync_lookup_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -886,7 +888,8 @@ def _get_async_bulk_lookup_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/recordings_api.py b/bandwidth/api/recordings_api.py index dfdde315..3702ffdf 100644 --- a/bandwidth/api/recordings_api.py +++ b/bandwidth/api/recordings_api.py @@ -340,7 +340,8 @@ def _delete_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -658,7 +659,8 @@ def _delete_recording_media_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -976,7 +978,8 @@ def _delete_recording_transcription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1296,7 +1299,8 @@ def _download_call_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1614,7 +1618,8 @@ def _get_call_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1932,7 +1937,8 @@ def _get_recording_transcription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2288,7 +2294,8 @@ def _list_account_call_recordings_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2591,7 +2598,8 @@ def _list_call_recordings_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2937,7 +2945,8 @@ def _transcribe_call_recording_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -3268,7 +3277,8 @@ def _update_call_recording_state_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/statistics_api.py b/bandwidth/api/statistics_api.py index 4abbbc77..de65a491 100644 --- a/bandwidth/api/statistics_api.py +++ b/bandwidth/api/statistics_api.py @@ -306,7 +306,8 @@ def _get_statistics_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/toll_free_verification_api.py b/bandwidth/api/toll_free_verification_api.py index bdde9268..5c70fa94 100644 --- a/bandwidth/api/toll_free_verification_api.py +++ b/bandwidth/api/toll_free_verification_api.py @@ -340,7 +340,8 @@ def _create_webhook_subscription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -643,7 +644,8 @@ def _delete_verification_request_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -946,7 +948,8 @@ def _delete_webhook_subscription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1249,7 +1252,8 @@ def _get_toll_free_verification_status_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1522,7 +1526,8 @@ def _list_toll_free_use_cases_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -1807,7 +1812,8 @@ def _list_webhook_subscriptions_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2120,7 +2126,8 @@ def _request_toll_free_verification_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2448,7 +2455,8 @@ def _update_toll_free_verification_request_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -2779,7 +2787,8 @@ def _update_webhook_subscription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/api/transcriptions_api.py b/bandwidth/api/transcriptions_api.py index 74f41c32..f90440b3 100644 --- a/bandwidth/api/transcriptions_api.py +++ b/bandwidth/api/transcriptions_api.py @@ -338,7 +338,8 @@ def _delete_real_time_transcription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -656,7 +657,8 @@ def _get_real_time_transcription_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( @@ -959,7 +961,8 @@ def _list_real_time_transcriptions_serialize( # authentication setting _auth_settings: List[str] = [ - 'Basic' + 'Basic', + 'OAuth2' ] return self.api_client.param_serialize( diff --git a/bandwidth/configuration.py b/bandwidth/configuration.py index a7fd607d..ad32ea05 100644 --- a/bandwidth/configuration.py +++ b/bandwidth/configuration.py @@ -13,6 +13,8 @@ """ # noqa: E501 +import time +import base64 import copy import http.client as httplib import logging @@ -115,6 +117,7 @@ "AuthSettings", { "Basic": BasicAuthSetting, + "OAuth2": OAuth2AuthSetting, }, total=False, ) @@ -149,6 +152,8 @@ class Configuration: :param username: Username for HTTP basic authentication. :param password: Password for HTTP basic authentication. :param access_token: Access token. + :param client_id: Client ID for OAuth2 authentication. + :param client_secret: Client Secret for OAuth2 authentication. :param server_index: Index to servers configuration. :param server_variables: Mapping with string values to replace variables in templated server configuration. The validation of enums is performed for @@ -196,6 +201,8 @@ def __init__( username: Optional[str]=None, password: Optional[str]=None, access_token: Optional[str]=None, + client_id: Optional[str]=None, + client_secret: Optional[str]=None, server_index: Optional[int]=None, server_variables: Optional[ServerVariablesT]=None, server_operation_index: Optional[Dict[int, int]]=None, @@ -251,6 +258,18 @@ def __init__( self.access_token = access_token """Access token """ + self.client_id = client_id + """Client ID for OAuth2 authentication + """ + self.client_secret = client_secret + """Client Secret for OAuth2 authentication + """ + self.temp_access_token = None + """Temporary access token for OAuth2 + """ + self.temp_access_token_expiration = 0 + """Expiration time of the temporary access token + """ self.logger = {} """Logging Settings """ @@ -507,6 +526,32 @@ def get_basic_auth_token(self) -> Optional[str]: basic_auth=username + ':' + password ).get('authorization') + def get_access_token(self) -> str: + """Gets HTTP bearer authentication header (string). + + :return: The token for bearer HTTP authentication. + """ + now = int(time.time()) + if self.temp_access_token and self.temp_access_token_expiration > now + 60: + return self.temp_access_token + else: + _bytes = f"{self.client_id}:{self.client_secret}".encode('utf-8') + _encoded_string = base64.b64encode(_bytes).decode('utf-8') + auth_header = f"Basic {_encoded_string}" + resp = urllib3.request( + 'POST', + 'https://api.bandwidth.com/api/v1/oauth2/token', + headers={ + 'Authorization': auth_header, + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body='grant_type=client_credentials' + ) + body = resp.json() + self.temp_access_token = body['access_token'] + self.temp_access_token_expiration = now + body['expires_in'] + return self.temp_access_token + def auth_settings(self)-> AuthSettings: """Gets Auth Settings dict for api client. @@ -520,6 +565,20 @@ def auth_settings(self)-> AuthSettings: 'key': 'Authorization', 'value': self.get_basic_auth_token() } + if self.access_token is not None: + auth['OAuth2'] = { + 'type': 'oauth2', + 'in': 'header', + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token + } + if self.client_id is not None and self.client_secret is not None: + auth['OAuth2'] = { + 'type': 'oauth2', + 'in': 'header', + 'key': 'Authorization', + 'value': 'Bearer ' + self.get_access_token(), + } return auth def to_debug_report(self) -> str: diff --git a/custom_templates/configuration.mustache b/custom_templates/configuration.mustache new file mode 100644 index 00000000..137adb93 --- /dev/null +++ b/custom_templates/configuration.mustache @@ -0,0 +1,837 @@ +# coding: utf-8 + +{{>partial_header}} + + +import time +import base64 +import copy +import http.client as httplib +import logging +from logging import FileHandler +{{^async}} +import multiprocessing +{{/async}} +import sys +from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union +from typing_extensions import NotRequired, Self + +import urllib3 + +{{#hasHttpSignatureMethods}} +from {{packageName}}.signing import HttpSigningConfiguration +{{/hasHttpSignatureMethods}} + +JSON_SCHEMA_VALIDATION_KEYWORDS = { + 'multipleOf', 'maximum', 'exclusiveMaximum', + 'minimum', 'exclusiveMinimum', 'maxLength', + 'minLength', 'pattern', 'maxItems', 'minItems' +} + +ServerVariablesT = Dict[str, str] + +GenericAuthSetting = TypedDict( + "GenericAuthSetting", + { + "type": str, + "in": str, + "key": str, + "value": str, + }, +) + + +OAuth2AuthSetting = TypedDict( + "OAuth2AuthSetting", + { + "type": Literal["oauth2"], + "in": Literal["header"], + "key": Literal["Authorization"], + "value": str, + }, +) + + +APIKeyAuthSetting = TypedDict( + "APIKeyAuthSetting", + { + "type": Literal["api_key"], + "in": str, + "key": str, + "value": Optional[str], + }, +) + + +BasicAuthSetting = TypedDict( + "BasicAuthSetting", + { + "type": Literal["basic"], + "in": Literal["header"], + "key": Literal["Authorization"], + "value": Optional[str], + }, +) + + +BearerFormatAuthSetting = TypedDict( + "BearerFormatAuthSetting", + { + "type": Literal["bearer"], + "in": Literal["header"], + "format": Literal["JWT"], + "key": Literal["Authorization"], + "value": str, + }, +) + + +BearerAuthSetting = TypedDict( + "BearerAuthSetting", + { + "type": Literal["bearer"], + "in": Literal["header"], + "key": Literal["Authorization"], + "value": str, + }, +) + + +HTTPSignatureAuthSetting = TypedDict( + "HTTPSignatureAuthSetting", + { + "type": Literal["http-signature"], + "in": Literal["header"], + "key": Literal["Authorization"], + "value": None, + }, +) + + +AuthSettings = TypedDict( + "AuthSettings", + { +{{#authMethods}} +{{#isOAuth}} + "{{name}}": OAuth2AuthSetting, +{{/isOAuth}} +{{#isApiKey}} + "{{name}}": APIKeyAuthSetting, +{{/isApiKey}} +{{#isBasic}} + {{#isBasicBasic}} + "{{name}}": BasicAuthSetting, + {{/isBasicBasic}} + {{#isBasicBearer}} + {{#bearerFormat}} + "{{name}}": BearerFormatAuthSetting, + {{/bearerFormat}} + {{^bearerFormat}} + "{{name}}": BearerAuthSetting, + {{/bearerFormat}} + {{/isBasicBearer}} + {{#isHttpSignature}} + "{{name}}": HTTPSignatureAuthSetting, + {{/isHttpSignature}} +{{/isBasic}} +{{/authMethods}} + }, + total=False, +) + + +class HostSettingVariable(TypedDict): + description: str + default_value: str + enum_values: List[str] + + +class HostSetting(TypedDict): + url: str + description: str + variables: NotRequired[Dict[str, HostSettingVariable]] + + +class Configuration: + """This class contains various settings of the API client. + + :param host: Base url. + :param ignore_operation_servers + Boolean to ignore operation servers for the API client. + Config will use `host` as the base url regardless of the operation servers. + :param api_key: Dict to store API key(s). + Each entry in the dict specifies an API key. + The dict key is the name of the security scheme in the OAS specification. + The dict value is the API key secret. + :param api_key_prefix: Dict to store API prefix (e.g. Bearer). + The dict key is the name of the security scheme in the OAS specification. + The dict value is an API key prefix when generating the auth data. + :param username: Username for HTTP basic authentication. + :param password: Password for HTTP basic authentication. + :param access_token: Access token. + :param client_id: Client ID for OAuth2 authentication. + :param client_secret: Client Secret for OAuth2 authentication. +{{#hasHttpSignatureMethods}} + :param signing_info: Configuration parameters for the HTTP signature security scheme. + Must be an instance of {{{packageName}}}.signing.HttpSigningConfiguration +{{/hasHttpSignatureMethods}} + :param server_index: Index to servers configuration. + :param server_variables: Mapping with string values to replace variables in + templated server configuration. The validation of enums is performed for + variables with defined enum values before. + :param server_operation_index: Mapping from operation ID to an index to server + configuration. + :param server_operation_variables: Mapping from operation ID to a mapping with + string values to replace variables in templated server configuration. + The validation of enums is performed for variables with defined enum + values before. + :param ssl_ca_cert: str - the path to a file of concatenated CA certificates + in PEM format. + :param retries: Number of retries for API requests. + :param ca_cert_data: verify the peer using concatenated CA certificate data + in PEM (str) or DER (bytes) format. + :param cert_file: the path to a client certificate file, for mTLS. + :param key_file: the path to a client key file, for mTLS. + +{{#hasAuthMethods}} + :Example: +{{#hasApiKeyMethods}} + + API Key Authentication Example. + Given the following security scheme in the OpenAPI specification: + components: + securitySchemes: + cookieAuth: # name for the security scheme + type: apiKey + in: cookie + name: JSESSIONID # cookie name + + You can programmatically set the cookie: + +conf = {{{packageName}}}.Configuration( + api_key={'cookieAuth': 'abc123'} + api_key_prefix={'cookieAuth': 'JSESSIONID'} +) + + The following cookie will be added to the HTTP request: + Cookie: JSESSIONID abc123 +{{/hasApiKeyMethods}} +{{#hasHttpBasicMethods}} + + HTTP Basic Authentication Example. + Given the following security scheme in the OpenAPI specification: + components: + securitySchemes: + http_basic_auth: + type: http + scheme: basic + + Configure API client with HTTP basic authentication: + +conf = {{{packageName}}}.Configuration( + username='the-user', + password='the-password', +) + +{{/hasHttpBasicMethods}} +{{#hasHttpSignatureMethods}} + + HTTP Signature Authentication Example. + Given the following security scheme in the OpenAPI specification: + components: + securitySchemes: + http_basic_auth: + type: http + scheme: signature + + Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme, + sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time + of the signature to 5 minutes after the signature has been created. + Note you can use the constants defined in the {{{packageName}}}.signing module, and you can + also specify arbitrary HTTP headers to be included in the HTTP signature, except for the + 'Authorization' header, which is used to carry the signature. + + One may be tempted to sign all headers by default, but in practice it rarely works. + This is because explicit proxies, transparent proxies, TLS termination endpoints or + load balancers may add/modify/remove headers. Include the HTTP headers that you know + are not going to be modified in transit. + +conf = {{{packageName}}}.Configuration( + signing_info = {{{packageName}}}.signing.HttpSigningConfiguration( + key_id = 'my-key-id', + private_key_path = 'rsa.pem', + signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019, + signing_algorithm = {{{packageName}}}.signing.ALGORITHM_RSASSA_PSS, + signed_headers = [{{{packageName}}}.signing.HEADER_REQUEST_TARGET, + {{{packageName}}}.signing.HEADER_CREATED, + {{{packageName}}}.signing.HEADER_EXPIRES, + {{{packageName}}}.signing.HEADER_HOST, + {{{packageName}}}.signing.HEADER_DATE, + {{{packageName}}}.signing.HEADER_DIGEST, + 'Content-Type', + 'User-Agent' + ], + signature_max_validity = datetime.timedelta(minutes=5) + ) +) +{{/hasHttpSignatureMethods}} +{{/hasAuthMethods}} + """ + + _default: ClassVar[Optional[Self]] = None + + def __init__( + self, + host: Optional[str]=None, + api_key: Optional[Dict[str, str]]=None, + api_key_prefix: Optional[Dict[str, str]]=None, + username: Optional[str]=None, + password: Optional[str]=None, + access_token: Optional[str]=None, + client_id: Optional[str]=None, + client_secret: Optional[str]=None, +{{#hasHttpSignatureMethods}} + signing_info: Optional[HttpSigningConfiguration]=None, +{{/hasHttpSignatureMethods}} + server_index: Optional[int]=None, + server_variables: Optional[ServerVariablesT]=None, + server_operation_index: Optional[Dict[int, int]]=None, + server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None, + ignore_operation_servers: bool=False, + ssl_ca_cert: Optional[str]=None, + retries: Optional[int] = None, + ca_cert_data: Optional[Union[str, bytes]] = None, + cert_file: Optional[str]=None, + key_file: Optional[str]=None, + *, + debug: Optional[bool] = None, + ) -> None: + """Constructor + """ + self._base_path = "{{{basePath}}}" if host is None else host + """Default Base url + """ + self.server_index = 0 if server_index is None and host is None else server_index + self.server_operation_index = server_operation_index or {} + """Default server index + """ + self.server_variables = server_variables or {} + self.server_operation_variables = server_operation_variables or {} + """Default server variables + """ + self.ignore_operation_servers = ignore_operation_servers + """Ignore operation servers + """ + self.temp_folder_path = None + """Temp file folder for downloading files + """ + # Authentication Settings + self.api_key = {} + if api_key: + self.api_key = api_key + """dict to store API key(s) + """ + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix + """dict to store API prefix (e.g. Bearer) + """ + self.refresh_api_key_hook = None + """function hook to refresh API key if expired + """ + self.username = username + """Username for HTTP basic authentication + """ + self.password = password + """Password for HTTP basic authentication + """ + self.access_token = access_token + """Access token + """ + self.client_id = client_id + """Client ID for OAuth2 authentication + """ + self.client_secret = client_secret + """Client Secret for OAuth2 authentication + """ + self.temp_access_token = None + """Temporary access token for OAuth2 + """ + self.temp_access_token_expiration = 0 + """Expiration time of the temporary access token + """ +{{#hasHttpSignatureMethods}} + if signing_info is not None: + signing_info.host = host + self.signing_info = signing_info + """The HTTP signing configuration + """ +{{/hasHttpSignatureMethods}} + self.logger = {} + """Logging Settings + """ + self.logger["package_logger"] = logging.getLogger("{{packageName}}") + self.logger["urllib3_logger"] = logging.getLogger("urllib3") + self.logger_format = '%(asctime)s %(levelname)s %(message)s' + """Log format + """ + self.logger_stream_handler = None + """Log stream handler + """ + self.logger_file_handler: Optional[FileHandler] = None + """Log file handler + """ + self.logger_file = None + """Debug file location + """ + if debug is not None: + self.debug = debug + else: + self.__debug = False + """Debug switch + """ + + self.verify_ssl = True + """SSL/TLS verification + Set this to false to skip verifying SSL certificate when calling API + from https server. + """ + self.ssl_ca_cert = ssl_ca_cert + """Set this to customize the certificate file to verify the peer. + """ + self.ca_cert_data = ca_cert_data + """Set this to verify the peer using PEM (str) or DER (bytes) + certificate data. + """ + self.cert_file = cert_file + """client certificate file + """ + self.key_file = key_file + """client key file + """ + self.assert_hostname = None + """Set this to True/False to enable/disable SSL hostname verification. + """ + self.tls_server_name = None + """SSL/TLS Server Name Indication (SNI) + Set this to the SNI value expected by the server. + """ + + {{#async}} + self.connection_pool_maxsize = 100 + """This value is passed to the aiohttp to limit simultaneous connections. + Default values is 100, None means no-limit. + """ + {{/async}} + {{^async}} + self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 + """urllib3 connection pool's maximum number of connections saved + per pool. urllib3 uses 1 connection as default value, but this is + not the best value when you are making a lot of possibly parallel + requests to the same host, which is often the case here. + cpu_count * 5 is used as default value to increase performance. + """ + {{/async}} + + self.proxy: Optional[str] = None + """Proxy URL + """ + self.proxy_headers = None + """Proxy headers + """ + self.safe_chars_for_path_param = '' + """Safe chars for path_param + """ + self.retries = retries + """Adding retries to override urllib3 default value 3 + """ + # Enable client side validation + self.client_side_validation = True + + self.socket_options = None + """Options to pass down to the underlying urllib3 socket + """ + + self.datetime_format = "{{{datetimeFormat}}}" + """datetime format + """ + + self.date_format = "{{{dateFormat}}}" + """date format + """ + + def __deepcopy__(self, memo: Dict[int, Any]) -> Self: + cls = self.__class__ + result = cls.__new__(cls) + memo[id(self)] = result + for k, v in self.__dict__.items(): + if k not in ('logger', 'logger_file_handler'): + setattr(result, k, copy.deepcopy(v, memo)) + # shallow copy of loggers + result.logger = copy.copy(self.logger) + # use setters to configure loggers + result.logger_file = self.logger_file + result.debug = self.debug + return result + + def __setattr__(self, name: str, value: Any) -> None: + object.__setattr__(self, name, value) +{{#hasHttpSignatureMethods}} + if name == "signing_info" and value is not None: + # Ensure the host parameter from signing info is the same as + # Configuration.host. + value.host = self.host +{{/hasHttpSignatureMethods}} + + @classmethod + def set_default(cls, default: Optional[Self]) -> None: + """Set default instance of configuration. + + It stores default configuration, which can be + returned by get_default_copy method. + + :param default: object of Configuration + """ + cls._default = default + + @classmethod + def get_default_copy(cls) -> Self: + """Deprecated. Please use `get_default` instead. + + Deprecated. Please use `get_default` instead. + + :return: The configuration object. + """ + return cls.get_default() + + @classmethod + def get_default(cls) -> Self: + """Return the default configuration. + + This method returns newly created, based on default constructor, + object of Configuration class or returns a copy of default + configuration. + + :return: The configuration object. + """ + if cls._default is None: + cls._default = cls() + return cls._default + + @property + def logger_file(self) -> Optional[str]: + """The logger file. + + If the logger_file is None, then add stream handler and remove file + handler. Otherwise, add file handler and remove stream handler. + + :param value: The logger_file path. + :type: str + """ + return self.__logger_file + + @logger_file.setter + def logger_file(self, value: Optional[str]) -> None: + """The logger file. + + If the logger_file is None, then add stream handler and remove file + handler. Otherwise, add file handler and remove stream handler. + + :param value: The logger_file path. + :type: str + """ + self.__logger_file = value + if self.__logger_file: + # If set logging file, + # then add file handler and remove stream handler. + self.logger_file_handler = logging.FileHandler(self.__logger_file) + self.logger_file_handler.setFormatter(self.logger_formatter) + for _, logger in self.logger.items(): + logger.addHandler(self.logger_file_handler) + + @property + def debug(self) -> bool: + """Debug status + + :param value: The debug status, True or False. + :type: bool + """ + return self.__debug + + @debug.setter + def debug(self, value: bool) -> None: + """Debug status + + :param value: The debug status, True or False. + :type: bool + """ + self.__debug = value + if self.__debug: + # if debug status is True, turn on debug logging + for _, logger in self.logger.items(): + logger.setLevel(logging.DEBUG) + # turn on httplib debug + httplib.HTTPConnection.debuglevel = 1 + else: + # if debug status is False, turn off debug logging, + # setting log level to default `logging.WARNING` + for _, logger in self.logger.items(): + logger.setLevel(logging.WARNING) + # turn off httplib debug + httplib.HTTPConnection.debuglevel = 0 + + @property + def logger_format(self) -> str: + """The logger format. + + The logger_formatter will be updated when sets logger_format. + + :param value: The format string. + :type: str + """ + return self.__logger_format + + @logger_format.setter + def logger_format(self, value: str) -> None: + """The logger format. + + The logger_formatter will be updated when sets logger_format. + + :param value: The format string. + :type: str + """ + self.__logger_format = value + self.logger_formatter = logging.Formatter(self.__logger_format) + + def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]: + """Gets API key (with prefix if set). + + :param identifier: The identifier of apiKey. + :param alias: The alternative identifier of apiKey. + :return: The token for api key authentication. + """ + if self.refresh_api_key_hook is not None: + self.refresh_api_key_hook(self) + key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None) + if key: + prefix = self.api_key_prefix.get(identifier) + if prefix: + return "%s %s" % (prefix, key) + else: + return key + + return None + + def get_basic_auth_token(self) -> Optional[str]: + """Gets HTTP basic authentication header (string). + + :return: The token for basic HTTP authentication. + """ + username = "" + if self.username is not None: + username = self.username + password = "" + if self.password is not None: + password = self.password + return urllib3.util.make_headers( + basic_auth=username + ':' + password + ).get('authorization') + + def get_access_token(self) -> str: + """Gets HTTP bearer authentication header (string). + + :return: The token for bearer HTTP authentication. + """ + now = int(time.time()) + if self.temp_access_token and self.temp_access_token_expiration > now + 60: + return self.temp_access_token + else: + print("Fetching new access token") + _bytes = f"{self.client_id}:{self.client_secret}".encode('utf-8') + _encoded_string = base64.b64encode(_bytes).decode('utf-8') + auth_header = f"Basic {_encoded_string}" + resp = urllib3.request( + 'POST', + {{#authMethods}}{{#isOAuth}}'{{tokenUrl}}',{{/isOAuth}}{{/authMethods}} + headers={ + 'Authorization': auth_header, + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body='grant_type=client_credentials' + ) + body = resp.json() + self.temp_access_token = body['access_token'] + self.temp_access_token_expiration = now + body['expires_in'] + return self.temp_access_token + + def auth_settings(self)-> AuthSettings: + """Gets Auth Settings dict for api client. + + :return: The Auth Settings information dict. + """ + auth: AuthSettings = {} +{{#authMethods}} +{{#isApiKey}} + if '{{name}}' in self.api_key{{#vendorExtensions.x-auth-id-alias}} or '{{.}}' in self.api_key{{/vendorExtensions.x-auth-id-alias}}: + auth['{{name}}'] = { + 'type': 'api_key', + 'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}}, + 'key': '{{keyParamName}}', + 'value': self.get_api_key_with_prefix( + '{{name}}',{{#vendorExtensions.x-auth-id-alias}} + alias='{{.}}',{{/vendorExtensions.x-auth-id-alias}} + ), + } +{{/isApiKey}} +{{#isBasic}} + {{#isBasicBasic}} + if self.username is not None and self.password is not None: + auth['{{name}}'] = { + 'type': 'basic', + 'in': 'header', + 'key': 'Authorization', + 'value': self.get_basic_auth_token() + } + {{/isBasicBasic}} + {{#isBasicBearer}} + if self.access_token is not None: + auth['{{name}}'] = { + 'type': 'bearer', + 'in': 'header', + {{#bearerFormat}} + 'format': '{{{.}}}', + {{/bearerFormat}} + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token + } + {{/isBasicBearer}} + {{#isHttpSignature}} + if self.signing_info is not None: + auth['{{name}}'] = { + 'type': 'http-signature', + 'in': 'header', + 'key': 'Authorization', + 'value': None # Signature headers are calculated for every HTTP request + } + {{/isHttpSignature}} +{{/isBasic}} +{{#isOAuth}} + if self.access_token is not None: + auth['OAuth2'] = { + 'type': 'oauth2', + 'in': 'header', + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token + } + if self.client_id is not None and self.client_secret is not None: + auth['OAuth2'] = { + 'type': 'oauth2', + 'in': 'header', + 'key': 'Authorization', + 'value': 'Bearer ' + self.get_access_token(), + } +{{/isOAuth}} +{{/authMethods}} + return auth + + def to_debug_report(self) -> str: + """Gets the essential information for debugging. + + :return: The report for debugging. + """ + return "Python SDK Debug Report:\n"\ + "OS: {env}\n"\ + "Python Version: {pyversion}\n"\ + "Version of the API: {{version}}\n"\ + "SDK Package Version: {{packageVersion}}".\ + format(env=sys.platform, pyversion=sys.version) + + def get_host_settings(self) -> List[HostSetting]: + """Gets an array of host settings + + :return: An array of host settings + """ + return [ + {{#servers}} + { + 'url': "{{{url}}}", + 'description': "{{{description}}}{{^description}}No description provided{{/description}}", + {{#variables}} + {{#-first}} + 'variables': { + {{/-first}} + '{{{name}}}': { + 'description': "{{{description}}}{{^description}}No description provided{{/description}}", + 'default_value': "{{{defaultValue}}}", + {{#enumValues}} + {{#-first}} + 'enum_values': [ + {{/-first}} + "{{{.}}}"{{^-last}},{{/-last}} + {{#-last}} + ] + {{/-last}} + {{/enumValues}} + }{{^-last}},{{/-last}} + {{#-last}} + } + {{/-last}} + {{/variables}} + }{{^-last}},{{/-last}} + {{/servers}} + ] + + def get_host_from_settings( + self, + index: Optional[int], + variables: Optional[ServerVariablesT]=None, + servers: Optional[List[HostSetting]]=None, + ) -> str: + """Gets host URL based on the index and variables + :param index: array index of the host settings + :param variables: hash of variable and the corresponding value + :param servers: an array of host settings or None + :return: URL based on host settings + """ + if index is None: + return self._base_path + + variables = {} if variables is None else variables + servers = self.get_host_settings() if servers is None else servers + + try: + server = servers[index] + except IndexError: + raise ValueError( + "Invalid index {0} when selecting the host settings. " + "Must be less than {1}".format(index, len(servers))) + + url = server['url'] + + # go through variables and replace placeholders + for variable_name, variable in server.get('variables', {}).items(): + used_value = variables.get( + variable_name, variable['default_value']) + + if 'enum_values' in variable \ + and used_value not in variable['enum_values']: + raise ValueError( + "The variable `{0}` in the host URL has invalid value " + "{1}. Must be {2}.".format( + variable_name, variables[variable_name], + variable['enum_values'])) + + url = url.replace("{" + variable_name + "}", used_value) + + return url + + @property + def host(self) -> str: + """Return generated host.""" + return self.get_host_from_settings(self.server_index, variables=self.server_variables) + + @host.setter + def host(self, value: str) -> None: + """Fix base path.""" + self._base_path = value + self.server_index = None diff --git a/custom_templates/python_doc_auth_partial.mustache b/custom_templates/python_doc_auth_partial.mustache new file mode 100644 index 00000000..a440b35e --- /dev/null +++ b/custom_templates/python_doc_auth_partial.mustache @@ -0,0 +1,112 @@ +# Defining the host is optional and defaults to {{{basePath}}} +# See configuration.py for a list of all supported configuration parameters. +configuration = {{{packageName}}}.Configuration( + host = "{{{basePath}}}" +) + +{{#hasAuthMethods}} +# The client must configure the authentication and authorization parameters +# in accordance with the API server security policy. +# Examples for each auth method are provided below, use the example that +# satisfies your auth use case. +{{#authMethods}} +{{#isBasic}} +{{#isBasicBasic}} + +# Configure HTTP basic authorization: {{{name}}} +configuration = {{{packageName}}}.Configuration( + username = os.environ["USERNAME"], + password = os.environ["PASSWORD"] +) +{{/isBasicBasic}} +{{#isBasicBearer}} + +# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}} +configuration = {{{packageName}}}.Configuration( + access_token = os.environ["BEARER_TOKEN"] +) +{{/isBasicBearer}} +{{#isHttpSignature}} + +# Configure HTTP message signature: {{{name}}} +# The HTTP Signature Header mechanism that can be used by a client to +# authenticate the sender of a message and ensure that particular headers +# have not been modified in transit. +# +# You can specify the signing key-id, private key path, signing scheme, +# signing algorithm, list of signed headers and signature max validity. +# The 'key_id' parameter is an opaque string that the API server can use +# to lookup the client and validate the signature. +# The 'private_key_path' parameter should be the path to a file that +# contains a DER or base-64 encoded private key. +# The 'private_key_passphrase' parameter is optional. Set the passphrase +# if the private key is encrypted. +# The 'signed_headers' parameter is used to specify the list of +# HTTP headers included when generating the signature for the message. +# You can specify HTTP headers that you want to protect with a cryptographic +# signature. Note that proxies may add, modify or remove HTTP headers +# for legitimate reasons, so you should only add headers that you know +# will not be modified. For example, if you want to protect the HTTP request +# body, you can specify the Digest header. In that case, the client calculates +# the digest of the HTTP request body and includes the digest in the message +# signature. +# The 'signature_max_validity' parameter is optional. It is configured as a +# duration to express when the signature ceases to be valid. The client calculates +# the expiration date every time it generates the cryptographic signature +# of an HTTP request. The API server may have its own security policy +# that controls the maximum validity of the signature. The client max validity +# must be lower than the server max validity. +# The time on the client and server must be synchronized, otherwise the +# server may reject the client signature. +# +# The client must use a combination of private key, signing scheme, +# signing algorithm and hash algorithm that matches the security policy of +# the API server. +# +# See {{{packageName}}}.signing for a list of all supported parameters. +from {{{packageName}}} import signing +import datetime + +configuration = {{{packageName}}}.Configuration( + host = "{{{basePath}}}", + signing_info = {{{packageName}}}.HttpSigningConfiguration( + key_id = 'my-key-id', + private_key_path = 'private_key.pem', + private_key_passphrase = 'YOUR_PASSPHRASE', + signing_scheme = {{{packageName}}}.signing.SCHEME_HS2019, + signing_algorithm = {{{packageName}}}.signing.ALGORITHM_ECDSA_MODE_FIPS_186_3, + hash_algorithm = {{{packageName}}}.signing.SCHEME_RSA_SHA256, + signed_headers = [ + {{{packageName}}}.signing.HEADER_REQUEST_TARGET, + {{{packageName}}}.signing.HEADER_CREATED, + {{{packageName}}}.signing.HEADER_EXPIRES, + {{{packageName}}}.signing.HEADER_HOST, + {{{packageName}}}.signing.HEADER_DATE, + {{{packageName}}}.signing.HEADER_DIGEST, + 'Content-Type', + 'Content-Length', + 'User-Agent' + ], + signature_max_validity = datetime.timedelta(minutes=5) + ) +) +{{/isHttpSignature}} +{{/isBasic}} +{{#isApiKey}} + +# Configure API key authorization: {{{name}}} +configuration.api_key['{{{name}}}'] = os.environ["API_KEY"] + +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['{{name}}'] = 'Bearer' +{{/isApiKey}} +{{#isOAuth}} + +# Configure your client ID and secret for OAuth +configuration = {{{packageName}}}.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) +{{/isOAuth}} +{{/authMethods}} +{{/hasAuthMethods}} diff --git a/docs/CallsApi.md b/docs/CallsApi.md index 03ab8819..e514c55e 100644 --- a/docs/CallsApi.md +++ b/docs/CallsApi.md @@ -25,6 +25,7 @@ All calls are initially queued. Your outbound calls will initiated at a specific ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -50,6 +51,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -82,7 +89,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -117,6 +124,7 @@ Retrieve the current state of a specific call. This information is near-realtime ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -141,6 +149,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -173,7 +187,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -209,6 +223,7 @@ Also, call information is kept for 7 days after the calls are hung up. If you at ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -233,6 +248,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -277,7 +298,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -310,6 +331,7 @@ Interrupts and redirects a call to a different URL that should return a BXML doc ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -334,6 +356,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -366,7 +394,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -400,6 +428,7 @@ Interrupts and replaces an active call's BXML document. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -423,6 +452,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -458,7 +493,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/ConferencesApi.md b/docs/ConferencesApi.md index 2564eedf..dad82836 100644 --- a/docs/ConferencesApi.md +++ b/docs/ConferencesApi.md @@ -25,6 +25,7 @@ Downloads the specified recording file. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -48,6 +49,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -82,7 +89,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -115,6 +122,7 @@ Returns information about the specified conference. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -139,6 +147,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -171,7 +185,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -204,6 +218,7 @@ Returns information about the specified conference member. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -228,6 +243,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -262,7 +283,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -295,6 +316,7 @@ Returns metadata for the specified recording. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -319,6 +341,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -353,7 +381,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -386,6 +414,7 @@ Returns a (potentially empty) list of metadata for the recordings that took plac ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -410,6 +439,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -442,7 +477,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -477,6 +512,7 @@ Returns a max of 1000 conferences, sorted by `createdTime` from oldest to newest ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -501,6 +537,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -541,7 +583,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -574,6 +616,7 @@ Update the conference state. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -598,6 +641,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -630,7 +679,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -663,6 +712,7 @@ Update the conference BXML document. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -686,6 +736,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -721,7 +777,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -754,6 +810,7 @@ Updates settings for a particular conference member. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -778,6 +835,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -812,7 +875,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/MFAApi.md b/docs/MFAApi.md index 3a981154..e15db167 100644 --- a/docs/MFAApi.md +++ b/docs/MFAApi.md @@ -19,6 +19,7 @@ Send an MFA code via text message (SMS). ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -44,6 +45,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -76,7 +83,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -105,6 +112,7 @@ Send an MFA Code via a phone call. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -130,6 +138,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -162,7 +176,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -191,6 +205,7 @@ Verify a previously sent MFA code. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -216,6 +231,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -248,7 +269,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/MediaApi.md b/docs/MediaApi.md index bd3a8bd6..1cfe39c2 100644 --- a/docs/MediaApi.md +++ b/docs/MediaApi.md @@ -24,6 +24,7 @@ file with the same name. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -47,6 +48,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -77,7 +84,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -110,6 +117,7 @@ Downloads a media file you previously uploaded. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -133,6 +141,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -165,7 +179,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -198,6 +212,7 @@ Gets a list of your media files. No query parameters are supported. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -222,6 +237,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -254,7 +275,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -291,6 +312,7 @@ A list of supported media types can be found [here](https://support.bandwidth.co ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -314,6 +336,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -350,7 +378,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/MessagesApi.md b/docs/MessagesApi.md index cab2fc2e..6f2e3fb4 100644 --- a/docs/MessagesApi.md +++ b/docs/MessagesApi.md @@ -18,6 +18,7 @@ Endpoint for sending text messages and picture messages using V2 messaging. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -43,6 +44,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -75,7 +82,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -109,6 +116,7 @@ Returns a list of messages based on query parameters. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -137,6 +145,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -221,7 +235,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/MultiChannelApi.md b/docs/MultiChannelApi.md index 0d7713b1..646239e5 100644 --- a/docs/MultiChannelApi.md +++ b/docs/MultiChannelApi.md @@ -17,6 +17,7 @@ Endpoint for sending Multi-Channel messages. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -42,6 +43,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -74,7 +81,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/PhoneNumberLookupApi.md b/docs/PhoneNumberLookupApi.md index da1fe651..d53e7597 100644 --- a/docs/PhoneNumberLookupApi.md +++ b/docs/PhoneNumberLookupApi.md @@ -19,6 +19,7 @@ Creates an asynchronous bulk phone number lookup request. Maximum of 15,000 tele ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -44,6 +45,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -76,7 +83,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -102,6 +109,7 @@ Creates a synchronous phone number lookup request. Maximum of 100 telephone numb ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -127,6 +135,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -159,7 +173,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -185,6 +199,7 @@ Get an existing [Asynchronous Bulk Number Lookup](#tag/Phone-Number-Lookup/opera ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -209,6 +224,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -241,7 +262,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/RecordingsApi.md b/docs/RecordingsApi.md index e461ef87..51043809 100644 --- a/docs/RecordingsApi.md +++ b/docs/RecordingsApi.md @@ -28,6 +28,7 @@ Note: After the deletion is requested and a `204` is returned, neither the recor ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -51,6 +52,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -83,7 +90,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -116,6 +123,7 @@ Deletes the specified recording's media. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -139,6 +147,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -171,7 +185,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -206,6 +220,7 @@ Note: After the deletion is requested and a `204` is returned, the transcription ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -229,6 +244,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -261,7 +282,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -294,6 +315,7 @@ Downloads the specified recording. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -317,6 +339,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -351,7 +379,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -384,6 +412,7 @@ Returns metadata for the specified recording. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -408,6 +437,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -442,7 +477,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -478,6 +513,7 @@ During a [``](/docs/voice/bxml/transfer) the A-leg transcript will be ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -502,6 +538,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -536,7 +578,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -572,6 +614,7 @@ empty if no recordings match the specified criteria. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -596,6 +639,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -634,7 +683,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -668,6 +717,7 @@ that took place during the specified call. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -692,6 +742,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -724,7 +780,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -759,6 +815,7 @@ less than 4 hours. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -783,6 +840,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -817,7 +880,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -850,6 +913,7 @@ Pause or resume a recording on an active phone call. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -874,6 +938,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -906,7 +976,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/StatisticsApi.md b/docs/StatisticsApi.md index 3df9571f..642e4e8f 100644 --- a/docs/StatisticsApi.md +++ b/docs/StatisticsApi.md @@ -17,6 +17,7 @@ Returns details about the current state of the account. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -41,6 +42,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -71,7 +78,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/TollFreeVerificationApi.md b/docs/TollFreeVerificationApi.md index d5995ce1..9d972ba1 100644 --- a/docs/TollFreeVerificationApi.md +++ b/docs/TollFreeVerificationApi.md @@ -27,6 +27,7 @@ The returned subscription object will contain an ID that can be used to modify o ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -52,6 +53,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -84,7 +91,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -117,6 +124,7 @@ Delete a toll-free verification submission for a toll-free number. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -140,6 +148,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -170,7 +184,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -203,6 +217,7 @@ Delete a webhook subscription by ID. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -226,6 +241,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -256,7 +277,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -290,6 +311,7 @@ Submission information will be appended to the response if it is available. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -314,6 +336,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -346,7 +374,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -379,6 +407,7 @@ Lists valid toll-free use cases. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -402,6 +431,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -428,7 +463,7 @@ This endpoint does not need any parameter. ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -462,6 +497,7 @@ If `basicAuthentication` is defined, the `password` property of that object will ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -486,6 +522,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -516,7 +558,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -548,6 +590,7 @@ Submit a request for verification of a toll-free phone number. ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -572,6 +615,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -602,7 +651,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -635,6 +684,7 @@ Submissions are only eligible for resubmission for 7 days within being processed ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -659,6 +709,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -691,7 +747,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -723,6 +779,7 @@ Update an existing webhook subscription (`callbackUrl` and `basicAuthentication` ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -748,6 +805,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -782,7 +845,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/docs/TranscriptionsApi.md b/docs/TranscriptionsApi.md index 2a8b05f2..af83cece 100644 --- a/docs/TranscriptionsApi.md +++ b/docs/TranscriptionsApi.md @@ -21,6 +21,7 @@ Note: After the deletion is requested and a `200` is returned, the transcription ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -44,6 +45,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -76,7 +83,7 @@ void (empty response body) ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -109,6 +116,7 @@ Retrieve the specified transcription that was created on this call via [startTra ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -133,6 +141,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -167,7 +181,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -200,6 +214,7 @@ List the transcriptions created on this call via [startTranscription](/docs/voic ### Example * Basic Authentication (Basic): +* OAuth Authentication (OAuth2): ```python import bandwidth @@ -224,6 +239,12 @@ configuration = bandwidth.Configuration( password = os.environ["PASSWORD"] ) +# Configure your client ID and secret for OAuth +configuration = bandwidth.Configuration( + client_id = os.environ["CLIENT_ID"], + client_secret = os.environ["CLIENT_SECRET"] +) + # Enter a context with an instance of the API client with bandwidth.ApiClient(configuration) as api_client: # Create an instance of the API class @@ -256,7 +277,7 @@ Name | Type | Description | Notes ### Authorization -[Basic](../README.md#Basic) +[Basic](../README.md#Basic), [OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/test-requirements.txt b/test-requirements.txt index c143f1ce..7277c594 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,8 @@ pytest >= 7.2.1 pytest-cov >= 2.8.1 -pyhamcrest>=2.1.0 +pyhamcrest >= 2.1.0 tox >= 3.9.0 flake8 >= 4.0.0 types-python-dateutil >= 2.8.19.14 mypy >= 1.5 -zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability +zipp >= 3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability diff --git a/test/smoke/test_calls_api.py b/test/smoke/test_calls_api.py index 10b3bf97..88099607 100644 --- a/test/smoke/test_calls_api.py +++ b/test/smoke/test_calls_api.py @@ -10,7 +10,7 @@ from hamcrest import assert_that, has_properties, not_none, instance_of -import bandwidth +from bandwidth import ApiClient, ApiResponse, Configuration from bandwidth.api import calls_api from bandwidth.models.create_call import CreateCall from bandwidth.models.create_call_response import CreateCallResponse @@ -20,7 +20,6 @@ from bandwidth.models.machine_detection_mode_enum import MachineDetectionModeEnum from bandwidth.models.call_state_enum import CallStateEnum from bandwidth.models.redirect_method_enum import RedirectMethodEnum -from bandwidth.models.call_state import CallState from bandwidth.models.update_call import UpdateCall from bandwidth.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException @@ -28,33 +27,34 @@ class CallsIntegration(unittest.TestCase): """Voice Calls API integration test""" - def setUp(self): - configuration = bandwidth.Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + @classmethod + def setUpClass(cls): + configuration = Configuration( + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - api_client = bandwidth.ApiClient(configuration) - self.calls_api_instance = calls_api.CallsApi(api_client) + api_client = ApiClient(configuration) + cls.calls_api_instance = calls_api.CallsApi(api_client) # Unauthorized API Client - unauthorizedConfiguration = bandwidth.Configuration( + unauthorizedConfiguration = Configuration( username='bad_username', password='bad_password' ) - unauthorized_api_client = bandwidth.ApiClient(unauthorizedConfiguration) - self.unauthorized_api_instance = calls_api.CallsApi(unauthorized_api_client) + unauthorized_api_client = ApiClient(unauthorizedConfiguration) + cls.unauthorized_api_instance = calls_api.CallsApi(unauthorized_api_client) # Forbidden API Client - forbiddenConfiguration = bandwidth.Configuration( + forbiddenConfiguration = Configuration( username=FORBIDDEN_USERNAME, password=FORBIDDEN_PASSWORD ) - forbidden_api_client = bandwidth.ApiClient(forbiddenConfiguration) - self.forbidden_api_instance = calls_api.CallsApi(forbidden_api_client) - self.account_id = BW_ACCOUNT_ID - self.createCallBody = CreateCall( + forbidden_api_client = ApiClient(forbiddenConfiguration) + cls.forbidden_api_instance = calls_api.CallsApi(forbidden_api_client) + cls.account_id = BW_ACCOUNT_ID + cls.createCallBody = CreateCall( to=USER_NUMBER, var_from=BW_NUMBER, privacy=True, @@ -92,17 +92,18 @@ def setUp(self): priority=5, tag="tag_example", ) - self.testCallBody = CreateCall(to=USER_NUMBER, var_from=BW_NUMBER, application_id=BW_VOICE_APPLICATION_ID, answer_url=BASE_CALLBACK_URL) - self.testMantecaCallBody = CreateCall(to=MANTECA_IDLE_NUMBER, var_from=MANTECA_ACTIVE_NUMBER, application_id=MANTECA_APPLICATION_ID, answer_url=MANTECA_BASE_URL + "/bxml/pause") - self.updateStateCompleted = UpdateCall(state=CallStateEnum("completed")) - self.testCallId = "Call-Id" - self.testBxmlBody = 'This is a test bxml response' - self.callIdArray = [] - self.TEST_SLEEP = 5 - self.TEST_SLEEP_LONG = 15 - - def tearDown(self): - callCleanup(self) + cls.testCallBody = CreateCall(to=USER_NUMBER, var_from=BW_NUMBER, application_id=BW_VOICE_APPLICATION_ID, answer_url=BASE_CALLBACK_URL) + cls.testMantecaCallBody = CreateCall(to=MANTECA_IDLE_NUMBER, var_from=MANTECA_ACTIVE_NUMBER, application_id=MANTECA_APPLICATION_ID, answer_url=MANTECA_BASE_URL + "/bxml/pause") + cls.updateStateCompleted = UpdateCall(state=CallStateEnum("completed")) + cls.testCallId = "Call-Id" + cls.testBxmlBody = 'This is a test bxml response' + cls.callIdArray = [] + cls.TEST_SLEEP = 5 + cls.TEST_SLEEP_LONG = 15 + + @classmethod + def tearDownClass(cls): + callCleanup(cls) def assertApiException(self, context: ApiException, expectedException: ApiException, expected_status_code: int): """Validates that common API exceptions, (401, 403, and 404) are properly formatted diff --git a/test/smoke/test_conferences_api.py b/test/smoke/test_conferences_api.py index 53f9f9d7..761aab40 100644 --- a/test/smoke/test_conferences_api.py +++ b/test/smoke/test_conferences_api.py @@ -2,20 +2,17 @@ Integration tests for Bandwidth's Voice Conferences API """ -from cgi import test import json import time -from typing import Dict, List, Tuple +from typing import Dict, Tuple import unittest from hamcrest import assert_that, has_properties, not_none, instance_of, greater_than -import bandwidth -from bandwidth import ApiResponse +from bandwidth import ApiClient, ApiResponse, Configuration from bandwidth.api import calls_api from bandwidth.models.create_call import CreateCall from bandwidth.models.create_call_response import CreateCallResponse -from bandwidth.models.call_state import CallState from bandwidth.models.call_state_enum import CallStateEnum from bandwidth.models.update_call import UpdateCall from bandwidth.models.redirect_method_enum import RedirectMethodEnum @@ -36,44 +33,45 @@ class ConferencesIntegration(unittest.TestCase): Voice Conferences API integration test """ - def setUp(self): + @classmethod + def setUpClass(cls): """ Set up for our tests by creating the CallsApi and ConferencesApi instances for testing as well as the unauthorized and forbidden credentials for the 4xx tests. """ - configuration = bandwidth.Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + configuration = Configuration( + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - api_client = bandwidth.ApiClient(configuration) + api_client = ApiClient(configuration) - self.calls_api_instance = calls_api.CallsApi(api_client) - self.conference_api_instance = conferences_api.ConferencesApi(api_client) + cls.calls_api_instance = calls_api.CallsApi(api_client) + cls.conference_api_instance = conferences_api.ConferencesApi(api_client) - unauthorizedConfiguration = bandwidth.Configuration( + unauthorizedConfiguration = Configuration( username='bad_username', password='bad_password' ) - unauthorized_api_client = bandwidth.ApiClient(unauthorizedConfiguration) - self.unauthorized_api_instance = conferences_api.ConferencesApi(unauthorized_api_client) + unauthorized_api_client = ApiClient(unauthorizedConfiguration) + cls.unauthorized_api_instance = conferences_api.ConferencesApi(unauthorized_api_client) - forbiddenConfiguration = bandwidth.Configuration( + forbiddenConfiguration = Configuration( username=FORBIDDEN_USERNAME, password=FORBIDDEN_PASSWORD ) - forbidden_api_client = bandwidth.ApiClient(forbiddenConfiguration) - self.forbidden_api_instance = conferences_api.ConferencesApi(forbidden_api_client) + forbidden_api_client = ApiClient(forbiddenConfiguration) + cls.forbidden_api_instance = conferences_api.ConferencesApi(forbidden_api_client) # Rest client for interacting with Manteca - self.rest_client = RESTClientObject(bandwidth.Configuration.get_default_copy()) - configuration = bandwidth.Configuration( + cls.rest_client = RESTClientObject(Configuration.get_default_copy()) + configuration = Configuration( username=BW_USERNAME, password=BW_PASSWORD, ) - self.account_id = BW_ACCOUNT_ID - self.callIdArray = [] - self.testUpdateConf = UpdateConference( + cls.account_id = BW_ACCOUNT_ID + cls.callIdArray = [] + cls.testUpdateConf = UpdateConference( state=ConferenceStateEnum("active"), redirect_url=MANTECA_BASE_URL + "/bxml/pause", redirect_method=RedirectMethodEnum("POST"), @@ -85,17 +83,18 @@ def setUp(self): fallback_password="mySecretPassword1!", tag="My Custom Tag", ) - self.testUpdateBxml = 'This is test BXML.' - self.testUpdateMember = UpdateConferenceMember(mute=False) - self.testConfId = "Conf-id" - self.testMemberId = "Member-Id" - self.testRecordId = "Recording-Id" - self.TEST_SLEEP = 3 - self.TEST_SLEEP_LONG = 10 - self.MAX_RETRIES = 40 - - def tearDown(self): - callCleanup(self) + cls.testUpdateBxml = 'This is test BXML.' + cls.testUpdateMember = UpdateConferenceMember(mute=False) + cls.testConfId = "Conf-id" + cls.testMemberId = "Member-Id" + cls.testRecordId = "Recording-Id" + cls.TEST_SLEEP = 3 + cls.TEST_SLEEP_LONG = 10 + cls.MAX_RETRIES = 40 + + @classmethod + def tearDownClass(cls): + callCleanup(cls) def assertApiException(self, context: ApiException, expectedException: ApiException, expected_status_code: int): """Validates that common API exceptions, (401, 403, and 404) are properly formatted diff --git a/test/smoke/test_media_api.py b/test/smoke/test_media_api.py index 5d1c9a5e..e875d28c 100644 --- a/test/smoke/test_media_api.py +++ b/test/smoke/test_media_api.py @@ -9,11 +9,11 @@ from bandwidth import ApiResponse -import bandwidth +from bandwidth import ApiClient, ApiResponse, Configuration from hamcrest import * from bandwidth.api import media_api from bandwidth.models.media import Media -from bandwidth.exceptions import ApiException, NotFoundException +from bandwidth.exceptions import NotFoundException from test.utils.env_variables import * @@ -21,19 +21,20 @@ class TestMedia(unittest.TestCase): """Media API integration Test """ - def setUp(self) -> None: - configuration = bandwidth.Configuration( + @classmethod + def setUpClass(cls) -> None: + configuration = Configuration( username=BW_USERNAME, password=BW_PASSWORD ) - self.api_client = bandwidth.ApiClient(configuration) - self.api_instance = media_api.MediaApi(self.api_client) - self.account_id = BW_ACCOUNT_ID - self.media_path = "./test/fixtures/" - self.media_file = "python_cat.jpeg" - self.media_id = PYTHON_VERSION + "_" + RUNNER_OS + "_" + str(uuid.uuid4()) + "_" + self.media_file - self.download_file_path = "cat_download.jpeg" - self.original_file = open(self.media_path + self.media_file, "rb") + cls.api_client = ApiClient(configuration) + cls.api_instance = media_api.MediaApi(cls.api_client) + cls.account_id = BW_ACCOUNT_ID + cls.media_path = "./test/fixtures/" + cls.media_file = "python_cat.jpeg" + cls.media_id = PYTHON_VERSION + "_" + RUNNER_OS + "_" + str(uuid.uuid4()) + "_" + cls.media_file + cls.download_file_path = "cat_download.jpeg" + cls.original_file = open(cls.media_path + cls.media_file, "rb") def uploadMedia(self) -> None: """Test uploading media diff --git a/test/smoke/test_messages_api.py b/test/smoke/test_messages_api.py index 86fd55ea..190a7d75 100644 --- a/test/smoke/test_messages_api.py +++ b/test/smoke/test_messages_api.py @@ -10,7 +10,7 @@ import bandwidth from hamcrest import * -from bandwidth import ApiResponse +from bandwidth import ApiClient, ApiResponse, Configuration from bandwidth.api import messages_api from bandwidth.models.list_message_direction_enum import ListMessageDirectionEnum from bandwidth.models.list_message_item import ListMessageItem @@ -27,48 +27,50 @@ class TestMessagesApi(unittest.TestCase): """MessagesApi unit test stubs""" - def setUp(self): + @classmethod + def setUpClass(cls): # API Client - configuration = bandwidth.Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + configuration = Configuration( + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - api_client = bandwidth.ApiClient(configuration) - self.api_instance = messages_api.MessagesApi(api_client) - self.account_id = BW_ACCOUNT_ID + api_client = ApiClient(configuration) + cls.api_instance = messages_api.MessagesApi(api_client) + cls.account_id = BW_ACCOUNT_ID # Unauthorized API Client - self.unauthorized_api_client = bandwidth.ApiClient() - self.unauthorized_api_instance = messages_api.MessagesApi(self.unauthorized_api_client) + cls.unauthorized_api_client = ApiClient() + cls.unauthorized_api_instance = messages_api.MessagesApi(cls.unauthorized_api_client) # Message Properties - self.application_id = BW_MESSAGING_APPLICATION_ID - self.to_number = [USER_NUMBER] - self.from_number = BW_NUMBER - self.text = 'python integration' - self.media = ['https://cdn2.thecatapi.com/images/MTY3ODIyMQ.jpg'] - self.tag = 'python integration tag' - self.priority = PriorityEnum("default") + cls.application_id = BW_MESSAGING_APPLICATION_ID + cls.to_number = [USER_NUMBER] + cls.from_number = BW_NUMBER + cls.text = 'python integration' + cls.media = ['https://cdn2.thecatapi.com/images/MTY3ODIyMQ.jpg'] + cls.tag = 'python integration tag' + cls.priority = PriorityEnum("default") # Message Request - self.message_request = MessageRequest( - application_id=self.application_id, - to=self.to_number, - var_from=self.from_number, - text=self.text, - media=self.media, - tag=self.tag, - priority=self.priority, + cls.message_request = MessageRequest( + application_id=cls.application_id, + to=cls.to_number, + var_from=cls.from_number, + text=cls.text, + media=cls.media, + tag=cls.tag, + priority=cls.priority, ) # Invalid Message Request - self.invalid_message_request = MessageRequest( - application_id=self.application_id, + cls.invalid_message_request = MessageRequest( + application_id=cls.application_id, to=['+invalid'], var_from='+invalid', text='', ) + @unittest.skip('skip') def test_create_message(self): response: ApiResponse = self.api_instance.create_message_with_http_info( self.account_id, diff --git a/test/smoke/test_mfa_api.py b/test/smoke/test_mfa_api.py index 176c08df..2bba8667 100644 --- a/test/smoke/test_mfa_api.py +++ b/test/smoke/test_mfa_api.py @@ -8,7 +8,7 @@ import logging from random import randint -import bandwidth +from bandwidth import ApiClient, Configuration from bandwidth.api import mfa_api from bandwidth.models.code_request import CodeRequest from bandwidth.models.messaging_code_response import MessagingCodeResponse @@ -25,15 +25,16 @@ class TestMultiFactorAuthentication(unittest.TestCase): """Multi-Factor Authentication API integration Test """ - def setUp(self) -> None: - configuration = bandwidth.Configuration( + @classmethod + def setUpClass(cls) -> None: + configuration = Configuration( username=BW_USERNAME, password=BW_PASSWORD ) - api_client = bandwidth.ApiClient(configuration) - self.api_instance = mfa_api.MFAApi(api_client) - self.account_id = BW_ACCOUNT_ID - self.messaging_code_request = CodeRequest( + api_client = ApiClient(configuration) + cls.api_instance = mfa_api.MFAApi(api_client) + cls.account_id = BW_ACCOUNT_ID + cls.messaging_code_request = CodeRequest( to=USER_NUMBER, var_from=BW_NUMBER, application_id=BW_MESSAGING_APPLICATION_ID, @@ -41,7 +42,7 @@ def setUp(self) -> None: message="Your temporary {NAME} {SCOPE} code is {CODE}", digits=6, ) - self.voice_code_request = CodeRequest( + cls.voice_code_request = CodeRequest( to=USER_NUMBER, var_from=BW_NUMBER, application_id=BW_VOICE_APPLICATION_ID, @@ -49,7 +50,7 @@ def setUp(self) -> None: message="Your temporary {NAME} {SCOPE} code is {CODE}", digits=6, ) - self.bad_code_request = CodeRequest( + cls.bad_code_request = CodeRequest( to=USER_NUMBER, var_from=BW_NUMBER, application_id='not_an_application_id', @@ -137,7 +138,7 @@ def testBadRequest(self) -> None: def testUnauthorizedRequest(self) -> None: """Validate an unauthorized (401) request """ - unauthorized_api_client = bandwidth.ApiClient() + unauthorized_api_client = ApiClient() unauthorized_api_instance = mfa_api.MFAApi(unauthorized_api_client) with self.assertRaises(UnauthorizedException) as context: @@ -150,12 +151,12 @@ def testUnauthorizedRequest(self) -> None: def testForbiddenRequest(self) -> None: """Validate a forbidden (403) request """ - configuration = bandwidth.Configuration( + configuration = Configuration( username=FORBIDDEN_USERNAME, # password=FORBIDDEN_PASSWORD, password='bad_password' ) - forbidden_api_client = bandwidth.ApiClient(configuration) + forbidden_api_client = ApiClient(configuration) forbidden_api_instance = mfa_api.MFAApi(forbidden_api_client) with self.assertRaises(ForbiddenException) as context: diff --git a/test/smoke/test_multi_channel_api.py b/test/smoke/test_multi_channel_api.py index e0c89d23..965e4ecc 100644 --- a/test/smoke/test_multi_channel_api.py +++ b/test/smoke/test_multi_channel_api.py @@ -24,7 +24,6 @@ from bandwidth.models.multi_channel_message_request import MultiChannelMessageRequest from bandwidth.models.multi_channel_message_channel_enum import MultiChannelMessageChannelEnum from bandwidth.models.multi_channel_channel_list_request_object import MultiChannelChannelListRequestObject -from bandwidth.models.multi_channel_channel_list_sms_response_object import MultiChannelChannelListSMSResponseObject from bandwidth.models.multi_channel_channel_list_sms_object import MultiChannelChannelListSMSObject from bandwidth.models.sms_message_content import SmsMessageContent from bandwidth.models.create_multi_channel_message_response import CreateMultiChannelMessageResponse @@ -45,15 +44,16 @@ class TestMultiChannelApi(unittest.TestCase): """MultiChannelApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( username=BW_USERNAME, password=BW_PASSWORD, ) api_client = ApiClient(configuration) - self.multi_channel_api_instance = MultiChannelApi(api_client) + cls.multi_channel_api_instance = MultiChannelApi(api_client) - self.expiration = datetime.now(ZoneInfo('America/New_York')) + timedelta(minutes=1) + cls.expiration = datetime.now(ZoneInfo('America/New_York')) + timedelta(minutes=1) def test_create_multi_channel_sms_message(self) -> None: """Test case for create_multi_channel_message diff --git a/test/smoke/test_phone_number_lookup_api.py b/test/smoke/test_phone_number_lookup_api.py index 118cbc57..bde0fe35 100644 --- a/test/smoke/test_phone_number_lookup_api.py +++ b/test/smoke/test_phone_number_lookup_api.py @@ -31,7 +31,6 @@ from bandwidth.models.completed_lookup_status_enum import CompletedLookupStatusEnum from bandwidth.models.lookup_result import LookupResult from bandwidth.models.line_type_enum import LineTypeEnum -from bandwidth.models.latest_message_delivery_status_enum import LatestMessageDeliveryStatusEnum from bandwidth.models.get_async_bulk_lookup_response import GetAsyncBulkLookupResponse from test.utils.env_variables import * @@ -39,18 +38,16 @@ class TestPhoneNumberLookupApi(unittest.TestCase): """PhoneNumberLookupApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) api_client = ApiClient(configuration) - self.api = PhoneNumberLookupApi(api_client) + cls.api = PhoneNumberLookupApi(api_client) - self.phone_numbers = [BW_NUMBER, USER_NUMBER] - - def tearDown(self) -> None: - pass + cls.phone_numbers = [BW_NUMBER, USER_NUMBER] def test_create_get_async_bulk_lookup(self) -> None: """Test case for create_async_bulk_lookup diff --git a/test/smoke/test_recordings_api.py b/test/smoke/test_recordings_api.py index b6bbbd9c..34cf8bd5 100644 --- a/test/smoke/test_recordings_api.py +++ b/test/smoke/test_recordings_api.py @@ -7,10 +7,9 @@ import time import json -import bandwidth from hamcrest import * -from bandwidth import ApiResponse +from bandwidth import ApiClient, ApiResponse, Configuration from bandwidth.api.recordings_api import RecordingsApi from bandwidth.configuration import Configuration from bandwidth.exceptions import ForbiddenException, NotFoundException, UnauthorizedException @@ -61,34 +60,36 @@ class TestRecordings(unittest.TestCase): Integration tests for the Recordings API. """ - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: """ Set up for our tests by creating the CallsApi and RecordingsApi instances for testing. """ - configuration = bandwidth.Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + configuration = Configuration( + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - api_client = bandwidth.ApiClient(configuration) + api_client = ApiClient(configuration) # Two Valid API Clients - self.calls_api_instance = CallsApi(api_client) - self.recordings_api_instance = RecordingsApi(api_client) + cls.calls_api_instance = CallsApi(api_client) + cls.recordings_api_instance = RecordingsApi(api_client) # Unauthorized Recordings API Client - self.unauthorized_recordings_api_instance = RecordingsApi( - api_client=bandwidth.ApiClient(Configuration.get_default_copy()) + cls.unauthorized_recordings_api_instance = RecordingsApi( + api_client=ApiClient(Configuration.get_default_copy()) ) # Rest client for interacting with Manteca - self.rest_client = RESTClientObject(Configuration.get_default_copy()) + cls.rest_client = RESTClientObject(Configuration.get_default_copy()) # Call ID Array - self.callIdArray = [] + cls.callIdArray = [] - def tearDown(self): - callCleanup(self) + @classmethod + def tearDownClass(cls): + callCleanup(cls) def create_and_validate_call(self, answer_url: str) -> Tuple[str, str]: """ diff --git a/test/smoke/test_statistics_api.py b/test/smoke/test_statistics_api.py index 2e99f0e7..b2b3db2a 100644 --- a/test/smoke/test_statistics_api.py +++ b/test/smoke/test_statistics_api.py @@ -15,14 +15,15 @@ class TestStatisticsApi(unittest.TestCase): """StatisticsApi integration Test """ - def setUp(self): + @classmethod + def setUpClass(cls): configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - self.api_client = ApiClient(configuration) - self.api_instance = StatisticsApi(self.api_client) - self.account_id = BW_ACCOUNT_ID + cls.api_client = ApiClient(configuration) + cls.api_instance = StatisticsApi(cls.api_client) + cls.account_id = BW_ACCOUNT_ID def test_get_statistics(self): api_response_with_http_info = self.api_instance.get_statistics_with_http_info(self.account_id) diff --git a/test/smoke/test_toll_free_verification_api.py b/test/smoke/test_toll_free_verification_api.py index 474b9204..dae3b75e 100644 --- a/test/smoke/test_toll_free_verification_api.py +++ b/test/smoke/test_toll_free_verification_api.py @@ -24,14 +24,15 @@ class TestTollFreeVerificationApi(unittest.TestCase): """TollFreeVerificationApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) - self.api_client = ApiClient(configuration) - self.api_instance = TollFreeVerificationApi(self.api_client) - self.account_id = BW_ACCOUNT_ID + cls.api_client = ApiClient(configuration) + cls.api_instance = TollFreeVerificationApi(cls.api_client) + cls.account_id = BW_ACCOUNT_ID def test_create_webhook_subscription(self) -> None: """Test case for create_webhook_subscription diff --git a/test/smoke/test_transcriptions_api.py b/test/smoke/test_transcriptions_api.py index 61c2aaa6..931c6c62 100644 --- a/test/smoke/test_transcriptions_api.py +++ b/test/smoke/test_transcriptions_api.py @@ -6,35 +6,36 @@ from hamcrest import * from bandwidth import ApiClient, Configuration -from bandwidth.rest import RESTClientObject, RESTResponse +from bandwidth.rest import RESTClientObject from bandwidth.api.transcriptions_api import TranscriptionsApi from bandwidth.api.calls_api import CallsApi -from bandwidth.models import CreateCall, CallTranscriptionMetadata, CallTranscriptionResponse, CallTranscription +from bandwidth.models import CreateCall, CreateCallResponse, CallTranscriptionMetadata, CallTranscriptionResponse, CallTranscription from test.utils.env_variables import * class TestTranscriptionsApi(unittest.TestCase): """TranscriptionsApi integration Test""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET ) api_client = ApiClient(configuration) - self.calls_api_instance = CallsApi(api_client) - self.transcriptions_api_instance = TranscriptionsApi(api_client) + cls.calls_api_instance = CallsApi(api_client) + cls.transcriptions_api_instance = TranscriptionsApi(api_client) # Rest client for interacting with Manteca - self.rest_client = RESTClientObject(Configuration.get_default_copy()) + cls.rest_client = RESTClientObject(Configuration.get_default_copy()) # Call ID Array - self.callIdArray = [] - self.SLEEP_TIME_SEC = 3 + cls.callIdArray = [] + cls.SLEEP_TIME_SEC = 3 # Transcription ID - self.transcription_id: str + cls.transcription_id: str def create_call_transcription(self) -> None: diff --git a/test/unit/api/test_calls_api.py b/test/unit/api/test_calls_api.py index 5770f8bd..ee0e4923 100644 --- a/test/unit/api/test_calls_api.py +++ b/test/unit/api/test_calls_api.py @@ -35,15 +35,16 @@ class TestCallsApi(unittest.TestCase): """CallsApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.calls_api_instance = CallsApi(api_client) + cls.calls_api_instance = CallsApi(api_client) def test_create_call(self) -> None: """Test case for create_call diff --git a/test/unit/api/test_conferences_api.py b/test/unit/api/test_conferences_api.py index d44a901f..b26f726f 100644 --- a/test/unit/api/test_conferences_api.py +++ b/test/unit/api/test_conferences_api.py @@ -32,15 +32,16 @@ class TestConferencesApi(unittest.TestCase): """ConferencesApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.conferences_api_instance = ConferencesApi(api_client) + cls.conferences_api_instance = ConferencesApi(api_client) def test_list_conferences(self) -> None: """Test case for list_conferences diff --git a/test/unit/api/test_phone_number_lookup_api.py b/test/unit/api/test_phone_number_lookup_api.py index a5b8ca68..c231d169 100644 --- a/test/unit/api/test_phone_number_lookup_api.py +++ b/test/unit/api/test_phone_number_lookup_api.py @@ -38,18 +38,16 @@ class TestPhoneNumberLookupApi(unittest.TestCase): """PhoneNumberLookupApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.api = PhoneNumberLookupApi(api_client) - - def tearDown(self) -> None: - pass + cls.api = PhoneNumberLookupApi(api_client) def test_create_async_bulk_lookup(self) -> None: """Test case for create_async_bulk_lookup diff --git a/test/unit/api/test_recordings_api.py b/test/unit/api/test_recordings_api.py index e203f974..78c66d41 100644 --- a/test/unit/api/test_recordings_api.py +++ b/test/unit/api/test_recordings_api.py @@ -34,18 +34,19 @@ class TestRecordingsApi(unittest.TestCase): """RecordingsApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.recordings_api_instance = RecordingsApi(api_client) + cls.recordings_api_instance = RecordingsApi(api_client) - self.call_id = "c-1234" - self.recording_id = "r-1234" + cls.call_id = "c-1234" + cls.recording_id = "r-1234" def test_update_call_recording_state(self) -> None: """Test case for update_call_recording_state diff --git a/test/unit/api/test_statistics_api.py b/test/unit/api/test_statistics_api.py index 42ab61dc..99ee94bd 100644 --- a/test/unit/api/test_statistics_api.py +++ b/test/unit/api/test_statistics_api.py @@ -25,15 +25,16 @@ class TestStatisticsApi(unittest.TestCase): """StatisticsApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.statistics_api_instance = StatisticsApi(api_client) + cls.statistics_api_instance = StatisticsApi(api_client) def test_get_statistics(self) -> None: """Test case for get_statistics diff --git a/test/unit/api/test_toll_free_verification_api.py b/test/unit/api/test_toll_free_verification_api.py index ad56c899..ad137c85 100644 --- a/test/unit/api/test_toll_free_verification_api.py +++ b/test/unit/api/test_toll_free_verification_api.py @@ -41,20 +41,21 @@ class TestTollFreeVerificationApi(unittest.TestCase): """TollFreeVerificationApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.tfv_api_instance = TollFreeVerificationApi(api_client) + cls.tfv_api_instance = TollFreeVerificationApi(api_client) - self.subscription_id = 'test-id-1234' - self.tf_phone_number = '+18005551234' + cls.subscription_id = 'test-id-1234' + cls.tf_phone_number = '+18005551234' - self.webhook_subscription_request_schema = WebhookSubscriptionRequestSchema( + cls.webhook_subscription_request_schema = WebhookSubscriptionRequestSchema( basic_authentication=TfvBasicAuthentication( username='username', password='password' @@ -63,7 +64,7 @@ def setUp(self) -> None: shared_secret_key='shared-secret-key' ) - self.verification = { + cls.verification = { 'businessAddress': Address( name='name', addr1='addr1', diff --git a/test/unit/api/test_transcriptions_api.py b/test/unit/api/test_transcriptions_api.py index 5f52b621..83a7150b 100644 --- a/test/unit/api/test_transcriptions_api.py +++ b/test/unit/api/test_transcriptions_api.py @@ -29,18 +29,19 @@ class TestTranscriptionsApi(unittest.TestCase): """TranscriptionsApi unit test stubs""" - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: configuration = Configuration( - username=BW_USERNAME, - password=BW_PASSWORD, + client_id=BW_CLIENT_ID, + client_secret=BW_CLIENT_SECRET, host='http://127.0.0.1:4010', ignore_operation_servers=True ) api_client = ApiClient(configuration) - self.transcriptions_api_instance = TranscriptionsApi(api_client) + cls.transcriptions_api_instance = TranscriptionsApi(api_client) - self.call_id = "c-abc123" - self.transcription_id = "t-abc123" + cls.call_id = "c-abc123" + cls.transcription_id = "t-abc123" def test_list_real_time_transcriptions(self) -> None: """Test case for list_real_time_transcriptions diff --git a/test/utils/env_variables.py b/test/utils/env_variables.py index d9a89c73..855834ae 100644 --- a/test/utils/env_variables.py +++ b/test/utils/env_variables.py @@ -3,6 +3,8 @@ try: BW_USERNAME = os.environ['BW_USERNAME'] BW_PASSWORD = os.environ['BW_PASSWORD'] + BW_CLIENT_ID = os.environ['BW_CLIENT_ID'] + BW_CLIENT_SECRET = os.environ['BW_CLIENT_SECRET'] BW_ACCOUNT_ID = os.environ['BW_ACCOUNT_ID'] BW_MESSAGING_APPLICATION_ID = os.environ['BW_MESSAGING_APPLICATION_ID'] BW_VOICE_APPLICATION_ID = os.environ['BW_VOICE_APPLICATION_ID']