Skip to content

Commit

Permalink
test: Add unit tests for fetch method (box/box-codegen#461) (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
box-sdk-build authored Mar 22, 2024
1 parent 5a4d1eb commit bb8b3eb
Show file tree
Hide file tree
Showing 4 changed files with 718 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "88dd8b0", "specHash": "d50ab5f", "version": "0.6.2" }
{ "engineHash": "3391dd6", "specHash": "d50ab5f", "version": "0.6.2" }
11 changes: 6 additions & 5 deletions box_sdk_gen/box/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pprint
from datetime import datetime
from typing import Any, Optional

from typing import Dict
Expand All @@ -8,14 +9,14 @@ class BoxSDKError(Exception):
def __init__(
self,
message: str,
timestamp: str = None,
timestamp: Optional[datetime] = None,
error: Optional[Exception] = None,
name: Optional[str] = None,
name: Optional[str] = 'BoxSDKError',
**kwargs,
):
super().__init__(message)
self.message = message
self.timestamp = timestamp
self.timestamp = timestamp if timestamp is not None else datetime.now()
self.error = error
self.name = name

Expand Down Expand Up @@ -110,9 +111,9 @@ def __init__(
request_info: RequestInfo,
response_info: ResponseInfo,
message: str,
timestamp: str,
timestamp: Optional[datetime] = None,
error: Optional[str] = None,
name: Optional[str] = None,
name: Optional[str] = 'BoxAPIError',
**kwargs,
):
super().__init__(
Expand Down
7 changes: 2 additions & 5 deletions box_sdk_gen/networking/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def fetch(url: str, options: FetchOptions) -> FetchResponse:
)

if (
not response.reauthentication_needed
not (response.reauthentication_needed and options.auth)
and network_response.status_code != 429
and network_response.status_code < 500
):
Expand Down Expand Up @@ -261,9 +261,7 @@ def __make_request(request: APIRequest, session: Session) -> APIResponse:
def __raise_on_unsuccessful_request(request: APIRequest, response: APIResponse) -> None:
if response.raised_exception:
raise BoxSDKError(
message=str(response.raised_exception),
timestamp=str(datetime.now()),
error=response.raised_exception,
message=str(response.raised_exception), error=response.raised_exception
)

network_response = response.network_response
Expand All @@ -275,7 +273,6 @@ def __raise_on_unsuccessful_request(request: APIRequest, response: APIResponse)

raise BoxAPIError(
message=f'{network_response.status_code} {response_json.get("message", "")}; Request ID: {response_json.get("request_id", "")}',
timestamp=str(datetime.now()),
request_info=RequestInfo(
method=request.method,
url=request.url,
Expand Down
Loading

0 comments on commit bb8b3eb

Please sign in to comment.