Skip to content

Commit e507d3f

Browse files
authored
fix: remove all warnings from attribute access (#323)
Removes all warning messages created by direct attribute access.
1 parent 1dacc4d commit e507d3f

File tree

18 files changed

+84
-304
lines changed

18 files changed

+84
-304
lines changed

integration/tests/posit/connect/oauth/test_associations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def test_find_update_by_content(self):
8787
updated_associations = self.content.oauth.associations.find()
8888
assert len(updated_associations) == 1
8989
assert updated_associations[0]["app_guid"] == self.content["guid"]
90-
assert updated_associations[0]["oauth_integration_guid"] == self.another_integration.guid
90+
assert (
91+
updated_associations[0]["oauth_integration_guid"] == self.another_integration["guid"]
92+
)
9193

9294
# unset content association
9395
self.content.oauth.associations.delete()

integration/tests/posit/connect/oauth/test_integrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_create_update_delete(self):
8888

8989
created.update(name="updated integration name")
9090
updated = self.client.oauth.integrations.get(integration["guid"])
91-
assert updated.name == "updated integration name"
91+
assert updated["name"] == "updated integration name"
9292

9393
# delete the new integration
9494

integration/tests/posit/connect/test_groups.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33

44
class TestGroups:
5+
@classmethod
56
def setup_class(cls):
67
cls.client = connect.Client()
78
cls.item = cls.client.groups.create(name="Friends")
89

10+
@classmethod
911
def teardown_class(cls):
1012
cls.item.delete()
1113
assert cls.client.groups.count() == 0
@@ -14,7 +16,7 @@ def test_count(self):
1416
assert self.client.groups.count() == 1
1517

1618
def test_get(self):
17-
assert self.client.groups.get(self.item.guid)
19+
assert self.client.groups.get(self.item["guid"])
1820

1921
def test_find(self):
2022
assert self.client.groups.find() == [self.item]

src/posit/connect/bundles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def metadata(self) -> BundleMetadata:
1919

2020
def delete(self) -> None:
2121
"""Delete the bundle."""
22-
path = f"v1/content/{self.content_guid}/bundles/{self.id}"
22+
path = f"v1/content/{self['content_guid']}/bundles/{self['id']}"
2323
url = self.params.url + path
2424
self.params.session.delete(url)
2525

@@ -39,9 +39,9 @@ def deploy(self) -> tasks.Task:
3939
>>> task.wait_for()
4040
None
4141
"""
42-
path = f"v1/content/{self.content_guid}/deploy"
42+
path = f"v1/content/{self['content_guid']}/deploy"
4343
url = self.params.url + path
44-
response = self.params.session.post(url, json={"bundle_id": self.id})
44+
response = self.params.session.post(url, json={"bundle_id": self["id"]})
4545
result = response.json()
4646
ts = tasks.Tasks(self.params)
4747
return ts.get(result["task_id"])
@@ -77,7 +77,7 @@ def download(self, output: io.BufferedWriter | str) -> None:
7777
f"download() expected argument type 'io.BufferedWriter` or 'str', but got '{type(output).__name__}'",
7878
)
7979

80-
path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
80+
path = f"v1/content/{self['content_guid']}/bundles/{self['id']}/download"
8181
url = self.params.url + path
8282
response = self.params.session.get(url, stream=True)
8383
if isinstance(output, io.BufferedWriter):

src/posit/connect/content.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def oauth(self) -> ContentItemOAuth:
5555

5656
def delete(self) -> None:
5757
"""Delete the content item."""
58-
path = f"v1/content/{self.guid}"
58+
path = f"v1/content/{self['guid']}"
5959
url = self.params.url + path
6060
self.params.session.delete(url)
6161

@@ -75,7 +75,7 @@ def deploy(self) -> tasks.Task:
7575
>>> task.wait_for()
7676
None
7777
"""
78-
path = f"v1/content/{self.guid}/deploy"
78+
path = f"v1/content/{self['guid']}/deploy"
7979
url = self.params.url + path
8080
response = self.params.session.post(url, json={"bundle_id": None})
8181
result = response.json()
@@ -99,7 +99,7 @@ def render(self) -> Task:
9999

100100
if self.is_rendered:
101101
variants = self._variants.find()
102-
variants = [variant for variant in variants if variant.is_default]
102+
variants = [variant for variant in variants if variant["is_default"]]
103103
if len(variants) != 1:
104104
raise RuntimeError(
105105
f"Found {len(variants)} default variants. Expected 1. Without a single default variant, the content cannot be refreshed. This is indicative of a corrupted state.",
@@ -108,7 +108,7 @@ def render(self) -> Task:
108108
return variant.render()
109109
else:
110110
raise ValueError(
111-
f"Render not supported for this application mode: {self.app_mode}. Did you need to use the 'restart()' method instead? Note that some application modes do not support 'render()' or 'restart()'.",
111+
f"Render not supported for this application mode: {self['app_mode']}. Did you need to use the 'restart()' method instead? Note that some application modes do not support 'render()' or 'restart()'.",
112112
)
113113

114114
def restart(self) -> None:
@@ -132,12 +132,12 @@ def restart(self) -> None:
132132
self.environment_variables.create(key, unix_epoch_in_seconds)
133133
self.environment_variables.delete(key)
134134
# GET via the base Connect URL to force create a new worker thread.
135-
url = posixpath.join(dirname(self.params.url), f"content/{self.guid}")
135+
url = posixpath.join(dirname(self.params.url), f"content/{self['guid']}")
136136
self.params.session.get(url)
137137
return None
138138
else:
139139
raise ValueError(
140-
f"Restart not supported for this application mode: {self.app_mode}. Did you need to use the 'render()' method instead? Note that some application modes do not support 'render()' or 'restart()'.",
140+
f"Restart not supported for this application mode: {self['app_mode']}. Did you need to use the 'render()' method instead? Note that some application modes do not support 'render()' or 'restart()'.",
141141
)
142142

143143
@overload
@@ -276,7 +276,7 @@ def _variants(self) -> Variants:
276276

277277
@property
278278
def is_interactive(self) -> bool:
279-
return self.app_mode in {
279+
return self["app_mode"] in {
280280
"api",
281281
"jupyter-voila",
282282
"python-api",
@@ -293,7 +293,7 @@ def is_interactive(self) -> bool:
293293

294294
@property
295295
def is_rendered(self) -> bool:
296-
return self.app_mode in {
296+
return self["app_mode"] in {
297297
"rmd-static",
298298
"jupyter-static",
299299
"quarto-static",

src/posit/connect/groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class Group(Resource):
1515
def delete(self) -> None:
1616
"""Delete the group."""
17-
path = f"v1/groups/{self.guid}"
17+
path = f"v1/groups/{self['guid']}"
1818
url = self.params.url + path
1919
self.params.session.delete(url)
2020

src/posit/connect/permissions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Permission(Resource):
1313
def delete(self) -> None:
1414
"""Delete the permission."""
15-
path = f"v1/content/{self.content_guid}/permissions/{self.id}"
15+
path = f"v1/content/{self['content_guid']}/permissions/{self['id']}"
1616
url = self.params.url + path
1717
self.params.session.delete(url)
1818

@@ -33,13 +33,13 @@ def update(self, *args, **kwargs) -> None:
3333
def update(self, *args, **kwargs) -> None:
3434
"""Update the permission."""
3535
body = {
36-
"principal_guid": self.principal_guid,
37-
"principal_type": self.principal_type,
38-
"role": self.role,
36+
"principal_guid": self.get("principal_guid"),
37+
"principal_type": self.get("principal_type"),
38+
"role": self.get("role"),
3939
}
4040
body.update(dict(*args))
4141
body.update(**kwargs)
42-
path = f"v1/content/{self.content_guid}/permissions/{self.id}"
42+
path = f"v1/content/{self['content_guid']}/permissions/{self['id']}"
4343
url = self.params.url + path
4444
response = self.params.session.put(
4545
url,

src/posit/connect/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def update(self, *args, **kwargs) -> None:
9090
]
9191
"""
9292
params = dict(*args, **kwargs)
93-
path = f"v1/tasks/{self.id}"
93+
path = f"v1/tasks/{self['id']}"
9494
url = self.params.url + path
9595
response = self.params.session.get(url, params=kwargs)
9696
result = response.json()

src/posit/connect/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def lock(self, *, force: bool = False):
4343
>>> user.lock(force=True)
4444
"""
4545
_me = me.get(self.params)
46-
if _me.guid == self["guid"] and not force:
46+
if _me["guid"] == self["guid"] and not force:
4747
raise RuntimeError(
4848
"You cannot lock your own account. Set force=True to override this behavior.",
4949
)

tests/posit/connect/oauth/test_integrations.py

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,11 @@
1-
from unittest import mock
2-
31
import responses
42
from responses import matchers
53

64
from posit.connect.client import Client
7-
from posit.connect.oauth.associations import IntegrationAssociations
8-
from posit.connect.oauth.integrations import Integration
95

106
from ..api import load_mock # type: ignore
117

128

13-
class TestIntegrationAttributes:
14-
@classmethod
15-
def setup_class(cls):
16-
guid = "22644575-a27b-4118-ad06-e24459b05126"
17-
fake_item = load_mock(f"v1/oauth/integrations/{guid}.json")
18-
cls.item = Integration(mock.Mock(), **fake_item)
19-
20-
def test_id(self):
21-
assert self.item.id == "3"
22-
23-
def test_guid(self):
24-
assert self.item.guid == "22644575-a27b-4118-ad06-e24459b05126"
25-
26-
def test_name(self):
27-
assert self.item.name == "keycloak integration"
28-
29-
def test_description(self):
30-
assert self.item.description == "integration description"
31-
32-
def test_template(self):
33-
assert self.item.template == "custom"
34-
35-
def test_config(self):
36-
assert self.item.config["auth_mode"] == "Confidential"
37-
assert (
38-
self.item.config["authorization_uri"]
39-
== "http://keycloak:8080/realms/rsconnect/protocol/openid-connect/auth"
40-
)
41-
assert self.item.config["client_id"] == "rsconnect-oidc"
42-
assert self.item.config["scopes"] == "email"
43-
assert self.item.config["token_endpoint_auth_method"] == "client_secret_basic"
44-
assert (
45-
self.item.config["token_uri"]
46-
== "http://keycloak:8080/realms/rsconnect/protocol/openid-connect/token"
47-
)
48-
49-
def test_created_time(self):
50-
assert self.item.created_time == "2024-07-16T19:28:05Z"
51-
52-
def test_updated_time(self):
53-
assert self.item.updated_time == "2024-07-17T19:28:05Z"
54-
55-
def test_associations(self):
56-
assert isinstance(self.item.associations, IntegrationAssociations)
57-
58-
599
class TestIntegrationDelete:
6010
@responses.activate
6111
def test(self):
@@ -96,7 +46,7 @@ def test(self):
9646
c = Client("https://connect.example", "12345")
9747
c.ctx.version = None
9848
integration = c.oauth.integrations.get(guid)
99-
assert integration.guid == guid
49+
assert integration["guid"] == guid
10050

10151
new_name = "New Name"
10252

@@ -111,7 +61,7 @@ def test(self):
11161

11262
integration.update(name=new_name)
11363
assert mock_update.call_count == 1
114-
assert integration.name == new_name
64+
assert integration["name"] == new_name
11565

11666

11767
class TestIntegrationsCreate:
@@ -151,10 +101,10 @@ def test(self):
151101

152102
# assert
153103
assert mock_create.call_count == 1
154-
assert integration.name == fake_integration["name"]
155-
assert integration.description == fake_integration["description"]
156-
assert integration.template == fake_integration["template"]
157-
assert integration.config == fake_integration["config"]
104+
assert integration["name"] == fake_integration["name"]
105+
assert integration["description"] == fake_integration["description"]
106+
assert integration["template"] == fake_integration["template"]
107+
assert integration["config"] == fake_integration["config"]
158108

159109

160110
class TestIntegrationsFind:
@@ -176,8 +126,8 @@ def test(self):
176126
# assert
177127
assert mock_get.call_count == 1
178128
assert len(integrations) == 2
179-
assert integrations[0].id == "3"
180-
assert integrations[1].id == "4"
129+
assert integrations[0]["id"] == "3"
130+
assert integrations[1]["id"] == "4"
181131

182132

183133
class TestIntegrationsGet:
@@ -197,4 +147,4 @@ def test(self):
197147
integration = c.oauth.integrations.get(guid)
198148

199149
assert mock_get.call_count == 1
200-
assert integration.guid == guid
150+
assert integration["guid"] == guid

0 commit comments

Comments
 (0)