55
66from posit .connect .client import Client
77from posit .connect .config import Config
8- from posit .connect .content import ContentItem
8+ from posit .connect .content import ContentItem , ContentItemOwner
99from posit .connect .permissions import Permissions
1010
1111from .api import load_mock # type: ignore
1212
1313
14+ class TestContentOwnerAttributes :
15+ @classmethod
16+ def setup_class (cls ):
17+ guid = "20a79ce3-6e87-4522-9faf-be24228800a4"
18+ config = Config (api_key = "12345" , url = "https://connect.example/" )
19+ session = requests .Session ()
20+ fake_item = load_mock (f"v1/users/{ guid } .json" )
21+ cls .item = ContentItemOwner (config , session , ** fake_item )
22+
23+ def test_guid (self ):
24+ assert self .item .guid == "20a79ce3-6e87-4522-9faf-be24228800a4"
25+
26+ def test_username (self ):
27+ assert self .item .username == "carlos12"
28+
29+ def test_first_name (self ):
30+ assert self .item .first_name == "Carlos"
31+
32+ def test_last_name (self ):
33+ assert self .item .last_name == "User"
34+
35+
1436class TestContentItemAttributes :
1537 @classmethod
1638 def setup_class (cls ):
@@ -138,7 +160,7 @@ def test_run_as_current_user(self):
138160 assert self .item .run_as_current_user is False
139161
140162 def test_owner_guid (self ):
141- assert self .item .owner_guid == "87c12c08-11cd-4de1-8da3-12a7579c4998 "
163+ assert self .item .owner_guid == "20a79ce3-6e87-4522-9faf-be24228800a4 "
142164
143165 def test_content_url (self ):
144166 assert (
@@ -156,7 +178,7 @@ def test_app_role(self):
156178 assert self .item .app_role == "viewer"
157179
158180 def test_owner (self ):
159- assert self . item . owner == {}
181+ assert " owner" not in self . item
160182
161183 def test_permissions (self ):
162184 assert isinstance (self .item .permissions , Permissions )
@@ -165,6 +187,35 @@ def test_tags(self):
165187 assert self .item .tags == []
166188
167189
190+ class TestContentItemGetContentOwner :
191+ @responses .activate
192+ def test_owner (self ):
193+ mock_content = load_mock (
194+ "v1/content/f2f37341-e21d-3d80-c698-a935ad614066.json"
195+ )
196+ responses .get (
197+ "https://connect.example/__api__/v1/content/f2f37341-e21d-3d80-c698-a935ad614066" ,
198+ json = mock_content ,
199+ )
200+
201+ mock_user_get = responses .get (
202+ f"https://connect.example/__api__/v1/users/20a79ce3-6e87-4522-9faf-be24228800a4" ,
203+ json = load_mock (
204+ f"v1/users/20a79ce3-6e87-4522-9faf-be24228800a4.json"
205+ ),
206+ )
207+
208+ c = Client ("12345" , "https://connect.example" )
209+ item = c .content .get ("f2f37341-e21d-3d80-c698-a935ad614066" )
210+ owner = item .owner
211+ assert owner .guid == "20a79ce3-6e87-4522-9faf-be24228800a4"
212+
213+ # load a second time, assert tha owner is loaded from cached result
214+ owner = item .owner
215+ assert owner .guid == "20a79ce3-6e87-4522-9faf-be24228800a4"
216+ assert mock_user_get .call_count == 1
217+
218+
168219class TestContentItemDelete :
169220 @responses .activate
170221 def test (self ):
0 commit comments