Skip to content

Commit 49d21bc

Browse files
committed
Unit test user.groups.find()
1 parent c1f23d9 commit 49d21bc

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"results": [
3+
{
4+
"guid": "empty-group-guid",
5+
"name": "Empty Friends",
6+
"owner_guid": "empty-owner-guid"
7+
},
8+
{
9+
"guid": "6f300623-1e0c-48e6-a473-ddf630c0c0c3",
10+
"name": "Friends",
11+
"owner_guid": "20a79ce3-6e87-4522-9faf-be24228800a4"
12+
}
13+
],
14+
"current_page": 1,
15+
"total": 2
16+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"guid": "6f300623-1e0c-48e6-a473-ddf630c0c0c3",
3-
"name": "Friends",
4-
"owner_guid": "20a79ce3-6e87-4522-9faf-be24228800a4"
5-
}
2+
"guid": "6f300623-1e0c-48e6-a473-ddf630c0c0c3",
3+
"name": "Friends",
4+
"owner_guid": "20a79ce3-6e87-4522-9faf-be24228800a4"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"results": [],
3+
"current_page": 1,
4+
"total": 0
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"results": [
3+
{
4+
"guid": "empty-group-guid",
5+
"name": "Empty Friends",
6+
"owner_guid": "empty-owner-guid"
7+
},
8+
{
9+
"guid": "6f300623-1e0c-48e6-a473-ddf630c0c0c3",
10+
"name": "Friends",
11+
"owner_guid": "20a79ce3-6e87-4522-9faf-be24228800a4"
12+
}
13+
],
14+
"current_page": 1,
15+
"total": 2
16+
}

tests/posit/connect/test_users.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from posit.connect.client import Client
99

10-
from .api import load_mock
10+
from .api import load_mock, load_mock_dict
1111

1212
session = Mock()
1313
url = Mock()
@@ -134,6 +134,52 @@ def test_unlock(self):
134134
assert not user["locked"]
135135

136136

137+
class TestUserGroups:
138+
@responses.activate
139+
def test_groups(self):
140+
# Get user
141+
carlos_guid = "20a79ce3-6e87-4522-9faf-be24228800a4"
142+
responses.get(
143+
f"https://connect.example/__api__/v1/users/{carlos_guid}",
144+
json=load_mock_dict(f"v1/users/{carlos_guid}.json"),
145+
)
146+
responses.get(
147+
"https://connect.example/__api__/v1/users",
148+
json=load_mock("v1/users?page_number=1&page_size=500.jsonc"),
149+
)
150+
# Get groups
151+
responses.get(
152+
"https://connect.example/__api__/v1/groups",
153+
json=load_mock_dict("v1/groups.json"),
154+
)
155+
# Get group members
156+
group_guid = "6f300623-1e0c-48e6-a473-ddf630c0c0c3"
157+
empty_group_guid = "empty-group-guid"
158+
for guid in (group_guid, empty_group_guid):
159+
responses.get(
160+
f"https://connect.example/__api__/v1/groups/{guid}/members",
161+
json=load_mock_dict(f"v1/groups/{guid}/members.json"),
162+
)
163+
164+
client = Client("https://connect.example/")
165+
users = client.users.find()
166+
assert len(users) == 2 + 2
167+
168+
carlos = client.users.get(carlos_guid)
169+
print("carlos.guid", carlos["guid"])
170+
no_groups = carlos.groups.find()
171+
print("no_groups", no_groups)
172+
assert len(no_groups) == 0
173+
174+
user = users[1]
175+
assert user["guid"] == "87c12c08-11cd-4de1-8da3-12a7579c4998"
176+
177+
groups = user.groups.find()
178+
assert len(groups) == 1
179+
group = groups[0]
180+
assert group["name"] == "Friends"
181+
182+
137183
class TestUsers:
138184
@responses.activate
139185
def test_users_get(self):

0 commit comments

Comments
 (0)