Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: drop support field access by attribute. #271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_count(self):
assert self.client.content.count() == 1

def test_get(self):
assert self.client.content.get(self.content.guid) == self.content
assert self.client.content.get(self.content["guid"]) == self.content

def test_find(self):
assert self.client.content.find()
Expand All @@ -34,12 +34,12 @@ def test_find_one(self):
def test_content_item_owner(self):
item = self.client.content.find_one(include=None)
owner = item.owner
assert owner.guid == self.client.me.guid
assert owner["guid"] == self.client.me["guid"]

def test_content_item_owner_from_include(self):
item = self.client.content.find_one(include="owner")
owner = item.owner
assert owner.guid == self.client.me.guid
assert owner["guid"] == self.client.me["guid"]

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2024.04.1"),
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/posit/connect/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_count(self):
assert self.client.groups.count() == 1

def test_get(self):
assert self.client.groups.get(self.item.guid)
assert self.client.groups.get(self.item["guid"])

def test_find(self):
assert self.client.groups.find() == [self.item]
Expand Down
156 changes: 20 additions & 136 deletions src/posit/connect/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,139 +9,19 @@


class BundleMetadata(resources.Resource):
"""Bundle metadata resource.

Attributes
----------
source : str | None
Source of the bundle.
source_repo : str | None
Source repository of the bundle.
source_branch : str | None
Source branch of the bundle.
source_commit : str | None
Source commit of the bundle.
archive_md5 : str | None
MD5 checksum of the bundle archive.
archive_sha1 : str | None
SHA-1 checksum of the bundle archive.
"""

@property
def source(self) -> str | None:
return self.get("source")

@property
def source_repo(self) -> str | None:
return self.get("source_repo")

@property
def source_branch(self) -> str | None:
return self.get("source_branch")

@property
def source_commit(self) -> str | None:
return self.get("source_commit")

@property
def archive_md5(self) -> str | None:
return self.get("archive_md5")

@property
def archive_sha1(self) -> str | None:
return self.get("archive_sha1")
pass


class Bundle(resources.Resource):
"""Bundle resource.

Attributes
----------
id : str
Identifier of the bundle.
content_guid : str
Content GUID of the bundle.
created_time : str
Creation time of the bundle.
cluster_name : str | None
Cluster name associated with the bundle.
image_name : str | None
Image name of the bundle.
r_version : str | None
R version used in the bundle.
r_environment_management : bool | None
Indicates if R environment management is enabled.
py_version : str | None
Python version used in the bundle.
py_environment_management : bool | None
Indicates if Python environment management is enabled.
quarto_version : str | None
Quarto version used in the bundle.
active : bool | None
Indicates if the bundle is active.
size : int | None
Size of the bundle.
metadata : BundleMetadata
Metadata of the bundle.
"""

@property
def id(self) -> str:
return self["id"]

@property
def content_guid(self) -> str:
return self["content_guid"]

@property
def created_time(self) -> str:
return self["created_time"]

@property
def cluster_name(self) -> str | None:
return self.get("cluster_name")

@property
def image_name(self) -> str | None:
return self.get("image_name")

@property
def r_version(self) -> str | None:
return self.get("r_version")

@property
def r_environment_management(self) -> bool | None:
return self.get("r_environment_management")

@property
def py_version(self) -> str | None:
return self.get("py_version")

@property
def py_environment_management(self) -> bool | None:
return self.get("py_environment_management")

@property
def quarto_version(self) -> str | None:
return self.get("quarto_version")

@property
def active(self) -> bool | None:
return self["active"]

@property
def size(self) -> int | None:
return self["size"]

@property
def metadata(self) -> BundleMetadata:
return BundleMetadata(self.params, **self.get("metadata", {}))

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

def deploy(self) -> tasks.Task:
"""Deploy the bundle.
Expand All @@ -159,9 +39,11 @@ def deploy(self) -> tasks.Task:
>>> task.wait_for()
None
"""
path = f"v1/content/{self.content_guid}/deploy"
url = self.url + path
response = self.session.post(url, json={"bundle_id": self.id})
path = f"v1/content/{self['content_guid']}/deploy"
url = self.params.url + path
response = self.params.session.post(
url, json={"bundle_id": self["id"]}
)
result = response.json()
ts = tasks.Tasks(self.params)
return ts.get(result["task_id"])
Expand Down Expand Up @@ -197,9 +79,11 @@ def download(self, output: io.BufferedWriter | str) -> None:
f"download() expected argument type 'io.BufferedWriter` or 'str', but got '{type(output).__name__}'"
)

path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
url = self.url + path
response = self.session.get(url, stream=True)
path = (
f"v1/content/{self['content_guid']}/bundles/{self['id']}/download"
)
url = self.params.url + path
response = self.params.session.get(url, stream=True)
if isinstance(output, io.BufferedWriter):
for chunk in response.iter_content():
output.write(chunk)
Expand Down Expand Up @@ -284,8 +168,8 @@ def create(self, archive: io.BufferedReader | bytes | str) -> Bundle:
)

path = f"v1/content/{self.content_guid}/bundles"
url = self.url + path
response = self.session.post(url, data=data)
url = self.params.url + path
response = self.params.session.post(url, data=data)
result = response.json()
return Bundle(self.params, **result)

Expand All @@ -298,8 +182,8 @@ def find(self) -> List[Bundle]:
List of all found bundles.
"""
path = f"v1/content/{self.content_guid}/bundles"
url = self.url + path
response = self.session.get(url)
url = self.params.url + path
response = self.params.session.get(url)
results = response.json()
return [Bundle(self.params, **result) for result in results]

Expand Down Expand Up @@ -328,7 +212,7 @@ def get(self, uid: str) -> Bundle:
The bundle with the specified ID.
"""
path = f"v1/content/{self.content_guid}/bundles/{uid}"
url = self.url + path
response = self.session.get(url)
url = self.params.url + path
response = self.params.session.get(url)
result = response.json()
return Bundle(self.params, **result)
Loading
Loading