splight-lib 4.3.0.dev1__tar.gz → 4.3.1__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-4.3.1/PKG-INFO +57 -0
- splight_lib-4.3.1/pyproject.toml +64 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/remote_client.py +2 -2
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/classmap.py +2 -1
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/remote_client.py +0 -1
- splight_lib-4.3.1/splight_lib/client/tests/test_communication.py +11 -0
- splight_lib-4.3.1/splight_lib/client/tests/test_database.py +163 -0
- splight_lib-4.3.1/splight_lib/client/tests/test_datalake.py +108 -0
- splight_lib-4.3.1/splight_lib/client/tests/test_hub.py +9 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/communication/event_handler.py +3 -56
- splight_lib-4.3.1/splight_lib/communication/tests/test_event_handler.py +1 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/component/abstract.py +33 -44
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/component/spec.py +28 -23
- splight_lib-4.3.1/splight_lib/component/tests/test_abstract.py +1 -0
- splight_lib-4.3.1/splight_lib/component/tests/test_spec.py +133 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/constants.py +1 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/encryption.py +1 -1
- splight_lib-4.3.1/splight_lib/logging/tests/test_logging.py +160 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/__init__.py +9 -4
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/alert.py +5 -2
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/asset.py +11 -7
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/attribute.py +2 -2
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/base.py +8 -8
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/communication.py +0 -7
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/component.py +78 -33
- splight_lib-4.3.1/splight_lib/models/dashboard.py +95 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/data_address.py +1 -1
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/event.py +14 -50
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/file.py +15 -8
- splight_lib-4.3.1/splight_lib/models/function.py +68 -0
- splight_lib-4.3.1/splight_lib/models/generic.py +34 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/hub.py +37 -30
- splight_lib-4.3.1/splight_lib/models/metadata.py +21 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/native.py +2 -2
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/pipeline.py +1 -1
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/secret.py +1 -2
- splight_lib-4.3.1/splight_lib/models/tests/models.json +478 -0
- splight_lib-4.3.1/splight_lib/models/tests/test_component_object_instance.py +88 -0
- splight_lib-4.3.1/splight_lib/models/tests/test_database_model.py +133 -0
- splight_lib-4.3.1/splight_lib/models/tests/test_metadata.py +58 -0
- splight_lib-4.3.1/splight_lib/models/tests/test_models.py +30 -0
- splight_lib-4.3.1/splight_lib/restclient/tests/test_restclient.py +35 -0
- splight_lib-4.3.1/splight_lib/settings.py +93 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/testing/__init__.py +2 -2
- splight_lib-4.3.1/splight_lib/tests/FakeProc.py +14 -0
- splight_lib-4.3.1/splight_lib/tests/test_encryption.py +1 -0
- splight_lib-4.3.1/splight_lib/tests/test_execution.py +114 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/utils/custom_model.py +2 -2
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/webhook.py +1 -1
- splight-lib-4.3.0.dev1/PKG-INFO +0 -32
- splight-lib-4.3.0.dev1/pyproject.toml +0 -6
- splight-lib-4.3.0.dev1/setup.cfg +0 -4
- splight-lib-4.3.0.dev1/setup.py +0 -43
- splight-lib-4.3.0.dev1/splight_lib/models/dashboard.py +0 -86
- splight-lib-4.3.0.dev1/splight_lib/models/metadata.py +0 -20
- splight-lib-4.3.0.dev1/splight_lib/models/query.py +0 -89
- splight-lib-4.3.0.dev1/splight_lib/models/setpoint.py +0 -68
- splight-lib-4.3.0.dev1/splight_lib/settings.py +0 -64
- splight-lib-4.3.0.dev1/splight_lib.egg-info/PKG-INFO +0 -32
- splight-lib-4.3.0.dev1/splight_lib.egg-info/SOURCES.txt +0 -85
- splight-lib-4.3.0.dev1/splight_lib.egg-info/dependency_links.txt +0 -1
- splight-lib-4.3.0.dev1/splight_lib.egg-info/not-zip-safe +0 -1
- splight-lib-4.3.0.dev1/splight_lib.egg-info/requires.txt +0 -38
- splight-lib-4.3.0.dev1/splight_lib.egg-info/top_level.txt +0 -1
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/LICENSE.txt +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/README.md +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/abstract/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/abstract/client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/auth/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/auth/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/auth/mac_auth.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/auth/token.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/abstract.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/classmap.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/local_client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/abstract.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/builder.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/database/local_client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/datalake/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/datalake/abstract.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/datalake/builder.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/datalake/local_client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/datalake/remote_client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/file_handler.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/filter.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/hub/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/hub/abstract.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/hub/client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/communication/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/component/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/component/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/execution.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/logging/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/logging/_internal.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/logging/component.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/logging/constants.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/logging/logging.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/models/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/restclient/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/restclient/client.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/restclient/exceptions.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/restclient/types.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/utils/__init__.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/utils/hub.py +0 -0
- {splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/version.py +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: splight-lib
|
|
3
|
+
Version: 4.3.1
|
|
4
|
+
Summary: Splight Library
|
|
5
|
+
Author: Splight Dev
|
|
6
|
+
Author-email: dev@splight-ae.com
|
|
7
|
+
Requires-Python: >=3.8.1,<4
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Dist: concurrent-log-handler (==0.9.21)
|
|
14
|
+
Requires-Dist: cryptography (==35.0.0)
|
|
15
|
+
Requires-Dist: email-validator (>=2.1.0.post1,<3.0.0)
|
|
16
|
+
Requires-Dist: furl (==2.1.3)
|
|
17
|
+
Requires-Dist: geojson-pydantic (==1.0.1)
|
|
18
|
+
Requires-Dist: hexbytes (==0.2.2)
|
|
19
|
+
Requires-Dist: httpx (==0.23.3)
|
|
20
|
+
Requires-Dist: jinja2 (==3.0.2)
|
|
21
|
+
Requires-Dist: mergedeep (==1.3.4)
|
|
22
|
+
Requires-Dist: pandas (==1.4.0)
|
|
23
|
+
Requires-Dist: parameterized (==0.8.1)
|
|
24
|
+
Requires-Dist: pathspec (==0.11.1)
|
|
25
|
+
Requires-Dist: protobuf (==4.21.6)
|
|
26
|
+
Requires-Dist: py7zr (==0.18.5)
|
|
27
|
+
Requires-Dist: pydantic (==2.4.2)
|
|
28
|
+
Requires-Dist: pydantic-settings (==2.0.3)
|
|
29
|
+
Requires-Dist: pysher (==1.0.8)
|
|
30
|
+
Requires-Dist: pytz (==2021.3)
|
|
31
|
+
Requires-Dist: pyyaml (==6.0.1)
|
|
32
|
+
Requires-Dist: requests (>=2.26.0)
|
|
33
|
+
Requires-Dist: retry (==0.9.2)
|
|
34
|
+
Requires-Dist: simplejson (==3.17.6)
|
|
35
|
+
Requires-Dist: strenum (==0.4.9)
|
|
36
|
+
Requires-Dist: stringcase (==1.2.0)
|
|
37
|
+
Requires-Dist: typing-extensions (>=4.6.1,<5.0.0)
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
[](https://github.com/splightplatform/splight-lib/actions/workflows/libupload.yml)
|
|
41
|
+
|
|
42
|
+
## How to install
|
|
43
|
+
|
|
44
|
+
For development
|
|
45
|
+
|
|
46
|
+
- `make install`
|
|
47
|
+
|
|
48
|
+
For productive envs.
|
|
49
|
+
|
|
50
|
+
- `python setup.py install`
|
|
51
|
+
|
|
52
|
+
## Tests
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
make test
|
|
56
|
+
```
|
|
57
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "splight-lib"
|
|
3
|
+
version = "4.3.1"
|
|
4
|
+
description = "Splight Library"
|
|
5
|
+
authors = ["Splight Dev <dev@splight-ae.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
|
|
8
|
+
[tool.poetry.dependencies]
|
|
9
|
+
python = ">=3.8.1,<4"
|
|
10
|
+
concurrent-log-handler = "0.9.21"
|
|
11
|
+
cryptography = "35.0.0"
|
|
12
|
+
furl = "2.1.3"
|
|
13
|
+
geojson-pydantic = "1.0.1"
|
|
14
|
+
hexbytes = "0.2.2"
|
|
15
|
+
httpx = "0.23.3"
|
|
16
|
+
jinja2 = "3.0.2"
|
|
17
|
+
mergedeep = "1.3.4"
|
|
18
|
+
pandas = "1.4.0"
|
|
19
|
+
parameterized = "0.8.1"
|
|
20
|
+
pathspec = "0.11.1"
|
|
21
|
+
protobuf = "4.21.6"
|
|
22
|
+
py7zr = "0.18.5"
|
|
23
|
+
pydantic = "2.4.2"
|
|
24
|
+
pysher = "1.0.8"
|
|
25
|
+
pytz = "2021.3"
|
|
26
|
+
pyyaml = "6.0.1"
|
|
27
|
+
requests = ">=2.26.0"
|
|
28
|
+
retry = "0.9.2"
|
|
29
|
+
simplejson = "3.17.6"
|
|
30
|
+
strenum = "0.4.9"
|
|
31
|
+
stringcase = "1.2.0"
|
|
32
|
+
typing-extensions = "^4.6.1"
|
|
33
|
+
pydantic-settings = "2.0.3"
|
|
34
|
+
email-validator = "^2.1.0.post1"
|
|
35
|
+
|
|
36
|
+
[tool.poetry.group.dev.dependencies]
|
|
37
|
+
black = "23.3.0"
|
|
38
|
+
isort = "5.12.0"
|
|
39
|
+
ipdb = "^0.13.13"
|
|
40
|
+
ipython = "8.12.2"
|
|
41
|
+
flake8 = "^6.1.0"
|
|
42
|
+
pre-commit = "3.2.2"
|
|
43
|
+
pytest = "^7.4.3"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["poetry-core"]
|
|
47
|
+
build-backend = "poetry.core.masonry.api"
|
|
48
|
+
|
|
49
|
+
[tool.black]
|
|
50
|
+
line-length = 79
|
|
51
|
+
|
|
52
|
+
[tool.isort]
|
|
53
|
+
profile = "black"
|
|
54
|
+
line_length = 79
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
filterwarnings = [
|
|
58
|
+
"error",
|
|
59
|
+
"ignore::RuntimeWarning",
|
|
60
|
+
"ignore::UserWarning",
|
|
61
|
+
"ignore::pytest.PytestUnraisableExceptionWarning",
|
|
62
|
+
"ignore::pytest.PytestUnhandledThreadExceptionWarning",
|
|
63
|
+
"ignore::pytest.PytestAssertRewriteWarning",
|
|
64
|
+
]
|
{splight-lib-4.3.0.dev1 → splight_lib-4.3.1}/splight_lib/client/communication/remote_client.py
RENAMED
|
@@ -46,7 +46,7 @@ class CommunicationFactory:
|
|
|
46
46
|
assert (
|
|
47
47
|
response.status_code == 201
|
|
48
48
|
), f"Cant create communication {self._model}."
|
|
49
|
-
return self._model.
|
|
49
|
+
return self._model.model_validate(response.json())
|
|
50
50
|
|
|
51
51
|
def get(self, params=None):
|
|
52
52
|
response = requests.get(
|
|
@@ -56,7 +56,7 @@ class CommunicationFactory:
|
|
|
56
56
|
response.status_code == 200
|
|
57
57
|
), f"Cant fetch communication {self._model}."
|
|
58
58
|
data = response.json()
|
|
59
|
-
return self._model.
|
|
59
|
+
return self._model.model_validate(data)
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
class RemoteCommunicationClient(AbstractCommunicationClient):
|
|
@@ -9,11 +9,12 @@ MODEL_NAME_MAP = {
|
|
|
9
9
|
"chartitem": f"{ENGINE_PREFIX}/dashboard/chartitems/",
|
|
10
10
|
"component": f"{ENGINE_PREFIX}/component/components/",
|
|
11
11
|
"componentobject": f"{ENGINE_PREFIX}/component/objects/",
|
|
12
|
-
"routineobject": f"{ENGINE_PREFIX}/component/routines/",
|
|
13
12
|
"dashboard": f"{ENGINE_PREFIX}/dashboard/dashboards/",
|
|
14
13
|
"file": f"{ENGINE_PREFIX}/files/",
|
|
15
14
|
"filter": f"{ENGINE_PREFIX}/dashboard/filters/",
|
|
15
|
+
"function": f"{ENGINE_PREFIX}/function/functions/",
|
|
16
16
|
"query": f"{ENGINE_PREFIX}/queries/",
|
|
17
|
+
"routineobject": f"{ENGINE_PREFIX}/component/routines/",
|
|
17
18
|
"secret": f"{ENGINE_PREFIX}/secrets/",
|
|
18
19
|
"setpoint": f"{ENGINE_PREFIX}/setpoints/",
|
|
19
20
|
"tab": f"{ENGINE_PREFIX}/dashboard/tabs/",
|
|
@@ -19,7 +19,6 @@ from splight_lib.client.exceptions import (
|
|
|
19
19
|
InvalidModelName,
|
|
20
20
|
)
|
|
21
21
|
from splight_lib.constants import ENGINE_PREFIX
|
|
22
|
-
from splight_lib.encryption import EncryptionClient
|
|
23
22
|
from splight_lib.logging._internal import LogTags, get_splight_logger
|
|
24
23
|
from splight_lib.restclient import SplightRestClient
|
|
25
24
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from unittest import TestCase
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TestCommunication(TestCase):
|
|
5
|
+
def test_import_communication(self):
|
|
6
|
+
from splight_lib.client.communication.abstract import (
|
|
7
|
+
AbstractCommunicationClient,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# TODO: complete tests for client/communication/remote_client.py
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
from unittest.mock import patch # noqa E402
|
|
2
|
+
|
|
3
|
+
import pytest # noqa E402
|
|
4
|
+
from furl import furl # noqa E402
|
|
5
|
+
|
|
6
|
+
from splight_lib.client.database.remote_client import ( # noqa E402
|
|
7
|
+
RemoteDatabaseClient,
|
|
8
|
+
SplightRestClient,
|
|
9
|
+
)
|
|
10
|
+
from splight_lib.client.exceptions import InvalidModelName # noqa E402
|
|
11
|
+
|
|
12
|
+
base_url = "http://test.com"
|
|
13
|
+
access_id = "access_id"
|
|
14
|
+
secret_key = "secret_key"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MockResponse:
|
|
18
|
+
status_code = 200
|
|
19
|
+
|
|
20
|
+
def __init__(self, json_data):
|
|
21
|
+
self.json_data = json_data
|
|
22
|
+
|
|
23
|
+
def raise_for_status(self):
|
|
24
|
+
return None
|
|
25
|
+
|
|
26
|
+
def json(self):
|
|
27
|
+
return self.json_data
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@patch("splight_lib.client.database.remote_client.SplightAuthToken")
|
|
31
|
+
@patch("splight_lib.client.database.remote_client.SplightRestClient")
|
|
32
|
+
def test_initialization(mock_rest_client, mock_auth_token):
|
|
33
|
+
client = RemoteDatabaseClient(
|
|
34
|
+
base_url=base_url,
|
|
35
|
+
access_id=access_id,
|
|
36
|
+
secret_key=secret_key,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
mock_auth_token.assert_called_once_with(
|
|
40
|
+
access_key=access_id, secret_key=secret_key
|
|
41
|
+
)
|
|
42
|
+
assert client._base_url.url == base_url
|
|
43
|
+
mock_rest_client().update_headers.assert_called_once()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@patch.object(
|
|
47
|
+
SplightRestClient,
|
|
48
|
+
"post",
|
|
49
|
+
return_value=MockResponse({"name": "instance_name", "id": "some_id"}),
|
|
50
|
+
)
|
|
51
|
+
def test_save_without_id(mock_post):
|
|
52
|
+
client = RemoteDatabaseClient(
|
|
53
|
+
base_url=base_url,
|
|
54
|
+
access_id=access_id,
|
|
55
|
+
secret_key=secret_key,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
mock_instance = {"name": "instance_name"}
|
|
59
|
+
result = client.save("alert", mock_instance)
|
|
60
|
+
|
|
61
|
+
mock_post.assert_called_once()
|
|
62
|
+
|
|
63
|
+
assert "id" in result
|
|
64
|
+
assert result["name"] == mock_instance["name"]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@patch.object(
|
|
68
|
+
SplightRestClient,
|
|
69
|
+
"put",
|
|
70
|
+
return_value=MockResponse({"name": "instance_name", "id": "instance_id"}),
|
|
71
|
+
)
|
|
72
|
+
def test_save_with_id(mock_put):
|
|
73
|
+
client = RemoteDatabaseClient(
|
|
74
|
+
base_url=base_url,
|
|
75
|
+
access_id=access_id,
|
|
76
|
+
secret_key=secret_key,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
mock_instance = {"id": "instance_id", "name": "instance_name"}
|
|
80
|
+
result = client.save("alert", mock_instance)
|
|
81
|
+
|
|
82
|
+
mock_put.assert_called_once_with(
|
|
83
|
+
furl(f"{base_url}/v2/engine/alert/alerts/instance_id/"),
|
|
84
|
+
json=mock_instance,
|
|
85
|
+
)
|
|
86
|
+
assert result == mock_instance
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@patch.object(SplightRestClient, "delete")
|
|
90
|
+
def test_delete(mock_delete):
|
|
91
|
+
client = RemoteDatabaseClient(
|
|
92
|
+
base_url=base_url,
|
|
93
|
+
access_id=access_id,
|
|
94
|
+
secret_key=secret_key,
|
|
95
|
+
)
|
|
96
|
+
client.delete("alert", "instance_id")
|
|
97
|
+
mock_delete.assert_called_once()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_delete_invalid_model_name():
|
|
101
|
+
client = RemoteDatabaseClient(
|
|
102
|
+
base_url=base_url,
|
|
103
|
+
access_id=access_id,
|
|
104
|
+
secret_key=secret_key,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
with pytest.raises(InvalidModelName):
|
|
108
|
+
client.delete("invalid_resource_name", "instance_id")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@patch.object(SplightRestClient, "get")
|
|
112
|
+
def test_get_with_id(mock_get):
|
|
113
|
+
mock_instance_id = "123"
|
|
114
|
+
mock_get.return_value = MockResponse(
|
|
115
|
+
{"name": "instance_name", "id": mock_instance_id}
|
|
116
|
+
)
|
|
117
|
+
client = RemoteDatabaseClient(
|
|
118
|
+
base_url=base_url,
|
|
119
|
+
access_id=access_id,
|
|
120
|
+
secret_key=secret_key,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
result = client._get("alert", id=mock_instance_id)
|
|
124
|
+
mock_get.assert_called_once()
|
|
125
|
+
assert result["id"] == mock_instance_id
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@patch.object(SplightRestClient, "get")
|
|
129
|
+
def test_get_without_id(mock_get):
|
|
130
|
+
mock_get.return_value = MockResponse(
|
|
131
|
+
{
|
|
132
|
+
"results": [{"name": "instance_name", "id": "instance_id"}],
|
|
133
|
+
"next": None,
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
client = RemoteDatabaseClient(
|
|
137
|
+
base_url=base_url,
|
|
138
|
+
access_id=access_id,
|
|
139
|
+
secret_key=secret_key,
|
|
140
|
+
)
|
|
141
|
+
result = client._get("alert")
|
|
142
|
+
|
|
143
|
+
assert result[0]["id"] == "instance_id"
|
|
144
|
+
assert result[0]["name"] == "instance_name"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@patch.object(SplightRestClient, "get")
|
|
148
|
+
def test_get_without_id_and_set_first(mock_get):
|
|
149
|
+
mock_get.return_value = MockResponse(
|
|
150
|
+
{
|
|
151
|
+
"results": [{"name": "instance_name", "id": "instance_id"}],
|
|
152
|
+
"next": None,
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
client = RemoteDatabaseClient(
|
|
156
|
+
base_url=base_url,
|
|
157
|
+
access_id=access_id,
|
|
158
|
+
secret_key=secret_key,
|
|
159
|
+
)
|
|
160
|
+
result = client._get("alert", first=True)
|
|
161
|
+
|
|
162
|
+
assert result[0]["id"] == "instance_id"
|
|
163
|
+
assert result[0]["name"] == "instance_name"
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from unittest.mock import Mock, patch # noqa E402
|
|
3
|
+
|
|
4
|
+
import pandas as pd # noqa E402
|
|
5
|
+
|
|
6
|
+
from splight_lib.client.datalake import RemoteDatalakeClient # noqa E402
|
|
7
|
+
from splight_lib.client.datalake.remote_client import ( # noqa E402
|
|
8
|
+
SplightRestClient,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
base_url = "http://test.com"
|
|
12
|
+
access_id = "access_id"
|
|
13
|
+
secret_key = "secret_key"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MockResponse:
|
|
17
|
+
status_code = 200
|
|
18
|
+
|
|
19
|
+
def __init__(self, json_data):
|
|
20
|
+
self.json_data = json_data
|
|
21
|
+
|
|
22
|
+
def raise_for_status(self):
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
def json(self):
|
|
26
|
+
return self.json_data
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@patch("splight_lib.client.datalake.remote_client.SplightAuthToken")
|
|
30
|
+
@patch("splight_lib.client.datalake.remote_client.SplightRestClient")
|
|
31
|
+
def test_initialization(mock_rest_client, mock_auth_token):
|
|
32
|
+
client = RemoteDatalakeClient(
|
|
33
|
+
base_url=base_url,
|
|
34
|
+
access_id=access_id,
|
|
35
|
+
secret_key=secret_key,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
mock_auth_token.assert_called_once_with(
|
|
39
|
+
access_key=access_id, secret_key=secret_key
|
|
40
|
+
)
|
|
41
|
+
mock_rest_client.assert_called_once()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@patch.object(
|
|
45
|
+
SplightRestClient, "post", return_value=MockResponse(({"key": "value"}))
|
|
46
|
+
)
|
|
47
|
+
def test_save(mock_post):
|
|
48
|
+
client = RemoteDatalakeClient(
|
|
49
|
+
base_url=base_url,
|
|
50
|
+
access_id=access_id,
|
|
51
|
+
secret_key=secret_key,
|
|
52
|
+
)
|
|
53
|
+
collection = "collection_name"
|
|
54
|
+
instances = [{"key": "value"}]
|
|
55
|
+
result = client.save(collection=collection, instances=instances)
|
|
56
|
+
mock_post.assert_called_once()
|
|
57
|
+
assert result == instances
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@patch.object(
|
|
61
|
+
SplightRestClient,
|
|
62
|
+
"get",
|
|
63
|
+
return_value=MockResponse({"results": [{"key": "value"}]}),
|
|
64
|
+
)
|
|
65
|
+
def test_raw_get(mock_get):
|
|
66
|
+
client = RemoteDatalakeClient(base_url, access_id, secret_key)
|
|
67
|
+
collection = "collection_name"
|
|
68
|
+
result = client._raw_get("resource", collection)
|
|
69
|
+
mock_get.assert_called_once()
|
|
70
|
+
assert result == [{"key": "value"}]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@patch.object(SplightRestClient, "delete", return_value=MockResponse(None))
|
|
74
|
+
def test_delete(mock_delete):
|
|
75
|
+
client = RemoteDatalakeClient(base_url, access_id, secret_key)
|
|
76
|
+
collection = "collection_name"
|
|
77
|
+
client.delete(collection)
|
|
78
|
+
mock_delete.assert_called_once()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@patch.object(SplightRestClient, "post", return_value=MockResponse(None))
|
|
82
|
+
def test_save_dataframe(mock_post):
|
|
83
|
+
client = RemoteDatalakeClient(base_url, access_id, secret_key)
|
|
84
|
+
collection = "collection_name"
|
|
85
|
+
dataframe = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
|
|
86
|
+
client.save_dataframe(collection, dataframe)
|
|
87
|
+
mock_post.assert_called_once()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@patch.object(SplightRestClient, "post", return_value=MockResponse(None))
|
|
91
|
+
def test_create_index(mock_post):
|
|
92
|
+
client = RemoteDatalakeClient(base_url, access_id, secret_key)
|
|
93
|
+
collection = "collection_name"
|
|
94
|
+
indexes = [{"key": 1}]
|
|
95
|
+
client.create_index(collection, indexes)
|
|
96
|
+
mock_post.assert_called_once()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@patch.object(
|
|
100
|
+
SplightRestClient, "post", return_value=MockResponse([{"key": "value"}])
|
|
101
|
+
)
|
|
102
|
+
def test_raw_aggregate(mock_post):
|
|
103
|
+
client = RemoteDatalakeClient(base_url, access_id, secret_key)
|
|
104
|
+
collection = "collection_name"
|
|
105
|
+
pipeline = [{"$match": {"key": "value"}}]
|
|
106
|
+
result = client.raw_aggregate(collection, pipeline)
|
|
107
|
+
mock_post.assert_called_once()
|
|
108
|
+
assert result == [{"key": "value"}]
|
|
@@ -20,10 +20,6 @@ from splight_lib.models.event import (
|
|
|
20
20
|
ComponentCommandStatus,
|
|
21
21
|
ComponentCommandTriggerEvent,
|
|
22
22
|
ComponentCommandUpdateEvent,
|
|
23
|
-
SetPointCreateEvent,
|
|
24
|
-
SetPointResponse,
|
|
25
|
-
SetPointResponseStatus,
|
|
26
|
-
SetPointUpdateEvent,
|
|
27
23
|
)
|
|
28
24
|
|
|
29
25
|
logger = get_splight_logger()
|
|
@@ -33,10 +29,6 @@ class InvalidCommandResponse(Exception):
|
|
|
33
29
|
pass
|
|
34
30
|
|
|
35
31
|
|
|
36
|
-
class InvalidSetPointResponse(Exception):
|
|
37
|
-
pass
|
|
38
|
-
|
|
39
|
-
|
|
40
32
|
class InvalidBidingObject(Exception):
|
|
41
33
|
pass
|
|
42
34
|
|
|
@@ -65,15 +57,15 @@ def database_object_event_handler(
|
|
|
65
57
|
event = CommunicationEvent.parse_raw(event_str)
|
|
66
58
|
if binding_object_type in DB_MODEL_TYPE_MAPPING.values():
|
|
67
59
|
# Case in which is not a ComponentObject
|
|
68
|
-
handler_arg = binding_object_type.
|
|
60
|
+
handler_arg = binding_object_type.model_validate(event.data)
|
|
69
61
|
elif issubclass(binding_object_type, ComponentObjectInstance):
|
|
70
62
|
# Case for data represents a ComponentObject
|
|
71
|
-
component_obj = ComponentObject.
|
|
63
|
+
component_obj = ComponentObject.model_validate(event.data)
|
|
72
64
|
model_class = ComponentObjectInstance.from_object(component_obj)
|
|
73
65
|
handler_arg = model_class.parse_object(component_obj)
|
|
74
66
|
elif issubclass(binding_object_type, RoutineObjectInstance):
|
|
75
67
|
# Case for data represents a RoutineObject
|
|
76
|
-
routine_obj = RoutineObject.
|
|
68
|
+
routine_obj = RoutineObject.model_validate(event.data)
|
|
77
69
|
model_class = RoutineObjectInstance.from_object(routine_obj)
|
|
78
70
|
handler_arg = model_class.parse_object(routine_obj)
|
|
79
71
|
else:
|
|
@@ -138,48 +130,3 @@ def command_event_handler(
|
|
|
138
130
|
data=component_command
|
|
139
131
|
)
|
|
140
132
|
comm_client.trigger(component_command_callback_event)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def setpoint_event_handler(
|
|
144
|
-
binding_function: Callable,
|
|
145
|
-
comm_client: AbstractCommunicationClient,
|
|
146
|
-
component_id: str,
|
|
147
|
-
event_str: str,
|
|
148
|
-
):
|
|
149
|
-
"""General handler for component's setpoint events.
|
|
150
|
-
|
|
151
|
-
Parameters
|
|
152
|
-
----------
|
|
153
|
-
binding_function: Callable
|
|
154
|
-
Function to be executed.
|
|
155
|
-
comm_client: AbstractCommunicationClient
|
|
156
|
-
Communication client to send command response.
|
|
157
|
-
component_id: str
|
|
158
|
-
The component's id that is reacting to the setpoint event.
|
|
159
|
-
event_str:
|
|
160
|
-
The raw event string from pusher client.
|
|
161
|
-
"""
|
|
162
|
-
logger.info("Setpoint triggered.", tags=LogTags.SETPOINT)
|
|
163
|
-
try:
|
|
164
|
-
event = SetPointCreateEvent.parse_raw(event_str)
|
|
165
|
-
setpoint = event.data
|
|
166
|
-
setpoint_response = binding_function(setpoint)
|
|
167
|
-
if not isinstance(setpoint_response, SetPointResponseStatus):
|
|
168
|
-
raise InvalidSetPointResponse("Setpoint response is invalid")
|
|
169
|
-
|
|
170
|
-
if setpoint_response != SetPointResponseStatus.IGNORE:
|
|
171
|
-
setpoint.responses = [
|
|
172
|
-
SetPointResponse(
|
|
173
|
-
component=component_id,
|
|
174
|
-
status=setpoint_response,
|
|
175
|
-
)
|
|
176
|
-
]
|
|
177
|
-
setpoint_callback_event = SetPointUpdateEvent(data=setpoint)
|
|
178
|
-
comm_client.trigger(setpoint_callback_event)
|
|
179
|
-
except Exception as exc:
|
|
180
|
-
logger.error(
|
|
181
|
-
"Error while handling setpoint create: %s",
|
|
182
|
-
exc,
|
|
183
|
-
exc_info=True,
|
|
184
|
-
tags=LogTags.SETPOINT,
|
|
185
|
-
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# TODO: complete tests for communication/event_handler.py
|