@@ -27,9 +27,10 @@ def enterprise_mocks(enterprise, requests_mock, sample_json):
27
27
m .json_user = sample_json ("UserInfo" )
28
28
m .json_users = {"users" : [m .json_user ]}
29
29
m .json_group = sample_json ("UserGroup" )
30
+ m .json_enterprise = sample_json ("EnterpriseInfo" )
30
31
m .user_id = m .json_user ["id" ]
31
32
m .group_id = m .json_group ["id" ]
32
- m .get_info = requests_mock .get (enterprise .url , json = sample_json ( "EnterpriseInfo" ) )
33
+ m .get_info = requests_mock .get (enterprise .url , json = m . json_enterprise )
33
34
m .get_user = requests_mock .get (
34
35
f"{ enterprise .url } /users/{ m .user_id } " , json = m .json_user
35
36
)
@@ -97,6 +98,35 @@ def test_info(enterprise, enterprise_mocks):
97
98
98
99
assert enterprise .info (force = True ).id == "entUBq2RGdihxl3vU"
99
100
assert enterprise_mocks .get_info .call_count == 2
101
+ assert "aggregated" not in enterprise_mocks .get_info .last_request .qs
102
+ assert "descendants" not in enterprise_mocks .get_info .last_request .qs
103
+
104
+
105
+ def test_info__aggregated_descendants (enterprise , enterprise_mocks ):
106
+ enterprise_mocks .json_enterprise ["aggregated" ] = {
107
+ "groupIds" : ["ugp1mKGb3KXUyQfOZ" ],
108
+ "userIds" : ["usrL2PNC5o3H4lBEi" ],
109
+ "workspaceIds" : ["wspmhESAta6clCCwF" ],
110
+ }
111
+ enterprise_mocks .json_enterprise ["descendants" ] = {
112
+ (sub_ent_id := fake_id ("ent" )): {
113
+ "groupIds" : ["ugp1mKGb3KXUyDESC" ],
114
+ "userIds" : ["usrL2PNC5o3H4DESC" ],
115
+ "workspaceIds" : ["wspmhESAta6clDESC" ],
116
+ }
117
+ }
118
+ info = enterprise .info (aggregated = True , descendants = True )
119
+ assert enterprise_mocks .get_info .call_count == 1
120
+ assert enterprise_mocks .get_info .last_request .qs ["include" ] == [
121
+ "aggregated" ,
122
+ "descendants" ,
123
+ ]
124
+ assert info .aggregated .group_ids == ["ugp1mKGb3KXUyQfOZ" ]
125
+ assert info .aggregated .user_ids == ["usrL2PNC5o3H4lBEi" ]
126
+ assert info .aggregated .workspace_ids == ["wspmhESAta6clCCwF" ]
127
+ assert info .descendants [sub_ent_id ].group_ids == ["ugp1mKGb3KXUyDESC" ]
128
+ assert info .descendants [sub_ent_id ].user_ids == ["usrL2PNC5o3H4DESC" ]
129
+ assert info .descendants [sub_ent_id ].workspace_ids == ["wspmhESAta6clDESC" ]
100
130
101
131
102
132
def test_user (enterprise , enterprise_mocks ):
@@ -122,6 +152,34 @@ def test_user__no_collaboration(enterprise, enterprise_mocks):
122
152
assert not user .collaborations .workspaces
123
153
124
154
155
+ def test_user__descendants (enterprise , enterprise_mocks ):
156
+ enterprise_mocks .json_users ["users" ][0 ]["descendants" ] = {
157
+ (other_ent_id := fake_id ("ent" )): {
158
+ "lastActivityTime" : "2021-01-01T12:34:56Z" ,
159
+ "isAdmin" : True ,
160
+ "groups" : [{"id" : (fake_group_id := fake_id ("ugp" ))}],
161
+ }
162
+ }
163
+ user = enterprise .user (enterprise_mocks .user_id , descendants = True )
164
+ d = user .descendants [other_ent_id ]
165
+ assert d .last_activity_time == "2021-01-01T12:34:56Z"
166
+ assert d .is_admin is True
167
+ assert d .groups [0 ].id == fake_group_id
168
+
169
+
170
+ def test_user__aggregates (enterprise , enterprise_mocks ):
171
+ enterprise_mocks .json_users ["users" ][0 ]["aggregated" ] = {
172
+ "lastActivityTime" : "2021-01-01T12:34:56Z" ,
173
+ "isAdmin" : True ,
174
+ "groups" : [{"id" : (fake_group_id := fake_id ("ugp" ))}],
175
+ }
176
+ user = enterprise .user (enterprise_mocks .user_id , aggregated = True )
177
+ a = user .aggregated
178
+ assert a .last_activity_time == "2021-01-01T12:34:56Z"
179
+ assert a .is_admin is True
180
+ assert a .groups [0 ].id == fake_group_id
181
+
182
+
125
183
@pytest .mark .parametrize (
126
184
"search_for" ,
127
185
(
@@ -138,6 +196,36 @@ def test_users(enterprise, search_for):
138
196
assert user .state == "provisioned"
139
197
140
198
199
+ def test_users__descendants (enterprise , enterprise_mocks ):
200
+ enterprise_mocks .json_users ["users" ][0 ]["descendants" ] = {
201
+ (other_ent_id := fake_id ("ent" )): {
202
+ "lastActivityTime" : "2021-01-01T12:34:56Z" ,
203
+ "isAdmin" : True ,
204
+ "groups" : [{"id" : (fake_group_id := fake_id ("ugp" ))}],
205
+ }
206
+ }
207
+ users = enterprise .users ([enterprise_mocks .user_id ], descendants = True )
208
+ assert len (users ) == 1
209
+ d = users [0 ].descendants [other_ent_id ]
210
+ assert d .last_activity_time == "2021-01-01T12:34:56Z"
211
+ assert d .is_admin is True
212
+ assert d .groups [0 ].id == fake_group_id
213
+
214
+
215
+ def test_users__aggregates (enterprise , enterprise_mocks ):
216
+ enterprise_mocks .json_users ["users" ][0 ]["aggregated" ] = {
217
+ "lastActivityTime" : "2021-01-01T12:34:56Z" ,
218
+ "isAdmin" : True ,
219
+ "groups" : [{"id" : (fake_group_id := fake_id ("ugp" ))}],
220
+ }
221
+ users = enterprise .users ([enterprise_mocks .user_id ], aggregated = True )
222
+ assert len (users ) == 1
223
+ a = users [0 ].aggregated
224
+ assert a .last_activity_time == "2021-01-01T12:34:56Z"
225
+ assert a .is_admin is True
226
+ assert a .groups [0 ].id == fake_group_id
227
+
228
+
141
229
def test_group (enterprise , enterprise_mocks ):
142
230
grp = enterprise .group ("ugp1mKGb3KXUyQfOZ" )
143
231
assert enterprise_mocks .get_group .call_count == 1
0 commit comments