From 468903ed038994040d78ada6141bde5f59cc777b Mon Sep 17 00:00:00 2001 From: ardevd Date: Fri, 2 May 2025 21:22:08 +0200 Subject: [PATCH 1/3] refactor: moved HTTPError into errors.py Makes more sense to move all custom error classes into errors.py --- dimo/errors.py | 9 +++++++++ dimo/request.py | 10 +--------- tests/test_request.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dimo/errors.py b/dimo/errors.py index 9e427c7..5976b2b 100644 --- a/dimo/errors.py +++ b/dimo/errors.py @@ -30,3 +30,12 @@ def check_optional_type(param_name: str, value: Any, expected_type: Union[Type, class DimoValueError(DimoError): pass + + +class HTTPError(Exception): + """Http error wrapper with status code and (optional) response body""" + + def __init__(self, status: int, message: str, body: Any = None): + super().__init__(f"HTTP {status}: {message}") + self.status = status + self.body = body diff --git a/dimo/request.py b/dimo/request.py index 1bc6ad0..dd12a0c 100644 --- a/dimo/request.py +++ b/dimo/request.py @@ -1,15 +1,7 @@ import json from typing import Any from requests import Session, RequestException - - -class HTTPError(Exception): - """Http error wrapper with status code and (optional) response body""" - - def __init__(self, status: int, message: str, body: Any = None): - super().__init__(f"HTTP {status}: {message}") - self.status = status - self.body = body +from errors import HTTPError class Request: diff --git a/tests/test_request.py b/tests/test_request.py index b99c20e..4a2ef9f 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -3,7 +3,7 @@ from requests import RequestException from unittest.mock import Mock -from dimo.request import Request, HTTPError +from dimo.errors import Request, HTTPError class DummyResponse: From d7f35525da97bc86158546b10f6fba9aad4e6a9b Mon Sep 17 00:00:00 2001 From: ardevd Date: Mon, 12 May 2025 13:43:19 +0200 Subject: [PATCH 2/3] fixed imports --- dimo/request.py | 2 +- tests/test_request.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dimo/request.py b/dimo/request.py index dd12a0c..7456bb4 100644 --- a/dimo/request.py +++ b/dimo/request.py @@ -1,7 +1,7 @@ import json from typing import Any from requests import Session, RequestException -from errors import HTTPError +from .errors import HTTPError class Request: diff --git a/tests/test_request.py b/tests/test_request.py index 4a2ef9f..d329900 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -3,7 +3,8 @@ from requests import RequestException from unittest.mock import Mock -from dimo.errors import Request, HTTPError +from dimo.errors import HTTPError +from dimo.request import Request class DummyResponse: From 8536fd7e1945d7b54493ae1dc5c0014f72581c3d Mon Sep 17 00:00:00 2001 From: ardevd Date: Mon, 12 May 2025 13:46:23 +0200 Subject: [PATCH 3/3] removed unused imports --- dimo/dimo.py | 9 ++++++--- dimo/request.py | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dimo/dimo.py b/dimo/dimo.py index df77909..0d5d0fe 100644 --- a/dimo/dimo.py +++ b/dimo/dimo.py @@ -1,4 +1,3 @@ -from typing_extensions import Optional from requests import Session from .api.attestation import Attestation @@ -21,7 +20,9 @@ class DIMO: - def __init__(self, env: str = "Production", session: Optional[Session] = None) -> None: + def __init__( + self, env: str = "Production", session: Optional[Session] = None + ) -> None: self.env = env # Assert valid environment specified @@ -32,7 +33,9 @@ def __init__(self, env: str = "Production", session: Optional[Session] = None) - self._client_id: Optional[str] = None self._services: Dict[str, Any] = {} - self.session = session or Session() # Use the provided session or create a new one + self.session = ( + session or Session() + ) # Use the provided session or create a new one # Creates a full path for endpoints combining DIMO service, specific endpoint, and optional params def _get_full_path(self, service: str, path: str, params=None) -> str: diff --git a/dimo/request.py b/dimo/request.py index 7456bb4..ff46527 100644 --- a/dimo/request.py +++ b/dimo/request.py @@ -1,5 +1,4 @@ import json -from typing import Any from requests import Session, RequestException from .errors import HTTPError