Skip to content

Commit c88dd7d

Browse files
committed
fix: accept single integration guid on association update
1 parent ac08b38 commit c88dd7d

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/posit/connect/oauth/associations.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from functools import partial
6+
from typing import overload
67

78
from typing_extensions import TYPE_CHECKING, List, Optional
89

@@ -127,8 +128,33 @@ def delete(self) -> None:
127128
path = f"v1/content/{self.content_guid}/oauth/integrations/associations"
128129
self._ctx.client.put(path, json=data)
129130

130-
def update(self, integration_guids: list[str]) -> None:
131+
@overload
132+
def update(self, integration_guid: str) -> None:
133+
"""Set a single integration association.
134+
135+
Parameters
136+
----------
137+
integration_guid : str
138+
The unique identifier of the integration.
139+
"""
140+
141+
@overload
142+
def update(self, integration_guid: list[str]) -> None:
143+
"""Set multiple integration associations.
144+
145+
Parameters
146+
----------
147+
integration_guids : list[str]
148+
A list of unique identifiers of the integrations.
149+
"""
150+
151+
def update(self, integration_guid: str | list[str]) -> None:
131152
"""Set integration associations."""
153+
if isinstance(integration_guid, str):
154+
integration_guids = [integration_guid]
155+
else:
156+
integration_guids = integration_guid
157+
132158
data = [{"oauth_integration_guid": guid} for guid in integration_guids]
133159

134160
path = f"v1/content/{self.content_guid}/oauth/integrations/associations"

tests/posit/connect/oauth/test_associations.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,36 @@ def test(self):
138138
assert mock_put.call_count == 1
139139
assert mock_get_content.call_count == 1
140140

141+
@responses.activate
142+
def test_overload_str_type(self):
143+
guid = "f2f37341-e21d-3d80-c698-a935ad614066"
144+
145+
# behavior
146+
mock_get_content = responses.get(
147+
f"https://connect.example/__api__/v1/content/{guid}",
148+
json=load_mock(f"v1/content/{guid}.json"),
149+
)
150+
151+
new_integration_guid = "00000000-a27b-4118-ad06-e24459b05126"
152+
153+
mock_put = responses.put(
154+
f"https://connect.example/__api__/v1/content/{guid}/oauth/integrations/associations",
155+
json=[
156+
{"oauth_integration_guid": new_integration_guid},
157+
],
158+
)
159+
160+
# setup
161+
c = Client("https://connect.example", "12345")
162+
c._ctx.version = None
163+
164+
# invoke
165+
c.content.get(guid).oauth.associations.update(new_integration_guid)
166+
167+
# assert
168+
assert mock_put.call_count == 1
169+
assert mock_get_content.call_count == 1
170+
141171

142172
class TestContentAssociationsDelete:
143173
@responses.activate

0 commit comments

Comments
 (0)