splight-lib 5.6.5.dev0__tar.gz → 5.7.0__tar.gz
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.
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/PKG-INFO +1 -1
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/pyproject.toml +1 -1
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/classmap.py +3 -1
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/remote_client.py +21 -11
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/exceptions.py +8 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/tests/test_database.py +5 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/tests/test_datalake.py +4 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/__init__.py +2 -1
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/asset.py +30 -2
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/base.py +2 -2
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/exceptions.py +4 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/hub_solution.py +10 -1
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/test_database_model.py +52 -26
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/LICENSE.txt +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/README.md +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/abstract/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/abstract/client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/auth/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/auth/exceptions.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/auth/mac_auth.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/auth/token.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/abstract.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/builder.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/database/local_client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/abstract.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/buffer.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/builder.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/exceptions.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/local_client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/remote_client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/datalake/schemas.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/file_handler.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/filter.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/hub/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/hub/abstract.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/client/hub/client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/abstract.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/exceptions.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/spec.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/tests/test_abstract.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/component/tests/test_spec.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/constants.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/encryption.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/engine.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/exceptions.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/scheduling.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/task.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/tests/test_execution.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/tests/test_scheduling.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/execution/trigger.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/_internal.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/component.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/constants.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/logging.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/logging/tests/test_logging.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/alert.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/attribute.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/component.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/dashboard.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/data_address.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/file.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/function.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/generic.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/hub.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/metadata.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/native.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/pipeline.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/secret.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/models.json +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/test_component_object_instance.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/test_metadata.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/test_models.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/client.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/exceptions.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/tests/test_restclient.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/types.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/settings.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/stringcase.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/testing/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/tests/FakeProc.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/tests/asset_geometries.json +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/tests/test_api_contracts.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/tests/test_encryption.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/utils/__init__.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/utils/custom_model.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/utils/hub.py +0 -0
- {splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/version.py +0 -0
|
@@ -3,7 +3,9 @@ from splight_lib.constants import ENGINE_PREFIX, HUB_PREFIX
|
|
|
3
3
|
MODEL_NAME_MAP = {
|
|
4
4
|
"advancedfilter": f"{ENGINE_PREFIX}/alert/advancedfilters/",
|
|
5
5
|
"alert": f"{ENGINE_PREFIX}/alert/alerts/",
|
|
6
|
-
"asset": f"{ENGINE_PREFIX}/assets/",
|
|
6
|
+
"asset": f"{ENGINE_PREFIX}/asset/assets/",
|
|
7
|
+
"assetkind": f"{ENGINE_PREFIX}/asset/kinds/",
|
|
8
|
+
# TODO: update to new endpoint for attributes
|
|
7
9
|
"attribute": f"{ENGINE_PREFIX}/attributes/",
|
|
8
10
|
"metadata": f"{ENGINE_PREFIX}/metadata/",
|
|
9
11
|
"chart": f"{ENGINE_PREFIX}/dashboard/charts/",
|
|
@@ -20,6 +20,7 @@ from splight_lib.client.exceptions import (
|
|
|
20
20
|
InstanceNotFound,
|
|
21
21
|
InvalidModel,
|
|
22
22
|
InvalidModelName,
|
|
23
|
+
RequestError,
|
|
23
24
|
)
|
|
24
25
|
from splight_lib.constants import ENGINE_PREFIX
|
|
25
26
|
from splight_lib.logging._internal import LogTags, get_splight_logger
|
|
@@ -116,7 +117,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
116
117
|
api_path = self._get_api_path(resource_name)
|
|
117
118
|
url = self._base_url / api_path / f"{id}/"
|
|
118
119
|
response = self._restclient.delete(url)
|
|
119
|
-
response.
|
|
120
|
+
if response.is_error:
|
|
121
|
+
raise RequestError(response.status_code, response.text)
|
|
120
122
|
|
|
121
123
|
@retry(SPLIGHT_REQUEST_EXCEPTIONS, tries=3, delay=1)
|
|
122
124
|
def _get(
|
|
@@ -155,7 +157,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
155
157
|
api_path = api_path.format_map({"prefix": ENGINE_PREFIX, **instance})
|
|
156
158
|
url = self._base_url / api_path
|
|
157
159
|
response = self._restclient.post(url, json=instance)
|
|
158
|
-
response.
|
|
160
|
+
if response.is_error:
|
|
161
|
+
raise RequestError(response.status_code, response.text)
|
|
159
162
|
return response.json()
|
|
160
163
|
|
|
161
164
|
def _retrieve_multiple(
|
|
@@ -180,8 +183,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
180
183
|
response = self._restclient.get(url)
|
|
181
184
|
if response.status_code == codes.NOT_FOUND:
|
|
182
185
|
raise InstanceNotFound(resource_name, id)
|
|
183
|
-
|
|
184
|
-
response.
|
|
186
|
+
elif response.is_error:
|
|
187
|
+
raise RequestError(response.status_code, response.text)
|
|
185
188
|
return response.json()
|
|
186
189
|
|
|
187
190
|
@retry(SPLIGHT_REQUEST_EXCEPTIONS, tries=3, delay=1)
|
|
@@ -214,7 +217,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
214
217
|
resource_id = instance.get("id")
|
|
215
218
|
url = self._base_url / api_path / f"{resource_id}/download_url/"
|
|
216
219
|
response = self._restclient.get(url)
|
|
217
|
-
response.
|
|
220
|
+
if response.is_error:
|
|
221
|
+
raise RequestError(response.status_code, response.text)
|
|
218
222
|
download_url = response.json().get("url")
|
|
219
223
|
|
|
220
224
|
file = NamedTemporaryFile(mode="wb+", suffix=instance["name"])
|
|
@@ -253,7 +257,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
253
257
|
def _list(self, url: furl, **kwargs) -> PaginatedResponse:
|
|
254
258
|
params = self._parse_params(**kwargs)
|
|
255
259
|
response = self._restclient.get(url, params=params)
|
|
256
|
-
response.
|
|
260
|
+
if response.is_error:
|
|
261
|
+
raise RequestError(response.status_code, response.text)
|
|
257
262
|
return response.json()
|
|
258
263
|
|
|
259
264
|
def _create(
|
|
@@ -281,7 +286,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
281
286
|
req_args = {"json": instance}
|
|
282
287
|
|
|
283
288
|
response = self._restclient.post(url, **req_args)
|
|
284
|
-
response.
|
|
289
|
+
if response.is_error:
|
|
290
|
+
raise RequestError(response.status_code, response.text)
|
|
285
291
|
instance = response.json()
|
|
286
292
|
logger.debug(
|
|
287
293
|
"Instance %s created", instance["id"], tags=LogTags.DATABASE
|
|
@@ -318,12 +324,14 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
318
324
|
|
|
319
325
|
response = self._restclient.put(url, **req_args)
|
|
320
326
|
|
|
321
|
-
response.
|
|
327
|
+
if response.is_error:
|
|
328
|
+
raise RequestError(response.status_code, response.text)
|
|
322
329
|
return response.json()
|
|
323
330
|
|
|
324
331
|
def _create_file(self, instance: Dict, url: furl):
|
|
325
332
|
response = self._restclient.post(url, data=instance)
|
|
326
|
-
response.
|
|
333
|
+
if response.is_error:
|
|
334
|
+
raise RequestError(response.status_code, response.text)
|
|
327
335
|
file_path = instance["file"]
|
|
328
336
|
# Check is this is handled somewher
|
|
329
337
|
created_instance = response.json()
|
|
@@ -335,7 +343,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
335
343
|
resource_id = instance.get("id")
|
|
336
344
|
url = self._base_url / api_path / f"{resource_id}/upload_url/"
|
|
337
345
|
response = self._restclient.get(url)
|
|
338
|
-
response.
|
|
346
|
+
if response.is_error:
|
|
347
|
+
raise RequestError(response.status_code, response.text)
|
|
339
348
|
upload_url = response.json().get("url")
|
|
340
349
|
file = open(file_path, "rb")
|
|
341
350
|
file_name = instance["name"]
|
|
@@ -345,7 +354,8 @@ class RemoteDatabaseClient(AbstractDatabaseClient, AbstractRemoteClient):
|
|
|
345
354
|
upload_url,
|
|
346
355
|
files=file,
|
|
347
356
|
)
|
|
348
|
-
response.
|
|
357
|
+
if response.is_error:
|
|
358
|
+
raise RequestError(response.status_code, response.text)
|
|
349
359
|
logger.debug(
|
|
350
360
|
"File uploaded succesfully %s.", resource_id, tags=LogTags.DATABASE
|
|
351
361
|
)
|
|
@@ -16,6 +16,14 @@ SPLIGHT_REQUEST_EXCEPTIONS = (
|
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
class RequestError(Exception):
|
|
20
|
+
def __init__(self, status_code: int, text: str):
|
|
21
|
+
self._msg = f"Got an error status code: {status_code} - {text}"
|
|
22
|
+
|
|
23
|
+
def __str__(self) -> str:
|
|
24
|
+
return self._msg
|
|
25
|
+
|
|
26
|
+
|
|
19
27
|
class InvalidModelName(Exception):
|
|
20
28
|
def __init__(self, model_name: str):
|
|
21
29
|
self._msg = f"Model {model_name} is not a valid database model"
|
|
@@ -21,6 +21,10 @@ class MockResponse:
|
|
|
21
21
|
def __init__(self, json_data):
|
|
22
22
|
self.json_data = json_data
|
|
23
23
|
|
|
24
|
+
@property
|
|
25
|
+
def is_error(self) -> bool:
|
|
26
|
+
return False if self.status_code < 400 else True
|
|
27
|
+
|
|
24
28
|
def raise_for_status(self):
|
|
25
29
|
return None
|
|
26
30
|
|
|
@@ -115,6 +119,7 @@ def test_delete(mocker: MockerFixture):
|
|
|
115
119
|
mock_delete = mocker.patch.object(
|
|
116
120
|
SplightRestClient,
|
|
117
121
|
"delete",
|
|
122
|
+
return_value=MockResponse({}),
|
|
118
123
|
)
|
|
119
124
|
client.delete("alert", "instance_id")
|
|
120
125
|
mock_delete.assert_called_once()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from splight_lib.models.alert import Alert, AlertItem
|
|
2
|
-
from splight_lib.models.asset import Asset
|
|
2
|
+
from splight_lib.models.asset import Asset, AssetKind
|
|
3
3
|
from splight_lib.models.attribute import Attribute
|
|
4
4
|
from splight_lib.models.component import (
|
|
5
5
|
Component,
|
|
@@ -30,6 +30,7 @@ __all__ = [
|
|
|
30
30
|
Alert,
|
|
31
31
|
AlertItem,
|
|
32
32
|
Asset,
|
|
33
|
+
AssetKind,
|
|
33
34
|
Attribute,
|
|
34
35
|
Boolean,
|
|
35
36
|
Chart,
|
|
@@ -2,16 +2,42 @@ import warnings
|
|
|
2
2
|
from typing import Any, List, Optional, Tuple
|
|
3
3
|
|
|
4
4
|
from geojson_pydantic import GeometryCollection
|
|
5
|
-
from pydantic import Field
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
6
|
|
|
7
7
|
from splight_lib.constants import DESCRIPTION_MAX_LENGTH
|
|
8
8
|
from splight_lib.models.attribute import Attribute
|
|
9
9
|
from splight_lib.models.base import SplightDatabaseBaseModel
|
|
10
|
+
from splight_lib.models.exceptions import MethodNotAllowed
|
|
10
11
|
from splight_lib.models.metadata import Metadata
|
|
11
12
|
|
|
12
13
|
warnings.filterwarnings("ignore", category=UserWarning)
|
|
13
14
|
|
|
14
15
|
|
|
16
|
+
class AssetRepr(BaseModel):
|
|
17
|
+
id: str
|
|
18
|
+
name: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class AssetRelationship(BaseModel):
|
|
22
|
+
id: str
|
|
23
|
+
name: str
|
|
24
|
+
description: Optional[str] = None
|
|
25
|
+
related_asset_kind: Optional[str] = None
|
|
26
|
+
asset: AssetRepr
|
|
27
|
+
related_asset: AssetRepr
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AssetKind(SplightDatabaseBaseModel):
|
|
31
|
+
id: Optional[str] = None
|
|
32
|
+
name: str
|
|
33
|
+
|
|
34
|
+
def save(self):
|
|
35
|
+
raise MethodNotAllowed("AssetKind objects are read-only")
|
|
36
|
+
|
|
37
|
+
def delete(self):
|
|
38
|
+
raise MethodNotAllowed("AssetKind objects are read-only")
|
|
39
|
+
|
|
40
|
+
|
|
15
41
|
class Asset(SplightDatabaseBaseModel):
|
|
16
42
|
id: Optional[str] = None
|
|
17
43
|
name: str
|
|
@@ -23,7 +49,9 @@ class Asset(SplightDatabaseBaseModel):
|
|
|
23
49
|
metadata: List[Metadata] = []
|
|
24
50
|
geometry: Optional[GeometryCollection] = None
|
|
25
51
|
centroid_coordinates: Optional[Tuple[float, float]] = None
|
|
26
|
-
|
|
52
|
+
kind: Optional[AssetKind] = None
|
|
53
|
+
related_to: List[AssetRelationship] = []
|
|
54
|
+
related_from: List[AssetRelationship] = []
|
|
27
55
|
|
|
28
56
|
def set_attribute(self, attribute: Attribute, value: Any, value_type: str):
|
|
29
57
|
new_value = self._db_client.operate(
|
|
@@ -41,8 +41,8 @@ class SplightDatabaseBaseModel(BaseModel):
|
|
|
41
41
|
self.model_dump(exclude_none=True, mode="json"),
|
|
42
42
|
files=files_dict,
|
|
43
43
|
)
|
|
44
|
-
|
|
45
|
-
self
|
|
44
|
+
for field in self.model_fields:
|
|
45
|
+
setattr(self, field, saved.get(field))
|
|
46
46
|
|
|
47
47
|
def delete(self):
|
|
48
48
|
self._db_client.delete(
|
|
@@ -18,9 +18,17 @@ class HubSolution(SplightDatabaseBaseModel):
|
|
|
18
18
|
main_file: Optional[FilePath] = Field(default=None, exclude=True)
|
|
19
19
|
variables_file: Optional[FilePath] = Field(default=None, exclude=True)
|
|
20
20
|
values_file: Optional[FilePath] = Field(default=None, exclude=True)
|
|
21
|
+
readme_file: Optional[FilePath] = Field(default=None, exclude=True)
|
|
21
22
|
|
|
22
23
|
def save(self) -> None:
|
|
23
|
-
if not all(
|
|
24
|
+
if not all(
|
|
25
|
+
[
|
|
26
|
+
self.main_file,
|
|
27
|
+
self.variables_file,
|
|
28
|
+
self.values_file,
|
|
29
|
+
self.readme_file,
|
|
30
|
+
]
|
|
31
|
+
):
|
|
24
32
|
raise ValueError("Missing one of the required files")
|
|
25
33
|
return super().save()
|
|
26
34
|
|
|
@@ -29,4 +37,5 @@ class HubSolution(SplightDatabaseBaseModel):
|
|
|
29
37
|
"main_file": self.main_file,
|
|
30
38
|
"variables_file": self.variables_file,
|
|
31
39
|
"values_file": self.values_file,
|
|
40
|
+
"readme_file": self.readme_file,
|
|
32
41
|
}
|
{splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/models/tests/test_database_model.py
RENAMED
|
@@ -9,8 +9,8 @@ from uuid import uuid4 # noqa: E402
|
|
|
9
9
|
|
|
10
10
|
import pytest # noqa: E402
|
|
11
11
|
|
|
12
|
-
from splight_lib.client.database.
|
|
13
|
-
|
|
12
|
+
from splight_lib.client.database.remote_client import ( # noqa: E402
|
|
13
|
+
RemoteDatabaseClient,
|
|
14
14
|
)
|
|
15
15
|
from splight_lib.models.base import SplightDatabaseBaseModel # noqa: E402
|
|
16
16
|
from splight_lib.settings import settings # noqa: E402
|
|
@@ -53,7 +53,7 @@ RESOURCE_LIST = [
|
|
|
53
53
|
]
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
@patch.object(
|
|
56
|
+
@patch.object(RemoteDatabaseClient, "_get", return_value=RESOURCE_LIST)
|
|
57
57
|
def test_list(mock):
|
|
58
58
|
instances = Resource.list()
|
|
59
59
|
mock.assert_called_with(Resource.__name__)
|
|
@@ -64,7 +64,7 @@ def test_list(mock):
|
|
|
64
64
|
)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
@patch.object(
|
|
67
|
+
@patch.object(RemoteDatabaseClient, "_get", return_value=RESOURCE_LIST)
|
|
68
68
|
def test_list_first(mock):
|
|
69
69
|
instances = Resource.list(first=True)
|
|
70
70
|
mock.assert_called_with(Resource.__name__, first=True)
|
|
@@ -81,11 +81,18 @@ def test_list_first(mock):
|
|
|
81
81
|
)
|
|
82
82
|
def test_retrieve(instance_dict):
|
|
83
83
|
with patch.object(
|
|
84
|
-
|
|
84
|
+
RemoteDatabaseClient, "_get", return_value=instance_dict
|
|
85
85
|
) as mock:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
with patch.object(
|
|
87
|
+
RemoteDatabaseClient,
|
|
88
|
+
"_get_api_path",
|
|
89
|
+
return_value="/api/resource/",
|
|
90
|
+
):
|
|
91
|
+
instance = Resource.retrieve(instance_dict["id"])
|
|
92
|
+
mock.assert_called_with(
|
|
93
|
+
Resource.__name__, id=instance.id, first=True
|
|
94
|
+
)
|
|
95
|
+
assert instance.model_dump() == instance_dict
|
|
89
96
|
|
|
90
97
|
|
|
91
98
|
@pytest.mark.parametrize(
|
|
@@ -94,12 +101,19 @@ def test_retrieve(instance_dict):
|
|
|
94
101
|
)
|
|
95
102
|
def test_save_with_id(instance_dict):
|
|
96
103
|
with patch.object(
|
|
97
|
-
|
|
104
|
+
RemoteDatabaseClient, "save", return_value=instance_dict
|
|
98
105
|
) as mock:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
with patch.object(
|
|
107
|
+
RemoteDatabaseClient,
|
|
108
|
+
"_get_api_path",
|
|
109
|
+
return_value="/api/resource/",
|
|
110
|
+
):
|
|
111
|
+
resource = Resource.model_validate(instance_dict)
|
|
112
|
+
resource.save()
|
|
113
|
+
mock.assert_called_with(
|
|
114
|
+
Resource.__name__, instance_dict, files=None
|
|
115
|
+
)
|
|
116
|
+
assert resource.model_dump() == instance_dict
|
|
103
117
|
|
|
104
118
|
|
|
105
119
|
@pytest.mark.parametrize(
|
|
@@ -108,14 +122,21 @@ def test_save_with_id(instance_dict):
|
|
|
108
122
|
)
|
|
109
123
|
def test_save_without_id(instance_dict):
|
|
110
124
|
with patch.object(
|
|
111
|
-
|
|
125
|
+
RemoteDatabaseClient, "save", return_value=instance_dict
|
|
112
126
|
) as mock:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
with patch.object(
|
|
128
|
+
RemoteDatabaseClient,
|
|
129
|
+
"_get_api_path",
|
|
130
|
+
return_value="/api/resource/",
|
|
131
|
+
):
|
|
132
|
+
resource = Resource.model_validate(instance_dict)
|
|
133
|
+
resource.id = None
|
|
134
|
+
resource_dict = resource.model_dump(exclude_none=True)
|
|
135
|
+
resource.save()
|
|
136
|
+
mock.assert_called_with(
|
|
137
|
+
Resource.__name__, resource_dict, files=None
|
|
138
|
+
)
|
|
139
|
+
assert resource.model_dump() == instance_dict
|
|
119
140
|
|
|
120
141
|
|
|
121
142
|
@pytest.mark.parametrize(
|
|
@@ -124,10 +145,15 @@ def test_save_without_id(instance_dict):
|
|
|
124
145
|
)
|
|
125
146
|
def test_delete(instance_dict):
|
|
126
147
|
with patch.object(
|
|
127
|
-
|
|
148
|
+
RemoteDatabaseClient, "delete", return_value=instance_dict
|
|
128
149
|
) as mock:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
)
|
|
150
|
+
with patch.object(
|
|
151
|
+
RemoteDatabaseClient,
|
|
152
|
+
"_get_api_path",
|
|
153
|
+
return_value="/api/resource/",
|
|
154
|
+
):
|
|
155
|
+
resource = Resource.model_validate(instance_dict)
|
|
156
|
+
resource.delete()
|
|
157
|
+
mock.assert_called_with(
|
|
158
|
+
resource_name=Resource.__name__, id=resource.id
|
|
159
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{splight_lib-5.6.5.dev0 → splight_lib-5.7.0}/splight_lib/restclient/tests/test_restclient.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|