Skip to content

feat: update responses with content_guid and content_id #405

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/posit/connect/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def find_by(
key: str = ...,
remote_id: str | None = ...,
app_id: str = ...,
content_id: str = ...,
variant_id: str = ...,
bundle_id: str = ...,
# Timestamps
Expand Down Expand Up @@ -129,6 +130,9 @@ def find_by(
Identifier for off-host execution configurations.
app_id : str, not required
Identifier of the parent content associated with the job.
This field is deprecated and has been renamed to content_id.
content_id : str, not required
Identifier of the parent content associated with the job.
variant_id : str, not required
Identifier of the variant responsible for the job.
bundle_id : str, not required
Expand Down
16 changes: 16 additions & 0 deletions src/posit/connect/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def fetch(
bundle_id: str = ...,
app_id: str = ...,
app_guid: str = ...,
content_id: str = ...,
content_guid: str = ...,
) -> Iterable[Package]:
"""
Fetch all records matching the specified conditions.
Expand All @@ -110,8 +112,14 @@ def fetch(
The unique identifier of the bundle this package is associated with.
app_id: str, not required
The numerical identifier of the application this package is associated with.
This field is deprecated and has been renamed to content_id.
app_guid: str, not required
The unique identifier of the application this package is associated with.
This field is deprecated and has been renamed to content_guid.
content_id: str, not required
The numerical identifier of the content item this package is associated with.
content_guid: str, not required
The unique identifier of the content item this package is associated with.

Returns
-------
Expand All @@ -130,6 +138,8 @@ def find_by(
bundle_id: str = ...,
app_id: str = ...,
app_guid: str = ...,
content_id: str = ...,
content_guid: str = ...,
) -> Package | None:
"""
Find the first record matching the specified conditions.
Expand All @@ -150,8 +160,14 @@ def find_by(
The unique identifier of the bundle this package is associated with.
app_id: str, not required
The numerical identifier of the application this package is associated with.
This field is deprecated and has been renamed to content_id.
app_guid: str, not required
The unique identifier of the application this package is associated with.
This field is deprecated and has been renamed to content_guid.
content_id: str, not required
The numerical identifier of the content item this package is associated with.
content_guid: str, not required
The unique identifier of the content item this package is associated with.

Returns
-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"key": "tHawGvHZTosJA2Dx",
"remote_id": "S3ViZXJuZXRlczpyZW5kZXItci1tYXJrZG93bi1zaXRlLWtnODJo",
"app_id": "54",
"content_id": "54",
"variant_id": "54",
"bundle_id": "54",
"start_time": "2006-01-02T15:04:05-07:00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"key": "tHawGvHZTosJA2Dx",
"remote_id": "S3ViZXJuZXRlczpyZW5kZXItci1tYXJrZG93bi1zaXRlLWtnODJo",
"app_id": "54",
"content_id": "54",
"variant_id": "54",
"bundle_id": "54",
"start_time": "2006-01-02T15:04:05-07:00",
Expand Down
6 changes: 5 additions & 1 deletion tests/posit/connect/__api__/v1/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
{
"language": "python",
"name": "posit",
"version": "0.6.0"
"version": "0.6.0",
"app_id": "123",
"app_guid": "abcd-1234",
"content_id": "123",
"content_guid": "abcd-1234"
}
],
"current_page": 1,
Expand Down
27 changes: 27 additions & 0 deletions tests/posit/connect/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ def test(self):
assert job
assert job["key"] == "tHawGvHZTosJA2Dx"

@responses.activate
def test_with_content_id(self):
responses.get(
"https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066",
json=load_mock("v1/content/f2f37341-e21d-3d80-c698-a935ad614066.json"),
)

responses.get(
"https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066/jobs",
json=load_mock("v1/content/f2f37341-e21d-3d80-c698-a935ad614066/jobs.json"),
)

c = Client("https://connect.example", "12345")
content = c.content.get("f2f37341-e21d-3d80-c698-a935ad614066")

# Test with content_id (new field)
job = content.jobs.find_by(content_id="54")
assert job
assert job["content_id"] == "54"
assert job["app_id"] == "54" # Should have both fields

# Test with app_id (deprecated field)
job = content.jobs.find_by(app_id="54")
assert job
assert job["app_id"] == "54"
assert job["content_id"] == "54" # Should have both fields


class TestJobDestory:
@responses.activate
Expand Down
22 changes: 22 additions & 0 deletions tests/posit/connect/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ def test(self):
assert package
assert package["name"] == "posit"
assert mock_get.call_count == 1

@responses.activate
def test_with_content_fields(self):
mock_get = responses.get(
"https://connect.example/__api__/v1/packages",
json=load_mock("v1/packages.json"),
)

c = Client("https://connect.example", "12345")
c._ctx.version = None

# Test with content_id and content_guid (new fields)
package = c.packages.find_by(name="posit", content_id="123", content_guid="abcd-1234")
assert package
assert package["name"] == "posit"
assert mock_get.call_count == 1

# Test with app_id and app_guid (deprecated fields)
package = c.packages.find_by(name="posit", app_id="123", app_guid="abcd-1234")
assert package
assert package["name"] == "posit"
assert mock_get.call_count == 2
Loading