Skip to content

Commit 5de2bc7

Browse files
committed
[Internal] Remove iam lists integration tests and add unit tests
1 parent 672da6f commit 5de2bc7

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

tests/integration/test_iam.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,3 @@ def test_scim_get_user_as_dict(w):
2222
user = w.users.get(first_user.id)
2323
# should not throw
2424
user.as_dict()
25-
26-
27-
@pytest.mark.parametrize(
28-
"path,call",
29-
[("/api/2.0/preview/scim/v2/Users", lambda w: w.users.list(count=10)),
30-
("/api/2.0/preview/scim/v2/Groups", lambda w: w.groups.list(count=4)),
31-
("/api/2.0/preview/scim/v2/ServicePrincipals", lambda w: w.service_principals.list(count=1)), ])
32-
def test_workspace_users_list_pagination(w, path, call):
33-
raw = w.api_client.do('GET', path)
34-
total = raw['totalResults']
35-
all = call(w)
36-
found = len(list(all))
37-
assert found == total
38-
39-
40-
@pytest.mark.parametrize(
41-
"path,call",
42-
[("/api/2.0/accounts/%s/scim/v2/Users", lambda a: a.users.list(count=3000)),
43-
("/api/2.0/accounts/%s/scim/v2/Groups", lambda a: a.groups.list(count=5)),
44-
("/api/2.0/accounts/%s/scim/v2/ServicePrincipals", lambda a: a.service_principals.list(count=1000)), ])
45-
def test_account_users_list_pagination(a, path, call):
46-
raw = a.api_client.do('GET', path.replace("%s", a.config.account_id))
47-
total = raw['totalResults']
48-
all = call(a)
49-
found = len(list(all))
50-
assert found == total

tests/test_iam.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
3+
from databricks.sdk import WorkspaceClient, AccountClient
4+
5+
@pytest.mark.parametrize(
6+
"path,call",
7+
[
8+
("/api/2.0/preview/scim/v2/Users", lambda w: w.users.list()),
9+
("/api/2.0/preview/scim/v2/Groups", lambda w: w.groups.list()),
10+
("/api/2.0/preview/scim/v2/ServicePrincipals", lambda w: w.service_principals.list()),
11+
],
12+
)
13+
def test_workspace_iam_list(config, requests_mock, path, call):
14+
requests_mock.get(
15+
f"http://localhost{path}",
16+
request_headers={
17+
"Accept": "application/json",
18+
},
19+
text="null",
20+
)
21+
w = WorkspaceClient(config=config)
22+
for _ in call(w):
23+
pass
24+
assert requests_mock.call_count == 1
25+
assert requests_mock.called
26+
27+
28+
@pytest.mark.parametrize(
29+
"path,call",
30+
[
31+
("/api/2.0/accounts/%s/scim/v2/Users", lambda a: a.users.list()),
32+
("/api/2.0/accounts/%s/scim/v2/Groups", lambda a: a.groups.list()),
33+
("/api/2.0/accounts/%s/scim/v2/ServicePrincipals", lambda a: a.service_principals.list()),
34+
],
35+
)
36+
def test_account_iam_list(config, requests_mock, path, call):
37+
config.account_id = "test_account_id"
38+
requests_mock.get(
39+
path.replace("%s", config.account_id),
40+
request_headers={
41+
"Accept": "application/json",
42+
},
43+
text="null",
44+
)
45+
a = AccountClient(config=config)
46+
for _ in call(a):
47+
pass
48+
assert requests_mock.call_count == 1
49+
assert requests_mock.called

0 commit comments

Comments
 (0)