diff --git a/src/posit/connect/_api_call.py b/src/posit/connect/_api_call.py index 5d652a28..fb40352d 100644 --- a/src/posit/connect/_api_call.py +++ b/src/posit/connect/_api_call.py @@ -16,7 +16,7 @@ def _endpoint(self, *path) -> str: ... def _get_api(self, *path) -> Any: ... def _delete_api(self, *path) -> Any | None: ... def _patch_api(self, *path, json: Any | None) -> Any: ... - def _post_api(self, *path, json: Any | None) -> Any: ... + def _post_api(self, *path, json: Any | None) -> Any | None: ... def _put_api(self, *path, json: Any | None) -> Any: ... @@ -68,14 +68,18 @@ def _post_api( self: ApiCallProtocol, *path, json: Any | None, - ) -> Any: + ) -> Any | None: response = self._ctx.session.post(self._endpoint(*path), json=json) + if len(response.content) == 0: + return None return response.json() def _put_api( self: ApiCallProtocol, *path, json: Any | None, - ) -> Any: + ) -> Any | None: response = self._ctx.session.put(self._endpoint(*path), json=json) + if len(response.content) == 0: + return None return response.json() diff --git a/src/posit/connect/oauth/integrations.py b/src/posit/connect/oauth/integrations.py index 085eedd6..0aabc8ab 100644 --- a/src/posit/connect/oauth/integrations.py +++ b/src/posit/connect/oauth/integrations.py @@ -123,6 +123,7 @@ def create(self, **kwargs) -> Integration: Integration """ result = self._post_api(json=kwargs) + assert result is not None, "Integration creation failed" return Integration(self._ctx, **result) def find(self) -> List[Integration]: diff --git a/src/posit/connect/permissions.py b/src/posit/connect/permissions.py index 62d428a7..e873d66d 100644 --- a/src/posit/connect/permissions.py +++ b/src/posit/connect/permissions.py @@ -66,6 +66,7 @@ def update(self, *args, **kwargs) -> Permission: body.update(dict(*args)) body.update(**kwargs) result = self._put_api(json=body) + assert result is not None, "Permission update failed." return Permission(self._ctx, **result) diff --git a/src/posit/connect/users.py b/src/posit/connect/users.py index 90f97276..94b0ffb6 100644 --- a/src/posit/connect/users.py +++ b/src/posit/connect/users.py @@ -232,6 +232,7 @@ def update( >>> user.update(first_name="Jane", last_name="Smith") """ result = self._put_api(json=kwargs) + assert result is not None, "User update failed." return User(self._ctx, **result) @@ -315,6 +316,7 @@ def create(self, **attributes: Unpack[_CreateUser]) -> User: """ # todo - use the 'context' module to inspect the 'authentication' object and route to POST (local) or PUT (remote). result = self._post_api(json=attributes) + assert result is not None, "User creation failed." return User(self._ctx, **result) class _FindUser(TypedDict): diff --git a/tests/posit/connect/test_users.py b/tests/posit/connect/test_users.py index 4905ca74..a2c55727 100644 --- a/tests/posit/connect/test_users.py +++ b/tests/posit/connect/test_users.py @@ -67,7 +67,6 @@ def test_lock(self): responses.post( "https://connect.example/__api__/v1/users/a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6/lock", match=[responses.matchers.json_params_matcher({"locked": True})], - json={}, ) locked_user = user.lock() assert locked_user["locked"] @@ -89,7 +88,6 @@ def test_lock_self_true(self): responses.post( "https://connect.example/__api__/v1/users/20a79ce3-6e87-4522-9faf-be24228800a4/lock", match=[responses.matchers.json_params_matcher({"locked": True})], - json={}, ) unlocked_user = user.lock(force=True) assert unlocked_user["locked"] @@ -131,7 +129,6 @@ def test_unlock(self): responses.post( "https://connect.example/__api__/v1/users/20a79ce3-6e87-4522-9faf-be24228800a4/lock", match=[responses.matchers.json_params_matcher({"locked": False})], - json={}, ) unlocked_user = user.unlock() assert not unlocked_user["locked"]