Skip to content

Commit

Permalink
Fix json errors in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Nov 14, 2024
1 parent 7fd9282 commit 0d3e9ae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/posit/connect/_api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...


Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions src/posit/connect/oauth/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions src/posit/connect/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions src/posit/connect/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions tests/posit/connect/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 0d3e9ae

Please sign in to comment.