Skip to content

Commit 7e6e8ad

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

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/posit/connect/oauth/associations.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from functools import partial
66

7-
from typing_extensions import TYPE_CHECKING, List, Optional
7+
from typing_extensions import TYPE_CHECKING, List, Optional, overload
88

99
from ..resources import BaseResource, Resources, _matches_exact, _matches_pattern
1010

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

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

134159
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)