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: inject url path parts instead of endpoints #315

Merged
merged 33 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0533f19
feat: add jobs
tdstein Oct 18, 2024
6b79912
--wip-- [skip ci]
tdstein Oct 22, 2024
279fcd6
refactor: introduce the active pattern
tdstein Oct 23, 2024
e349870
add link to parent
tdstein Oct 23, 2024
533839b
skip when Quarto unavailable
tdstein Oct 23, 2024
1066ca3
adds unit tests
tdstein Oct 23, 2024
437c515
adds docstrings
tdstein Oct 23, 2024
a1ca377
Update src/posit/connect/resources.py
tdstein Oct 24, 2024
82b9b7e
applies feedback discussed in pull requests
tdstein Oct 24, 2024
6b8126d
refactor: inject url path parts instead of endpoints
tdstein Oct 25, 2024
b64f3e7
update docstrings
tdstein Oct 28, 2024
f57340d
renames init arguments to path and pathinfo
tdstein Oct 28, 2024
72b62ac
minor cleanup
tdstein Oct 28, 2024
f1d6f42
refactors _data property into _get_or_fetch method
tdstein Oct 29, 2024
dd74d60
fix method signature
tdstein Oct 29, 2024
fb52c83
fix cache check
tdstein Oct 29, 2024
bbbd6b4
Update src/posit/connect/resources.py
tdstein Oct 29, 2024
bc2cfcb
feat: add jobs
tdstein Oct 18, 2024
9c3d6dd
--wip-- [skip ci]
tdstein Oct 22, 2024
9019386
refactor: introduce the active pattern
tdstein Oct 23, 2024
4bfe3f8
add link to parent
tdstein Oct 23, 2024
a721b61
skip when Quarto unavailable
tdstein Oct 23, 2024
107ee85
adds unit tests
tdstein Oct 23, 2024
a070f0a
adds docstrings
tdstein Oct 23, 2024
d196271
Update src/posit/connect/resources.py
tdstein Oct 24, 2024
d87cfe7
applies feedback discussed in pull requests
tdstein Oct 24, 2024
2add280
Merge remote-tracking branch 'origin/tdstein/jobs' into tdstein/jobs-…
tdstein Oct 29, 2024
97d24f6
Merge remote-tracking branch 'origin/main' into tdstein/jobs-endpoint…
tdstein Oct 30, 2024
7eeb054
refactor: wrap cache interactions (#318)
tdstein Oct 30, 2024
03accf8
removes pathinfo options when not needed
tdstein Oct 30, 2024
77f8a38
remove unecessary arg
tdstein Oct 30, 2024
ac488c7
additional path cleanup
tdstein Oct 30, 2024
b3ff1cd
remove self imposed complexity of the method
tdstein Oct 31, 2024
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
38 changes: 38 additions & 0 deletions integration/tests/posit/connect/test_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import pytest
from packaging import version

from posit import connect

from . import CONNECT_VERSION


class TestJobs:
@classmethod
def setup_class(cls):
cls.client = connect.Client()
cls.content = cls.client.content.create(name="example-quarto-minimal")

@classmethod
def teardown_class(cls):
cls.content.delete()
assert cls.client.content.count() == 0

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Quarto not available",
)
def test(self):
content = self.content

path = Path("../../../resources/connect/bundles/example-quarto-minimal/bundle.tar.gz")
path = Path(__file__).parent / path
path = path.resolve()
path = str(path)

bundle = content.bundles.create(path)
bundle.deploy()

jobs = content.jobs
assert len(jobs) == 1
10 changes: 9 additions & 1 deletion src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

from . import tasks
from .bundles import Bundles
from .context import Context
from .env import EnvVars
from .jobs import JobsMixin
from .oauth.associations import ContentItemAssociations
from .permissions import Permissions
from .resources import Resource, ResourceParameters, Resources
Expand All @@ -32,7 +34,13 @@ class ContentItemOwner(Resource):
pass


class ContentItem(VanityMixin, Resource):
class ContentItem(JobsMixin, VanityMixin, Resource):
def __init__(self, /, params: ResourceParameters, **kwargs):
ctx = Context(params.session, params.url)
path = f"v1/content"
pathinfo = kwargs["guid"]
super().__init__(ctx, path, pathinfo, **kwargs)

def __getitem__(self, key: Any) -> Any:
v = super().__getitem__(key)
if key == "owner" and isinstance(v, dict):
Expand Down
6 changes: 4 additions & 2 deletions src/posit/connect/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import requests
from packaging.version import Version

from .urls import Url


def requires(version: str):
def decorator(func):
Expand All @@ -22,7 +24,7 @@ def wrapper(instance: ContextManager, *args, **kwargs):


class Context(dict):
def __init__(self, session: requests.Session, url: str):
def __init__(self, session: requests.Session, url: Url):
self.session = session
self.url = url

Expand All @@ -38,7 +40,7 @@ def version(self) -> Optional[str]:
return value

@version.setter
def version(self, value: str):
def version(self, value):
self["version"] = value


Expand Down
Loading