Skip to content

Commit fa82d86

Browse files
committed
--wip--
1 parent 999755b commit fa82d86

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import select
2+
from posit import connect
3+
4+
5+
class TestContent:
6+
@classmethod
7+
def setup_class(cls):
8+
cls.client = connect.Client()
9+
cls.environment = cls.client.environments.create(
10+
title="Title", cluster_name="Kubernetes", name="Name"
11+
)
12+
13+
@classmethod
14+
def teardown_class(cls):
15+
cls.environment.destroy()
16+
17+
def test_find(self):
18+
uid = self.environment["guid"]
19+
environment = self.client.environments.find(uid)
20+
assert environment == self.environment
21+
22+
def test_find_by(self):
23+
environment = self.client.environments.find_by(name="Name")
24+
assert environment == self.environment
25+
26+
def test_update(self):
27+
self.environment.update(title="New Title")
28+
assert self.environment["title"] == "New Title"

src/posit/connect/environments.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from typing import Dict, Literal, Optional, TypedDict, overload
2+
3+
from typing_extensions import NotRequired, Required, Unpack
4+
15
from .resources import (
26
ActiveCreatorMethods,
37
ActiveDestroyerMethods,
@@ -7,12 +11,50 @@
711

812

913
class Environment(ActiveUpdaterMethods, ActiveDestroyerMethods):
10-
pass
14+
class _UpdateEnvironment(TypedDict, total=False):
15+
title: Required[str]
16+
description: NotRequired[Optional[str]]
17+
matching: NotRequired[Optional[Literal["any", "exact", "none"]]]
18+
supervisor: NotRequired[Optional[str]]
19+
python: NotRequired[Dict]
20+
quarto: NotRequired[Dict]
21+
r: NotRequired[Dict]
22+
tensorflow: NotRequired[Dict]
23+
24+
@overload
25+
def update(self, /, **attributes: Unpack[_UpdateEnvironment]): ...
26+
27+
@overload
28+
def update(self, /, **attributes): ...
29+
30+
def update(self, /, **attributes):
31+
return super().update(**attributes)
1132

1233

1334
class Environments(ActiveFinderMethods[Environment], ActiveCreatorMethods[Environment]):
1435
def __init__(self, ctx, path, pathinfo="environments", uid="guid"):
1536
super().__init__(ctx, path, pathinfo, uid)
1637

38+
class _CreateEnvironment(TypedDict, total=False):
39+
title: Required[str]
40+
description: NotRequired[Optional[str]]
41+
cluster_name: Required[Literal["Kubernetes"]]
42+
name: Required[str]
43+
matching: NotRequired[Optional[Literal["any", "exact", "none"]]]
44+
supervisor: NotRequired[Optional[str]]
45+
python: NotRequired[Dict]
46+
quarto: NotRequired[Dict]
47+
r: NotRequired[Dict]
48+
tensorflow: NotRequired[Dict]
49+
50+
@overload
51+
def create(self, **attributes: Unpack[_CreateEnvironment]): ...
52+
53+
@overload
54+
def create(self, **attributes): ...
55+
56+
def create(self, **attributes):
57+
return super().create(**attributes)
58+
1759
def _create_instance(self, path, pathinfo, /, **attributes):
1860
return Environment(self._ctx, path, pathinfo, **attributes)

src/posit/connect/resources.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,15 @@ def create(self, **attributes) -> T:
238238
return self._create_instance(self._path, uid, **result)
239239

240240

241-
class ActiveDestroyerMethods(Active):
241+
class ActiveDestroyerMethods(Active, ABC):
242242
def destroy(self):
243243
endpoint = self._ctx.url + self._path
244244
self._ctx.session.delete(endpoint)
245245

246246

247-
class ActiveUpdaterMethods(Active):
247+
class ActiveUpdaterMethods(Active, ABC):
248248
def update(self, /, **attributes):
249-
super().update(**attributes)
250-
self.save()
251-
252-
def save(self):
253249
endpoint = self._ctx.url + self._path
254-
response = self._ctx.session.put(endpoint, json=self)
250+
response = self._ctx.session.put(endpoint, json=attributes)
255251
result = response.json()
256252
super().update(**result)

0 commit comments

Comments
 (0)