msfabricpysdkcore 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- msfabricpysdkcore/__init__.py +2 -1
- msfabricpysdkcore/admin_item.py +106 -0
- msfabricpysdkcore/admin_workspace.py +127 -0
- msfabricpysdkcore/adminapi.py +535 -0
- msfabricpysdkcore/capacity.py +56 -0
- msfabricpysdkcore/client.py +4 -265
- msfabricpysdkcore/coreapi.py +324 -0
- msfabricpysdkcore/domain.py +378 -0
- msfabricpysdkcore/item.py +19 -1
- msfabricpysdkcore/job_instance.py +3 -0
- msfabricpysdkcore/lakehouse.py +96 -0
- msfabricpysdkcore/onelakeshortcut.py +3 -0
- msfabricpysdkcore/tests/__init__.py +0 -0
- msfabricpysdkcore/tests/test_admin_apis.py +69 -0
- msfabricpysdkcore/tests/test_domains.py +125 -0
- msfabricpysdkcore/tests/test_git.py +62 -0
- msfabricpysdkcore/tests/test_items_incl_lakehouse.py +69 -0
- msfabricpysdkcore/tests/test_jobs.py +39 -0
- msfabricpysdkcore/tests/test_shortcuts.py +53 -0
- msfabricpysdkcore/tests/test_workspaces_capacities.py +146 -0
- msfabricpysdkcore/workspace.py +47 -7
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/METADATA +201 -19
- msfabricpysdkcore-0.0.4.dist-info/RECORD +28 -0
- msfabricpysdkcore-0.0.2.dist-info/RECORD +0 -13
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/WHEEL +0 -0
- {msfabricpysdkcore-0.0.2.dist-info → msfabricpysdkcore-0.0.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
import unittest
|
2
|
+
from dotenv import load_dotenv
|
3
|
+
from datetime import datetime
|
4
|
+
from msfabricpysdkcore import FabricClientCore, FabricClientAdmin
|
5
|
+
|
6
|
+
load_dotenv()
|
7
|
+
|
8
|
+
class TestFabricClientCore(unittest.TestCase):
|
9
|
+
|
10
|
+
def __init__(self, *args, **kwargs):
|
11
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
12
|
+
|
13
|
+
|
14
|
+
def test_domains(self):
|
15
|
+
fcc = FabricClientCore()
|
16
|
+
fca = FabricClientAdmin()
|
17
|
+
|
18
|
+
ws = fcc.get_workspace_by_name("sdktestdomains")
|
19
|
+
cap = fcc.get_capacity(capacity_id=ws.capacity_id)
|
20
|
+
principal = {'id': 'b4f4e299-e6e1-4667-886c-57e4a8dde1c2', 'type': 'User'}
|
21
|
+
|
22
|
+
# Delete if exists
|
23
|
+
try:
|
24
|
+
domain = fca.get_domain_by_name("sdktestdomains")
|
25
|
+
domain.delete()
|
26
|
+
except:
|
27
|
+
pass
|
28
|
+
try:
|
29
|
+
domain = fca.get_domain_by_name("sdktestdomains2")
|
30
|
+
domain.delete()
|
31
|
+
except:
|
32
|
+
pass
|
33
|
+
|
34
|
+
# Create domain
|
35
|
+
domain_name = "sdktestdomains"
|
36
|
+
domain = fca.create_domain(display_name=domain_name)
|
37
|
+
self.assertIsNotNone(domain.id)
|
38
|
+
self.assertEqual(domain.display_name, domain_name)
|
39
|
+
|
40
|
+
# Get domain by name
|
41
|
+
domain_clone = fca.get_domain_by_name(domain_name)
|
42
|
+
self.assertIsNotNone(domain_clone.id)
|
43
|
+
self.assertEqual(domain_clone.display_name, domain_name)
|
44
|
+
|
45
|
+
# Get domain by id
|
46
|
+
domain_clone = fca.get_domain_by_id(domain.id)
|
47
|
+
self.assertIsNotNone(domain_clone.id)
|
48
|
+
self.assertEqual(domain_clone.display_name, domain_name)
|
49
|
+
|
50
|
+
# List domains
|
51
|
+
domains = fca.list_domains()
|
52
|
+
self.assertGreater(len(domains), 0)
|
53
|
+
domains_ids = [d.id for d in domains]
|
54
|
+
self.assertIn(domain.id, domains_ids)
|
55
|
+
|
56
|
+
# Update domain
|
57
|
+
domain_new_name = "sdktestdomains2"
|
58
|
+
domain_clone = fca.update_domain(domain.id, display_name=domain_new_name)
|
59
|
+
self.assertEqual(domain_clone.display_name, domain_new_name)
|
60
|
+
|
61
|
+
# Assign domain workspaces by Ids
|
62
|
+
status_code = fca.assign_domain_workspaces_by_ids(domain.id, [ws.id])
|
63
|
+
self.assertEqual(status_code, 200)
|
64
|
+
|
65
|
+
# List domain workspaces
|
66
|
+
workspaces = fca.list_domain_workspaces(domain.id, workspace_objects=True)
|
67
|
+
self.assertGreater(len(workspaces), 0)
|
68
|
+
workspaces_ids = [w.id for w in workspaces]
|
69
|
+
self.assertIn(ws.id, workspaces_ids)
|
70
|
+
|
71
|
+
# Unassign domain workspaces by ids
|
72
|
+
status_code = fca.unassign_domain_workspaces_by_ids(domain.id, [ws.id])
|
73
|
+
self.assertEqual(status_code, 200)
|
74
|
+
|
75
|
+
workspaces = fca.list_domain_workspaces(domain.id)
|
76
|
+
self.assertEqual(len(workspaces), 0)
|
77
|
+
|
78
|
+
# Assign domain workspaces by capacities
|
79
|
+
status_code = fca.assign_domain_workspaces_by_capacities(domain.id, [cap.id])
|
80
|
+
self.assertEqual(status_code, 202)
|
81
|
+
|
82
|
+
workspaces = fca.list_domain_workspaces(domain.id, workspace_objects=True)
|
83
|
+
self.assertGreater(len(workspaces), 0)
|
84
|
+
workspaces_ids = [w.id for w in workspaces]
|
85
|
+
self.assertIn(ws.id, workspaces_ids)
|
86
|
+
|
87
|
+
# Unassign all domain workspaces
|
88
|
+
status_code = fca.unassign_all_domain_workspaces(domain.id)
|
89
|
+
self.assertEqual(status_code, 200)
|
90
|
+
|
91
|
+
workspaces = fca.list_domain_workspaces(domain.id)
|
92
|
+
self.assertEqual(len(workspaces), 0)
|
93
|
+
|
94
|
+
# Assign domain workspaces by principals
|
95
|
+
status_code = fca.assign_domains_workspaces_by_principals(domain.id, [principal], wait_for_completion=True)
|
96
|
+
|
97
|
+
self.assertEqual(status_code, 202)
|
98
|
+
|
99
|
+
workspaces = fca.list_domain_workspaces(domain.id, workspace_objects=True)
|
100
|
+
self.assertGreater(len(workspaces), 0)
|
101
|
+
workspaces_ids = [w.id for w in workspaces]
|
102
|
+
self.assertIn(ws.id, workspaces_ids)
|
103
|
+
|
104
|
+
# Role assignments bulk assign
|
105
|
+
|
106
|
+
principal_2 = {'id': '6edbc444-16cd-43f4-ae48-cbe734b89657', 'type': 'User'}
|
107
|
+
principals = [principal, principal_2]
|
108
|
+
|
109
|
+
status_code = fca.role_assignments_bulk_assign(domain.id, "Contributors", principals)
|
110
|
+
|
111
|
+
self.assertEqual(status_code, 200)
|
112
|
+
|
113
|
+
# Role assignments bulk unassign
|
114
|
+
status_code = fca.role_assignments_bulk_unassign(domain.id, "Contributors", [principal_2])
|
115
|
+
|
116
|
+
self.assertEqual(status_code, 200)
|
117
|
+
|
118
|
+
# Delete domain
|
119
|
+
status_code = fca.delete_domain(domain.id)
|
120
|
+
|
121
|
+
self.assertEqual(status_code, 200)
|
122
|
+
|
123
|
+
domains = fca.list_domains()
|
124
|
+
domains_ids = [d.id for d in domains]
|
125
|
+
self.assertNotIn(domain.id, domains_ids)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import unittest
|
2
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
3
|
+
from datetime import datetime
|
4
|
+
from dotenv import load_dotenv
|
5
|
+
|
6
|
+
class TestFabricClientCore(unittest.TestCase):
|
7
|
+
|
8
|
+
def __init__(self, *args, **kwargs):
|
9
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
10
|
+
#load_dotenv()
|
11
|
+
self.fc = FabricClientCore()
|
12
|
+
self.workspace_id = "fd3ba978-0b94-43e2-9f23-f65761e9ff34"
|
13
|
+
|
14
|
+
def test_git(self):
|
15
|
+
|
16
|
+
datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
17
|
+
ws2_name = "git" + datetime_str
|
18
|
+
self.fc.create_workspace(display_name=ws2_name)
|
19
|
+
ws2 = self.fc.get_workspace_by_name(name=ws2_name)
|
20
|
+
self.fc.assign_to_capacity(workspace_id=ws2.id, capacity_id="a089a991-221c-49be-a41e-9020198cf7af")
|
21
|
+
|
22
|
+
git_provider_details = {'organizationName': 'dasenf1860',
|
23
|
+
'projectName': 'fabrictest',
|
24
|
+
'gitProviderType': 'AzureDevOps',
|
25
|
+
'repositoryName': 'fabrictest',
|
26
|
+
'branchName': 'main',
|
27
|
+
'directoryName': '/folder1'}
|
28
|
+
|
29
|
+
status_code = self.fc.git_connect(workspace_id=ws2.id, git_provider_details=git_provider_details)
|
30
|
+
|
31
|
+
self.assertEqual(status_code, 204)
|
32
|
+
|
33
|
+
initialization_strategy = "PreferWorkspace"
|
34
|
+
|
35
|
+
status_code = self.fc.git_initialize_connection(workspace_id=ws2.id, initialization_strategy=initialization_strategy)
|
36
|
+
self.assertEqual(status_code, 200)
|
37
|
+
|
38
|
+
connection_details = self.fc.git_get_connection(workspace_id=ws2.id)
|
39
|
+
self.assertEqual(connection_details['gitConnectionState'], 'ConnectedAndInitialized')
|
40
|
+
|
41
|
+
status = self.fc.git_get_status(workspace_id=ws2.id)
|
42
|
+
self.assertTrue(len(status["changes"]) > 0)
|
43
|
+
|
44
|
+
status_code = self.fc.update_from_git(workspace_id=ws2.id, remote_commit_hash=status["remoteCommitHash"])
|
45
|
+
|
46
|
+
self.assertEqual(status_code, 202)
|
47
|
+
|
48
|
+
blubb_lakehouse = False
|
49
|
+
for item in ws2.list_items():
|
50
|
+
if item.type == "Lakehouse" and item.display_name == "blubb":
|
51
|
+
blubb_lakehouse = True
|
52
|
+
|
53
|
+
self.assertTrue(blubb_lakehouse)
|
54
|
+
|
55
|
+
status_code = self.fc.git_disconnect(workspace_id=ws2.id)
|
56
|
+
|
57
|
+
self.assertEqual(status_code, 204)
|
58
|
+
|
59
|
+
ws2.delete()
|
60
|
+
|
61
|
+
if __name__ == "__main__":
|
62
|
+
unittest.main()
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import unittest
|
2
|
+
from datetime import datetime
|
3
|
+
from dotenv import load_dotenv
|
4
|
+
from time import sleep
|
5
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
6
|
+
|
7
|
+
class TestFabricClientCore(unittest.TestCase):
|
8
|
+
|
9
|
+
def __init__(self, *args, **kwargs):
|
10
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
11
|
+
#load_dotenv()
|
12
|
+
self.fc = FabricClientCore()
|
13
|
+
self.workspace_id = "c3352d34-0b54-40f0-b204-cc964b1beb8d"
|
14
|
+
|
15
|
+
datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
16
|
+
self.item_name = "testitem" + datetime_str
|
17
|
+
self.item_type = "Notebook"
|
18
|
+
|
19
|
+
def test_item_end_to_end(self):
|
20
|
+
|
21
|
+
item = self.fc.create_item(display_name=self.item_name, type=self.item_type, workspace_id=self.workspace_id)
|
22
|
+
self.assertEqual(item.display_name, self.item_name)
|
23
|
+
self.assertEqual(item.type, self.item_type)
|
24
|
+
self.assertEqual(item.workspace_id, self.workspace_id)
|
25
|
+
self.assertEqual(item.description, "")
|
26
|
+
|
27
|
+
item = self.fc.get_item(workspace_id=self.workspace_id, item_id=item.id)
|
28
|
+
item_ = self.fc.get_item(workspace_id=self.workspace_id,
|
29
|
+
item_name=self.item_name, item_type=self.item_type)
|
30
|
+
self.assertEqual(item.id, item_.id)
|
31
|
+
self.assertEqual(item.display_name, self.item_name)
|
32
|
+
self.assertEqual(item.type, self.item_type)
|
33
|
+
self.assertEqual(item.workspace_id, self.workspace_id)
|
34
|
+
self.assertEqual(item.description, "")
|
35
|
+
|
36
|
+
item_list = self.fc.list_items(workspace_id=self.workspace_id)
|
37
|
+
self.assertTrue(len(item_list) > 0)
|
38
|
+
|
39
|
+
item_ids = [item_.id for item_ in item_list]
|
40
|
+
self.assertIn(item.id, item_ids)
|
41
|
+
|
42
|
+
self.fc.update_item(workspace_id=self.workspace_id, item_id=item.id, display_name=f"u{self.item_name}")
|
43
|
+
item = self.fc.get_item(workspace_id=self.workspace_id, item_id=item.id)
|
44
|
+
self.assertEqual(item.display_name, f"u{self.item_name}")
|
45
|
+
|
46
|
+
status_code = self.fc.delete_item(workspace_id=self.workspace_id, item_id=item.id)
|
47
|
+
|
48
|
+
self.assertAlmostEqual(status_code, 200)
|
49
|
+
|
50
|
+
def test_lakehouse(self):
|
51
|
+
|
52
|
+
lakehouse = self.fc.get_item(workspace_id=self.workspace_id, item_name="lakehouse1", item_type="Lakehouse")
|
53
|
+
item_id = lakehouse.id
|
54
|
+
date_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
55
|
+
table_name = f"table{date_str}"
|
56
|
+
|
57
|
+
|
58
|
+
status_code = self.fc.load_table(workspace_id=self.workspace_id, item_id=item_id, table_name=table_name,
|
59
|
+
path_type="File", relative_path="Files/folder1/titanic.csv")
|
60
|
+
|
61
|
+
self.assertEqual(status_code, 202)
|
62
|
+
|
63
|
+
table_list = self.fc.list_tables(workspace_id=self.workspace_id, item_id=item_id)
|
64
|
+
table_names = [table["name"] for table in table_list]
|
65
|
+
|
66
|
+
self.assertIn(table_name, table_names)
|
67
|
+
|
68
|
+
if __name__ == "__main__":
|
69
|
+
unittest.main()
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import unittest
|
2
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
3
|
+
|
4
|
+
class TestFabricClientCore(unittest.TestCase):
|
5
|
+
|
6
|
+
def __init__(self, *args, **kwargs):
|
7
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
8
|
+
#load_dotenv()
|
9
|
+
self.fc = FabricClientCore()
|
10
|
+
self.workspace_id = "c3352d34-0b54-40f0-b204-cc964b1beb8d"
|
11
|
+
self.item_id = "7e38f344-81df-4805-83b6-b9cc16830500"
|
12
|
+
|
13
|
+
|
14
|
+
def test_jobs_end_to_end(self):
|
15
|
+
job = self.fc.run_on_demand_item_job(workspace_id=self.workspace_id,
|
16
|
+
item_id=self.item_id,
|
17
|
+
job_type="RunNotebook")
|
18
|
+
|
19
|
+
self.assertEqual(job.item_id, self.item_id)
|
20
|
+
self.assertEqual(job.workspace_id, self.workspace_id)
|
21
|
+
self.assertEqual(job.job_type, "RunNotebook")
|
22
|
+
self.assertIn(job.status, ["NotStarted", "InProgress"])
|
23
|
+
self.assertEqual(job.invoke_type, "Manual")
|
24
|
+
|
25
|
+
job2 = self.fc.get_item_job_instance(workspace_id=self.workspace_id,
|
26
|
+
item_id=self.item_id,
|
27
|
+
job_instance_id=job.id)
|
28
|
+
|
29
|
+
self.assertEqual(job.id, job2.id)
|
30
|
+
|
31
|
+
status_code = self.fc.cancel_item_job_instance(workspace_id=self.workspace_id,
|
32
|
+
item_id=self.item_id,
|
33
|
+
job_instance_id=job.id)
|
34
|
+
|
35
|
+
self.assertEqual(status_code, 202)
|
36
|
+
|
37
|
+
if __name__ == "__main__":
|
38
|
+
unittest.main()
|
39
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import unittest
|
2
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
3
|
+
from datetime import datetime
|
4
|
+
from dotenv import load_dotenv
|
5
|
+
|
6
|
+
class TestFabricClientCore(unittest.TestCase):
|
7
|
+
|
8
|
+
def __init__(self, *args, **kwargs):
|
9
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
10
|
+
#load_dotenv()
|
11
|
+
self.fc = FabricClientCore()
|
12
|
+
self.workspace_id = "c3352d34-0b54-40f0-b204-cc964b1beb8d"
|
13
|
+
|
14
|
+
self.lakehouse_target = "cb4ca0b5-b53b-4879-b206-a53c35cbff55"
|
15
|
+
self.lakehouse_shortcut = "e2c09c89-bf97-4f71-bdeb-36338795ec36"
|
16
|
+
|
17
|
+
datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
18
|
+
self.shortcutname = "shortcut" + datetime_str
|
19
|
+
self.path_target = "Files/folder1"
|
20
|
+
self.path_shortcut = "Files/shortcutfolder"
|
21
|
+
|
22
|
+
self.target = {'oneLake': {'itemId': self.lakehouse_target,
|
23
|
+
'path': self.path_target,
|
24
|
+
'workspaceId': self.workspace_id}}
|
25
|
+
|
26
|
+
def test_shortcut_end_to_end(self):
|
27
|
+
|
28
|
+
item = self.fc.create_shortcut(workspace_id=self.workspace_id,
|
29
|
+
item_id=self.lakehouse_shortcut,
|
30
|
+
path=self.path_shortcut,
|
31
|
+
name=self.shortcutname,
|
32
|
+
target=self.target)
|
33
|
+
self.assertEqual(item.name, self.shortcutname)
|
34
|
+
self.assertEqual(item.path, self.path_shortcut)
|
35
|
+
self.assertEqual(item.target, self.target)
|
36
|
+
|
37
|
+
item = self.fc.get_shortcut(workspace_id=self.workspace_id,
|
38
|
+
item_id=self.lakehouse_shortcut,
|
39
|
+
path=self.path_shortcut,
|
40
|
+
name=self.shortcutname)
|
41
|
+
self.assertEqual(item.name, self.shortcutname)
|
42
|
+
self.assertEqual(item.path, self.path_shortcut)
|
43
|
+
self.assertEqual(item.target, self.target)
|
44
|
+
|
45
|
+
status_code = self.fc.delete_shortcut(workspace_id=self.workspace_id,
|
46
|
+
item_id=self.lakehouse_shortcut,
|
47
|
+
path=self.path_shortcut,
|
48
|
+
name=self.shortcutname)
|
49
|
+
|
50
|
+
self.assertAlmostEqual(status_code, 200)
|
51
|
+
|
52
|
+
if __name__ == "__main__":
|
53
|
+
unittest.main()
|
@@ -0,0 +1,146 @@
|
|
1
|
+
import unittest
|
2
|
+
from dotenv import load_dotenv
|
3
|
+
from datetime import datetime
|
4
|
+
from msfabricpysdkcore.coreapi import FabricClientCore
|
5
|
+
|
6
|
+
load_dotenv()
|
7
|
+
|
8
|
+
class TestFabricClientCore(unittest.TestCase):
|
9
|
+
|
10
|
+
def __init__(self, *args, **kwargs):
|
11
|
+
super(TestFabricClientCore, self).__init__(*args, **kwargs)
|
12
|
+
self.fc = FabricClientCore()
|
13
|
+
datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
|
14
|
+
self.display_name = "testws" + datetime_str
|
15
|
+
self.workspace_id = None
|
16
|
+
|
17
|
+
def test_end_to_end_workspace(self):
|
18
|
+
|
19
|
+
ws_created = self.fc.create_workspace(display_name=self.display_name,
|
20
|
+
description="test workspace",
|
21
|
+
exists_ok=False)
|
22
|
+
# Add assertions here to verify the result
|
23
|
+
self.assertEqual(ws_created.display_name, self.display_name)
|
24
|
+
self.workspace_id = ws_created.id
|
25
|
+
ws = self.fc.get_workspace_by_id(id = self.workspace_id)
|
26
|
+
self.assertEqual(ws.display_name, self.display_name)
|
27
|
+
self.assertEqual(ws.description, "test workspace")
|
28
|
+
|
29
|
+
# def test_assign_to_capacity(self):
|
30
|
+
|
31
|
+
result_status_code = self.fc.assign_to_capacity(workspace_id=ws.id,
|
32
|
+
capacity_id="41cb829c-c231-4e9f-b4fc-f9042a6f9840")
|
33
|
+
self.assertEqual(result_status_code, 202)
|
34
|
+
|
35
|
+
|
36
|
+
# def test_list_workspaces(self):
|
37
|
+
|
38
|
+
result = self.fc.list_workspaces()
|
39
|
+
display_names = [ws.display_name for ws in result]
|
40
|
+
self.assertIn(self.display_name, display_names)
|
41
|
+
|
42
|
+
for ws in result:
|
43
|
+
if ws.display_name == self.display_name:
|
44
|
+
self.assertEqual(ws.capacity_id, "41cb829c-c231-4e9f-b4fc-f9042a6f9840")
|
45
|
+
|
46
|
+
|
47
|
+
# def test_get_workspace_by_name(self):
|
48
|
+
|
49
|
+
workspace_name = self.display_name
|
50
|
+
ws = self.fc.get_workspace_by_name(name = workspace_name)
|
51
|
+
self.assertEqual(ws.display_name, self.display_name)
|
52
|
+
|
53
|
+
# def test_get_workspace_by_id(self):
|
54
|
+
ws = self.fc.get_workspace_by_id(id = self.workspace_id)
|
55
|
+
self.assertEqual(self.display_name, ws.display_name)
|
56
|
+
|
57
|
+
|
58
|
+
# def test_get_workspace(self):
|
59
|
+
result = self.fc.get_workspace_by_id(id = self.workspace_id)
|
60
|
+
self.assertEqual(result.display_name, self.display_name)
|
61
|
+
|
62
|
+
# def test_add_role_assignment(self):
|
63
|
+
result_status = self.fc.add_workspace_role_assignment(workspace_id = ws.id,
|
64
|
+
principal = {"id" : "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69",
|
65
|
+
"type" : "ServicePrincipal"},
|
66
|
+
role = 'Member')
|
67
|
+
|
68
|
+
self.assertEqual(result_status, 200)
|
69
|
+
|
70
|
+
# def test_get_workspace_role_assignments(self):
|
71
|
+
result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
|
72
|
+
self.assertTrue("value" in result)
|
73
|
+
self.assertTrue(len(result["value"]) == 2)
|
74
|
+
for user in result["value"]:
|
75
|
+
if user["principal"]["displayName"] == "fabrictestuser":
|
76
|
+
self.assertTrue(user["role"] == "Member")
|
77
|
+
|
78
|
+
# def test_update_workspace_role_assignment(self):
|
79
|
+
|
80
|
+
result_status_code = self.fc.update_workspace_role_assignment(workspace_id = ws.id,
|
81
|
+
role = "Contributor",
|
82
|
+
principal_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
|
83
|
+
|
84
|
+
self.assertEqual(result_status_code, 200)
|
85
|
+
|
86
|
+
result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
|
87
|
+
self.assertTrue("value" in result)
|
88
|
+
self.assertTrue(len(result["value"]) == 2)
|
89
|
+
for user in result["value"]:
|
90
|
+
if user["principal"]["displayName"] == "fabrictestuser":
|
91
|
+
self.assertTrue(user["role"] == "Contributor")
|
92
|
+
|
93
|
+
# def test_delete_role_assignment(self):
|
94
|
+
result_status_code = self.fc.delete_workspace_role_assignment(workspace_id = ws.id,
|
95
|
+
principal_id = "fe9dee5d-d244-4c93-8ea1-d5e6a2225c69")
|
96
|
+
self.assertEqual(result_status_code, 200)
|
97
|
+
|
98
|
+
# def test_get_workspace_role_assignments(self):
|
99
|
+
result = self.fc.get_workspace_role_assignments(workspace_id = ws.id)
|
100
|
+
self.assertTrue("value" in result)
|
101
|
+
self.assertTrue(len(result["value"]) == 1)
|
102
|
+
user = result["value"][0]
|
103
|
+
# self.assertTrue(user["principal"]["displayName"] == "fabricapi")
|
104
|
+
self.assertTrue(user["role"] == "Admin")
|
105
|
+
|
106
|
+
# def test_update_workspace(self):
|
107
|
+
ws_updated = self.fc.update_workspace(workspace_id=ws.id,
|
108
|
+
display_name="newname8912389u1293",
|
109
|
+
description="new description")
|
110
|
+
self.assertEqual(ws_updated.display_name, "newname8912389u1293")
|
111
|
+
self.assertEqual(ws_updated.description, "new description")
|
112
|
+
ws = self.fc.get_workspace_by_id(id = ws.id)
|
113
|
+
self.assertEqual(ws.display_name, "newname8912389u1293")
|
114
|
+
self.assertEqual(ws.description, "new description")
|
115
|
+
|
116
|
+
# def test_unassign_from_capacity(self):
|
117
|
+
|
118
|
+
result_status_code = self.fc.unassign_from_capacity(workspace_id=ws.id)
|
119
|
+
self.assertEqual(result_status_code, 202)
|
120
|
+
ws = self.fc.get_workspace_by_id(ws.id)
|
121
|
+
self.assertEqual(ws.capacity_id, None)
|
122
|
+
|
123
|
+
# def test_delete_workspace(self):
|
124
|
+
result_status = self.fc.delete_workspace(display_name="newname8912389u1293")
|
125
|
+
self.assertEqual(result_status, 200)
|
126
|
+
|
127
|
+
def test_list_capacities(self):
|
128
|
+
result = self.fc.list_capacities()
|
129
|
+
self.assertTrue(len(result) > 0)
|
130
|
+
cap_ids = [cap.id for cap in result]
|
131
|
+
self.assertIn("41cb829c-c231-4e9f-b4fc-f9042a6f9840", cap_ids)
|
132
|
+
|
133
|
+
def test_get_capacity(self):
|
134
|
+
capacity = self.fc.get_capacity(capacity_id = "41cb829c-c231-4e9f-b4fc-f9042a6f9840")
|
135
|
+
self.assertEqual(capacity.id, "41cb829c-c231-4e9f-b4fc-f9042a6f9840")
|
136
|
+
|
137
|
+
cap = self.fc.get_capacity(capacity_name= capacity.display_name)
|
138
|
+
|
139
|
+
self.assertEqual(capacity.id, cap.id)
|
140
|
+
self.assertIsNotNone(cap.state)
|
141
|
+
self.assertIsNotNone(cap.sku)
|
142
|
+
self.assertIsNotNone(cap.region)
|
143
|
+
|
144
|
+
|
145
|
+
if __name__ == "__main__":
|
146
|
+
unittest.main()
|
msfabricpysdkcore/workspace.py
CHANGED
@@ -33,6 +33,9 @@ class Workspace:
|
|
33
33
|
}
|
34
34
|
return json.dumps(dict_, indent=2)
|
35
35
|
|
36
|
+
def __repr__(self) -> str:
|
37
|
+
return self.__str__()
|
38
|
+
|
36
39
|
def get_role_assignments(self):
|
37
40
|
"""Get role assignments for the workspace"""
|
38
41
|
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/roleAssignments"
|
@@ -240,14 +243,29 @@ class Workspace:
|
|
240
243
|
print(response.text)
|
241
244
|
raise Exception(f"Error creating item: {response.text}")
|
242
245
|
break
|
243
|
-
|
246
|
+
|
244
247
|
item_dict = json.loads(response.text)
|
248
|
+
if item_dict is None:
|
249
|
+
print("Item not returned by API, trying to get it by name")
|
250
|
+
return self.get_item_by_name(display_name, type)
|
245
251
|
return Item.from_dict(item_dict, auth=self.auth)
|
246
252
|
|
247
253
|
|
248
|
-
def
|
254
|
+
def get_item_by_name(self, item_name, item_type):
|
255
|
+
"""Get an item from a workspace by name"""
|
256
|
+
ws_items = self.list_items()
|
257
|
+
for item in ws_items:
|
258
|
+
if item.display_name == item_name and item.type == item_type:
|
259
|
+
return item
|
260
|
+
|
261
|
+
def get_item(self, item_id = None, item_name = None, item_type = None):
|
249
262
|
# GET https://api.fabric.microsoft.com/v1/workspaces/{workspaceId}/items/{itemId}
|
250
263
|
"""Get an item from a workspace"""
|
264
|
+
if item_id is None and item_name is not None and item_type is not None:
|
265
|
+
return self.get_item_by_name(item_name, item_type)
|
266
|
+
elif item_id is None:
|
267
|
+
raise Exception("item_id or the combination item_name + item_type is required")
|
268
|
+
|
251
269
|
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items/{item_id}"
|
252
270
|
|
253
271
|
for _ in range(10):
|
@@ -259,7 +277,7 @@ class Workspace:
|
|
259
277
|
if response.status_code not in (200, 429):
|
260
278
|
print(response.status_code)
|
261
279
|
print(response.text)
|
262
|
-
raise Exception(f"Error getting item
|
280
|
+
raise Exception(f"Error getting item: {response.text}")
|
263
281
|
break
|
264
282
|
|
265
283
|
item_dict = json.loads(response.text)
|
@@ -268,11 +286,15 @@ class Workspace:
|
|
268
286
|
def delete_item(self, item_id):
|
269
287
|
"""Delete an item from a workspace"""
|
270
288
|
return self.get_item(item_id).delete()
|
289
|
+
|
271
290
|
|
272
|
-
def list_items(self):
|
291
|
+
def list_items(self, continuationToken = None):
|
273
292
|
"""List items in a workspace"""
|
274
293
|
url = f"https://api.fabric.microsoft.com/v1/workspaces/{self.id}/items"
|
275
294
|
|
295
|
+
if continuationToken:
|
296
|
+
url = f"{url}?continuationToken={continuationToken}"
|
297
|
+
|
276
298
|
for _ in range(10):
|
277
299
|
response = requests.get(url=url, headers=self.auth.get_headers())
|
278
300
|
if response.status_code == 429:
|
@@ -284,8 +306,16 @@ class Workspace:
|
|
284
306
|
print(response.text)
|
285
307
|
raise Exception(f"Error listing items: {response.text}")
|
286
308
|
break
|
287
|
-
|
288
|
-
|
309
|
+
|
310
|
+
resp_dict = json.loads(response.text)
|
311
|
+
items = resp_dict["value"]
|
312
|
+
items = [Item.from_dict(item, auth=self.auth) for item in items]
|
313
|
+
|
314
|
+
if "continuationToken" in resp_dict:
|
315
|
+
item_list_next = self.list_items(continuationToken=resp_dict["continuationToken"])
|
316
|
+
items.extend(item_list_next)
|
317
|
+
|
318
|
+
return items
|
289
319
|
|
290
320
|
def get_item_definition(self, item_id):
|
291
321
|
"""Get the definition of an item from a workspace"""
|
@@ -478,4 +508,14 @@ class Workspace:
|
|
478
508
|
raise Exception(f"Error updating from git: {response.text}")
|
479
509
|
break
|
480
510
|
|
481
|
-
return response.status_code
|
511
|
+
return response.status_code
|
512
|
+
|
513
|
+
def list_tables(self, item_id):
|
514
|
+
return self.get_item(item_id=item_id).list_tables()
|
515
|
+
|
516
|
+
def load_table(self, item_id, table_name, path_type, relative_path,
|
517
|
+
file_extension = None, format_options = None,
|
518
|
+
mode = None, recursive = None, wait_for_completion = True):
|
519
|
+
return self.get_item(item_id).load_table(table_name, path_type, relative_path,
|
520
|
+
file_extension, format_options,
|
521
|
+
mode, recursive, wait_for_completion)
|