diff --git a/http_client/src/http_client/auth.py b/http_client/src/http_client/auth.py index f7b18da7..fd86da4f 100644 --- a/http_client/src/http_client/auth.py +++ b/http_client/src/http_client/auth.py @@ -60,12 +60,9 @@ def generate_application_jwt(self): try: return self._jwt_client.generate_application_jwt(self._jwt_claims) except AttributeError as err: - if '_jwt_client' in str(err): - raise JWTGenerationError( - 'JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".' - ) - else: - raise err + raise JWTGenerationError( + 'JWT generation failed. Check that you passed in valid values for "application_id" and "private_key".' + ) from err def create_basic_auth_string(self): hash = b64encode(f'{self.api_key}:{self.api_secret}'.encode('utf-8')).decode( diff --git a/http_client/tests/data/400.txt b/http_client/tests/data/400.txt new file mode 100644 index 00000000..4ff18741 --- /dev/null +++ b/http_client/tests/data/400.txt @@ -0,0 +1 @@ +Error: Bad Request \ No newline at end of file diff --git a/http_client/tests/test_http_client.py b/http_client/tests/test_http_client.py index 969f5379..9d9a7338 100644 --- a/http_client/tests/test_http_client.py +++ b/http_client/tests/test_http_client.py @@ -117,6 +117,18 @@ def test_http_response_general_error(): assert '400 response from https://example.com/get_json.' in err.message +@responses.activate +def test_http_response_general_text_error(): + build_response(path, 'GET', 'https://example.com/get', '400.txt', 400, 'text/plain') + + client = HttpClient(Auth()) + try: + client.get(host='example.com', request_path='/get') + except HttpRequestError as err: + assert err.response.text == 'Error: Bad Request' + assert '400 response from https://example.com/get.' in err.message + + @responses.activate def test_authentication_error(): build_response(path, 'GET', 'https://example.com/get_json', '401.json', 401) diff --git a/number_insight_v2/src/number_insight_v2/number_insight_v2.py b/number_insight_v2/src/number_insight_v2/number_insight_v2.py index ff3d76d5..84199b97 100644 --- a/number_insight_v2/src/number_insight_v2/number_insight_v2.py +++ b/number_insight_v2/src/number_insight_v2/number_insight_v2.py @@ -1,26 +1,8 @@ -import requests -from package1.module1 import say_hello +from http_client.http_client import HttpClient -def say_goodbye(): - """Says goodbye to the caller.""" - print("goodbye") - return 0 +class NI2: + """Number Insight API V2.""" - -def say_hello_then_goodbye(): - """Says hello then goodbye to the caller using say_hello from another package.""" - say_hello() - print("goodbye") - return 0 - - -def make_http_request(): - """Makes an HTTP request.""" - response = requests.get("https://example.com") - print(response) - return response - - -say_hello_then_goodbye() -make_http_request() + def __init__(self, http_client: HttpClient) -> None: + self._http_client = http_client diff --git a/vonage/src/vonage/vonage.py b/vonage/src/vonage/vonage.py index 10a3a81d..7538d36a 100644 --- a/vonage/src/vonage/vonage.py +++ b/vonage/src/vonage/vonage.py @@ -2,6 +2,8 @@ from http_client.http_client import HttpClient +from number_insight_v2.number_insight_v2 import NI2 + class Vonage: """Main Server SDK class for using Vonage APIs. @@ -33,7 +35,7 @@ def __init__( self._http_client = HttpClient(self._auth, http_client_options) - # self.ni2 = NI2(self._http_client) + self.ni2 = NI2(self._http_client) @property def auth(self):