Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add unit tests for fetch method (box/box-codegen#461) #99

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading