superb-ai-onprem 0.1.5__py3-none-any.whl → 0.2.0__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.
Potentially problematic release.
This version of superb-ai-onprem might be problematic. Click here for more details.
- spb_onprem/__init__.py +18 -2
- spb_onprem/_version.py +2 -2
- spb_onprem/activities/__init__.py +0 -0
- spb_onprem/activities/entities/__init__.py +10 -0
- spb_onprem/activities/entities/activity.py +39 -0
- spb_onprem/activities/entities/activity_history.py +31 -0
- spb_onprem/activities/params/__init__.py +23 -0
- spb_onprem/activities/params/activities.py +53 -0
- spb_onprem/activities/params/activity.py +42 -0
- spb_onprem/activities/params/create_activity.py +80 -0
- spb_onprem/activities/params/delete_activity.py +23 -0
- spb_onprem/activities/params/start_activity.py +59 -0
- spb_onprem/activities/params/update_activity.py +79 -0
- spb_onprem/activities/params/update_activity_history.py +54 -0
- spb_onprem/activities/queries.py +226 -0
- spb_onprem/activities/service.py +315 -0
- spb_onprem/base_model.py +2 -3
- spb_onprem/data/service.py +1 -1
- spb_onprem/entities.py +12 -0
- spb_onprem/searches.py +6 -0
- spb_onprem/slices/params/slices.py +1 -1
- {superb_ai_onprem-0.1.5.dist-info → superb_ai_onprem-0.2.0.dist-info}/METADATA +1 -1
- {superb_ai_onprem-0.1.5.dist-info → superb_ai_onprem-0.2.0.dist-info}/RECORD +31 -12
- {superb_ai_onprem-0.1.5.dist-info → superb_ai_onprem-0.2.0.dist-info}/top_level.txt +1 -0
- tests/__init__.py +1 -0
- tests/activities/__init__.py +1 -0
- tests/activities/real_test.py +66 -0
- tests/activities/test_params.py +67 -0
- tests/activities/test_service.py +139 -0
- {superb_ai_onprem-0.1.5.dist-info → superb_ai_onprem-0.2.0.dist-info}/WHEEL +0 -0
- {superb_ai_onprem-0.1.5.dist-info → superb_ai_onprem-0.2.0.dist-info}/licenses/LICENSE +0 -0
tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from spb_onprem import (
|
|
2
|
+
DatasetService,
|
|
3
|
+
Dataset,
|
|
4
|
+
ActivityService,
|
|
5
|
+
Activity,
|
|
6
|
+
ActivityHistory,
|
|
7
|
+
ActivityStatus,
|
|
8
|
+
ActivitySchema,
|
|
9
|
+
SchemaType,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_activity_service():
|
|
14
|
+
dataset_service = DatasetService()
|
|
15
|
+
dataset = dataset_service.get_dataset(
|
|
16
|
+
dataset_id="01JPM6NR1APMBXJNC0YW72S1FN"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
print(dataset)
|
|
20
|
+
|
|
21
|
+
activity_service = ActivityService()
|
|
22
|
+
cursor = None
|
|
23
|
+
assign_data_slice_activity = None
|
|
24
|
+
while True:
|
|
25
|
+
(described_activities, cursor, _) = activity_service.get_activities(
|
|
26
|
+
dataset_id=dataset.id,
|
|
27
|
+
cursor=cursor,
|
|
28
|
+
length=50
|
|
29
|
+
)
|
|
30
|
+
for activity in described_activities:
|
|
31
|
+
if activity.activity_type == "ASSIGN_DATA_TO_SLICE":
|
|
32
|
+
assign_data_slice_activity = activity
|
|
33
|
+
break
|
|
34
|
+
if cursor is None:
|
|
35
|
+
break
|
|
36
|
+
|
|
37
|
+
print(assign_data_slice_activity.parameter_schema)
|
|
38
|
+
|
|
39
|
+
activity_history = activity_service.start_activity(
|
|
40
|
+
dataset_id=dataset.id,
|
|
41
|
+
activity_id=assign_data_slice_activity.id,
|
|
42
|
+
parameters={
|
|
43
|
+
"dataset_id": dataset.id,
|
|
44
|
+
"slice_name": "sdk_test_slice",
|
|
45
|
+
"slice_description": "sdk_test_slice_description",
|
|
46
|
+
"filter": {
|
|
47
|
+
"must": {
|
|
48
|
+
"keyContains": "validation_v5/87d37e96-0bab3a63.jpg"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"filter_type": "DATA",
|
|
52
|
+
"is_new_slice": True,
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
print(activity_history)
|
|
56
|
+
|
|
57
|
+
activity_service.update_activity_history_status(
|
|
58
|
+
activity_history_id=activity_history.id,
|
|
59
|
+
status=ActivityStatus.FAILED,
|
|
60
|
+
meta={
|
|
61
|
+
"sdk_test": "sdk_test_value"
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
test_activity_service()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from spb_onprem.activities.params.update_activity_history import update_activity_history_params
|
|
3
|
+
from spb_onprem.activities.entities import ActivityStatus
|
|
4
|
+
from spb_onprem.exceptions import BadParameterError
|
|
5
|
+
from spb_onprem.base_types import Undefined
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestUpdateActivityHistoryParams:
|
|
9
|
+
def test_update_activity_history_params_with_status(self):
|
|
10
|
+
# Given
|
|
11
|
+
activity_history_id = "test_history_id"
|
|
12
|
+
status = ActivityStatus.SUCCESS
|
|
13
|
+
meta = {"key": "value"}
|
|
14
|
+
|
|
15
|
+
# When
|
|
16
|
+
params = update_activity_history_params(
|
|
17
|
+
activity_history_id=activity_history_id,
|
|
18
|
+
status=status,
|
|
19
|
+
meta=meta
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# Then
|
|
23
|
+
assert params["activity_history_id"] == activity_history_id
|
|
24
|
+
assert params["status"] == status
|
|
25
|
+
assert params["meta"] == meta
|
|
26
|
+
assert "progress" not in params
|
|
27
|
+
|
|
28
|
+
def test_update_activity_history_params_with_progress(self):
|
|
29
|
+
# Given
|
|
30
|
+
activity_history_id = "test_history_id"
|
|
31
|
+
progress = {"current": 50, "total": 100}
|
|
32
|
+
|
|
33
|
+
# When
|
|
34
|
+
params = update_activity_history_params(
|
|
35
|
+
activity_history_id=activity_history_id,
|
|
36
|
+
progress=progress
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Then
|
|
40
|
+
assert params["activity_history_id"] == activity_history_id
|
|
41
|
+
assert params["progress"] == progress
|
|
42
|
+
assert "status" not in params
|
|
43
|
+
assert "meta" not in params
|
|
44
|
+
|
|
45
|
+
def test_update_activity_history_params_without_required_fields(self):
|
|
46
|
+
# Given
|
|
47
|
+
activity_history_id = None
|
|
48
|
+
|
|
49
|
+
# When/Then
|
|
50
|
+
with pytest.raises(BadParameterError) as exc_info:
|
|
51
|
+
update_activity_history_params(
|
|
52
|
+
activity_history_id=activity_history_id
|
|
53
|
+
)
|
|
54
|
+
assert str(exc_info.value) == "Activity history ID is required"
|
|
55
|
+
|
|
56
|
+
def test_update_activity_history_params_without_status_or_progress(self):
|
|
57
|
+
# Given
|
|
58
|
+
activity_history_id = "test_history_id"
|
|
59
|
+
|
|
60
|
+
# When/Then
|
|
61
|
+
with pytest.raises(BadParameterError) as exc_info:
|
|
62
|
+
update_activity_history_params(
|
|
63
|
+
activity_history_id=activity_history_id,
|
|
64
|
+
status=Undefined,
|
|
65
|
+
progress=Undefined
|
|
66
|
+
)
|
|
67
|
+
assert str(exc_info.value) == "Either status or progress must be provided"
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
from spb_onprem.activities.service import ActivityService
|
|
5
|
+
from spb_onprem.activities.entities import Activity, ActivityHistory, ActivityStatus
|
|
6
|
+
from spb_onprem.base_types import Undefined
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def activity_service():
|
|
11
|
+
return ActivityService()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestActivityService:
|
|
15
|
+
def test_create_activity(self, activity_service):
|
|
16
|
+
# Given
|
|
17
|
+
mock_response = {
|
|
18
|
+
"createJob": {
|
|
19
|
+
"id": "test_id",
|
|
20
|
+
"type": "test_type",
|
|
21
|
+
"name": "test_name",
|
|
22
|
+
"description": "test_description"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
activity_service.request_gql = MagicMock(return_value=mock_response)
|
|
26
|
+
|
|
27
|
+
# When
|
|
28
|
+
activity = activity_service.create_activity(
|
|
29
|
+
activity_type="test_type",
|
|
30
|
+
name="test_name",
|
|
31
|
+
description="test_description"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Then
|
|
35
|
+
assert isinstance(activity, Activity)
|
|
36
|
+
assert activity.id == "test_id"
|
|
37
|
+
assert activity.type == "test_type"
|
|
38
|
+
assert activity.name == "test_name"
|
|
39
|
+
assert activity.description == "test_description"
|
|
40
|
+
|
|
41
|
+
def test_get_activities(self, activity_service):
|
|
42
|
+
# Given
|
|
43
|
+
mock_response = {
|
|
44
|
+
"jobs": {
|
|
45
|
+
"activities": [
|
|
46
|
+
{
|
|
47
|
+
"id": "test_id_1",
|
|
48
|
+
"type": "test_type",
|
|
49
|
+
"name": "test_name_1"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "test_id_2",
|
|
53
|
+
"type": "test_type",
|
|
54
|
+
"name": "test_name_2"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"next": "next_cursor",
|
|
58
|
+
"totalCount": 2
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
activity_service.request_gql = MagicMock(return_value=mock_response)
|
|
62
|
+
|
|
63
|
+
# When
|
|
64
|
+
activities, next_cursor, total_count = activity_service.get_activities(
|
|
65
|
+
dataset_id="test_dataset_id"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Then
|
|
69
|
+
assert len(activities) == 2
|
|
70
|
+
assert all(isinstance(activity, Activity) for activity in activities)
|
|
71
|
+
assert next_cursor == "next_cursor"
|
|
72
|
+
assert total_count == 2
|
|
73
|
+
|
|
74
|
+
def test_start_activity(self, activity_service):
|
|
75
|
+
# Given
|
|
76
|
+
mock_response = {
|
|
77
|
+
"startJob": {
|
|
78
|
+
"id": "test_history_id",
|
|
79
|
+
"jobId": "test_activity_id",
|
|
80
|
+
"status": ActivityStatus.RUNNING.value
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
activity_service.request_gql = MagicMock(return_value=mock_response)
|
|
84
|
+
|
|
85
|
+
# When
|
|
86
|
+
activity_history = activity_service.start_activity(
|
|
87
|
+
dataset_id="test_dataset_id",
|
|
88
|
+
activity_id="test_activity_id"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Then
|
|
92
|
+
assert isinstance(activity_history, ActivityHistory)
|
|
93
|
+
assert activity_history.id == "test_history_id"
|
|
94
|
+
assert activity_history.activity_id == "test_activity_id"
|
|
95
|
+
assert activity_history.status == ActivityStatus.RUNNING
|
|
96
|
+
|
|
97
|
+
def test_update_activity_history_status(self, activity_service):
|
|
98
|
+
# Given
|
|
99
|
+
mock_response = {
|
|
100
|
+
"updateJobHistory": {
|
|
101
|
+
"id": "test_history_id",
|
|
102
|
+
"jobId": "test_activity_id",
|
|
103
|
+
"status": ActivityStatus.SUCCESS.value
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
activity_service.request_gql = MagicMock(return_value=mock_response)
|
|
107
|
+
|
|
108
|
+
# When
|
|
109
|
+
activity_history = activity_service.update_activity_history_status(
|
|
110
|
+
activity_history_id="test_history_id",
|
|
111
|
+
status=ActivityStatus.SUCCESS
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Then
|
|
115
|
+
assert isinstance(activity_history, ActivityHistory)
|
|
116
|
+
assert activity_history.id == "test_history_id"
|
|
117
|
+
assert activity_history.status == ActivityStatus.SUCCESS
|
|
118
|
+
|
|
119
|
+
def test_update_activity_history_progress(self, activity_service):
|
|
120
|
+
# Given
|
|
121
|
+
mock_response = {
|
|
122
|
+
"updateJobHistory": {
|
|
123
|
+
"id": "test_history_id",
|
|
124
|
+
"jobId": "test_activity_id",
|
|
125
|
+
"progress": {"current": 50, "total": 100}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
activity_service.request_gql = MagicMock(return_value=mock_response)
|
|
129
|
+
|
|
130
|
+
# When
|
|
131
|
+
activity_history = activity_service.update_activity_history_progress(
|
|
132
|
+
activity_history_id="test_history_id",
|
|
133
|
+
progress={"current": 50, "total": 100}
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Then
|
|
137
|
+
assert isinstance(activity_history, ActivityHistory)
|
|
138
|
+
assert activity_history.id == "test_history_id"
|
|
139
|
+
assert activity_history.progress == {"current": 50, "total": 100}
|
|
File without changes
|
|
File without changes
|