Skip to content

Commit

Permalink
added error case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Jan 31, 2024
1 parent 6dc8903 commit 7852634
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
9 changes: 3 additions & 6 deletions http_client/src/http_client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions http_client/tests/data/400.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: Bad Request
12 changes: 12 additions & 0 deletions http_client/tests/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 5 additions & 23 deletions number_insight_v2/src/number_insight_v2/number_insight_v2.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion vonage/src/vonage/vonage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7852634

Please sign in to comment.