Skip to content

Commit 1ae8daa

Browse files
authored
Add ApplicationNotAllowedException and update related tests (#1963)
This pull request introduces a new exception, `ApplicationNotAllowedException`, to handle cases where access to a setup is denied for a specific application. It also refactors the exception hierarchy to group related access-denied errors under a new base class, `ResourceAccessDeniedException`. Additionally, tests and fixtures are updated to cover the new exception. Exception hierarchy improvements: * Introduced a new base exception, `ResourceAccessDeniedException`, and updated `NotAuthenticatedException`, `MissingAuthorizationTokenException`, and `AccessDeniedToGatewayException` to inherit from it for better error categorization. [[1]](diffhunk://#diff-0dfa3f77b5b6d197b7ad275059dc5023e18e69b0cb889da6c6de67732257ddeeL32-R36) [[2]](diffhunk://#diff-0dfa3f77b5b6d197b7ad275059dc5023e18e69b0cb889da6c6de67732257ddeeL64-R68) [[3]](diffhunk://#diff-0dfa3f77b5b6d197b7ad275059dc5023e18e69b0cb889da6c6de67732257ddeeL100-R111) New exception for application access denial: * Added `ApplicationNotAllowedException` (inheriting from `ResourceAccessDeniedException`) for handling cases when the API returns a "RESOURCE_ACCESS_DENIED" error with the message "Your setup cannot be accessed through this application". [[1]](diffhunk://#diff-0dfa3f77b5b6d197b7ad275059dc5023e18e69b0cb889da6c6de67732257ddeeL100-R111) [[2]](diffhunk://#diff-11513003e65960c0b1a4bccb3c6bf2b7dea08c03923a8e53b8dea1a05f213aa2R64) [[3]](diffhunk://#diff-11513003e65960c0b1a4bccb3c6bf2b7dea08c03923a8e53b8dea1a05f213aa2R975-R978) Test and fixture updates: * Added a new test fixture (`cloud/resource-access-denied.json`) and updated tests to verify that `ApplicationNotAllowedException` is raised for the appropriate error response. [[1]](diffhunk://#diff-0f9b9c678d1ade309735bdfcbc0d9ad8c6425b6d4d58d3ed017e5a8a9f215928R1-R4) [[2]](diffhunk://#diff-0d92063e88430a02df61616c5f16b148b64ac4539d9cb9b8d883d5a23351b110R330-R334)
1 parent 8d375f4 commit 1ae8daa

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

pyoverkiz/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from pyoverkiz.exceptions import (
4545
AccessDeniedToGatewayException,
4646
ActionGroupSetupNotFoundException,
47+
ApplicationNotAllowedException,
4748
BadCredentialsException,
4849
CozyTouchBadCredentialsException,
4950
CozyTouchServiceException,
@@ -971,6 +972,10 @@ async def check_response(response: ClientResponse) -> None:
971972
if "Access denied to gateway" in message:
972973
raise AccessDeniedToGatewayException(message)
973974

975+
# {"errorCode": "RESOURCE_ACCESS_DENIED", "error": "Your setup cannot be accessed through this application"}
976+
if message == "Your setup cannot be accessed through this application":
977+
raise ApplicationNotAllowedException(message)
978+
974979
# Undefined Overkiz exception
975980
raise OverkizException(result)
976981

pyoverkiz/exceptions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class NoSuchResourceException(BaseOverkizException):
2929
"""Raised when an invalid API call is made."""
3030

3131

32-
class NotAuthenticatedException(BaseOverkizException):
32+
class ResourceAccessDeniedException(BaseOverkizException):
33+
"""Raised when the API returns a RESOURCE_ACCESS_DENIED error."""
34+
35+
36+
class NotAuthenticatedException(ResourceAccessDeniedException):
3337
"""Raised when the user is not authenticated."""
3438

3539

@@ -61,7 +65,7 @@ class MissingAPIKeyException(BaseOverkizException):
6165
"""Raised when the API key is missing."""
6266

6367

64-
class MissingAuthorizationTokenException(BaseOverkizException):
68+
class MissingAuthorizationTokenException(ResourceAccessDeniedException):
6569
"""Raised when the authorization token is missing."""
6670

6771

@@ -97,10 +101,14 @@ class UnknownObjectException(BaseOverkizException):
97101
"""Raised when an unknown object is provided."""
98102

99103

100-
class AccessDeniedToGatewayException(BaseOverkizException):
104+
class AccessDeniedToGatewayException(ResourceAccessDeniedException):
101105
"""Raised when access is denied to the gateway. This often happens when the user is not the owner of the gateway."""
102106

103107

108+
class ApplicationNotAllowedException(ResourceAccessDeniedException):
109+
"""Raised when the setup cannot be accessed through the application."""
110+
111+
104112
# Nexity
105113
class NexityBadCredentialsException(BadCredentialsException):
106114
"""Raised when invalid credentials are provided to Nexity authentication API."""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"errorCode": "RESOURCE_ACCESS_DENIED",
3+
"error": "Your setup cannot be accessed through this application"
4+
}

tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ async def test_get_diagnostic_data(self, client: OverkizClient, fixture_name: st
327327
exceptions.AccessDeniedToGatewayException,
328328
400,
329329
),
330+
(
331+
"cloud/application-not-allowed.json",
332+
exceptions.ApplicationNotAllowedException,
333+
400,
334+
),
330335
(
331336
"cloud/bad-credentials.json",
332337
exceptions.BadCredentialsException,

0 commit comments

Comments
 (0)