component-local 0.0.1b3800__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.
File without changes
File without changes
@@ -0,0 +1,54 @@
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Optional, Union
4
+
5
+ from database_mysql_local.generic_crud import GenericCRUD
6
+ from logger_local.MetaLogger import MetaLogger
7
+
8
+ from .constants_src_component_local import ConstantsSrcComponent
9
+
10
+
11
+ # TODO When reading components.json5, We should get the componentId from component_table using a function wrapped with a script in component-main-local-python-package (so we can also use it in TypeScript and Powershell) # noqa E501
12
+ class ComponentLocal(GenericCRUD, metaclass=MetaLogger,
13
+ object=ConstantsSrcComponent.COMPONENT_LOCAL_PYTHON_CODE_LOGGER_OBJECT): # noqa E501
14
+ def __init__(self, is_test_data: bool = False) -> None:
15
+ GenericCRUD.__init__(
16
+ self,
17
+ default_schema_name=ConstantsSrcComponent.COMPONENT_SCHEMA_NAME,
18
+ default_table_name=ConstantsSrcComponent.COMPONENT_TABLE_NAME,
19
+ default_view_table_name=ConstantsSrcComponent.COMPONENT_VIEW_NAME,
20
+ default_column_name=ConstantsSrcComponent.COMPONENT_COLUMN_NAME,
21
+ is_test_data=is_test_data)
22
+
23
+ def get_component_id(self, component_name: str,
24
+ json_path: Union[str, Path, None] = None) -> Optional[int]:
25
+ """Returns the component_id of component_name.
26
+ 1st priority: the componentId in the JSON file (if json_path was given and it has the component).
27
+ 2nd priority: the component_id from component.component_table."""
28
+ if json_path is not None:
29
+ component_id = self.get_component_id_from_json(component_name=component_name, json_path=json_path)
30
+ if component_id is not None:
31
+ return component_id
32
+ return self.get_component_id_by_name(component_name=component_name)
33
+
34
+ def get_component_id_by_name(self, component_name: str) -> Optional[int]:
35
+ """Returns the component_id with this name in component.component_table, None if there is no such component.
36
+ If more than one component has this name, the one with the lowest component_id is returned."""
37
+ if not component_name:
38
+ raise ValueError("component_name is required")
39
+ component_id = self.select_one_value_by_column_and_value(
40
+ select_clause_value=ConstantsSrcComponent.COMPONENT_COLUMN_NAME,
41
+ column_name="name", column_value=component_name,
42
+ order_by=ConstantsSrcComponent.COMPONENT_COLUMN_NAME)
43
+ return component_id
44
+
45
+ @staticmethod
46
+ def get_component_id_from_json(component_name: str, json_path: Union[str, Path]) -> Optional[int]:
47
+ """Returns the componentId of component_name from a JSON file in the format of component.json.example,
48
+ None if the component or its componentId are not in the file."""
49
+ with open(json_path, encoding="utf-8") as json_file:
50
+ components = json.load(json_file)
51
+ component = components.get(component_name)
52
+ if not isinstance(component, dict):
53
+ return None
54
+ return component.get("componentId")
@@ -0,0 +1,26 @@
1
+ from typing import Any
2
+ from logger_local.LoggerComponentEnum import LoggerComponentEnum
3
+
4
+
5
+ class ConstantsSrcComponent:
6
+ """This is a class of all the constants of Component"""
7
+
8
+ COMPONENT_LOCAL_PYTHON_DEVELOPER_EMAIL_ADDRESS: str = 'shirlee.g@circ.zone'
9
+
10
+ # The CODE component_id of component-local in component.component_table
11
+ COMPONENT_LOCAL_PYTHON_CODE_COMPONENT_ID: int = 306
12
+
13
+ COMPONENT_LOCAL_PYTHON_COMPONENT_NAME = 'Component local Python package'
14
+ COMPONENT_LOCAL_PYTHON_CODE_LOGGER_OBJECT: dict[str, Any] = {
15
+ 'component_id': COMPONENT_LOCAL_PYTHON_CODE_COMPONENT_ID,
16
+ 'component_name': COMPONENT_LOCAL_PYTHON_COMPONENT_NAME,
17
+ 'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
18
+ 'developer_email_address': COMPONENT_LOCAL_PYTHON_DEVELOPER_EMAIL_ADDRESS # noqa E501
19
+ }
20
+
21
+ UNKNOWN_COMPONENT_ID = 0
22
+
23
+ COMPONENT_SCHEMA_NAME = 'component'
24
+ COMPONENT_TABLE_NAME = 'component_table'
25
+ COMPONENT_VIEW_NAME = 'component_view'
26
+ COMPONENT_COLUMN_NAME = 'component_id'
File without changes
@@ -0,0 +1,107 @@
1
+ # So we can run debugger without launch.json in VSCode
2
+ from dotenv import load_dotenv
3
+ load_dotenv() # Load environment variables before any imports that need them
4
+
5
+ import json
6
+ import sys
7
+ from unittest.mock import MagicMock
8
+
9
+ import pytest
10
+
11
+ from logger_local.LoggerLocal import Logger
12
+
13
+ from ..src.component_local import ComponentLocal
14
+ from ..src.constants_src_component_local import ConstantsSrcComponent
15
+ from .constants_tests_component_local import ComponentTestsConstants
16
+
17
+ logger = Logger.create_logger(object=ComponentTestsConstants.COMPONENT_LOCAL_PYTHON_TEST_LOGGER_OBJECT) # noqa E501
18
+
19
+ # Local test values, not real component ids (the real ones are in component.component_table)
20
+ EVENT_COMPONENT_ID = 247
21
+ UNKNOWN_COMPONENT_NAME = "no-such-component"
22
+
23
+
24
+ @pytest.fixture(name="component_local")
25
+ def component_local_fixture() -> ComponentLocal:
26
+ # Skips __init__ so these tests don't need a database connection
27
+ component_local = ComponentLocal.__new__(ComponentLocal)
28
+ component_local.select_one_value_by_column_and_value = MagicMock(return_value=EVENT_COMPONENT_ID)
29
+ return component_local
30
+
31
+
32
+ @pytest.fixture(name="json_path")
33
+ def json_path_fixture(tmp_path):
34
+ path = tmp_path / "component.json"
35
+ path.write_text(json.dumps({
36
+ "event": {"componentId": EVENT_COMPONENT_ID, "environmentName": "local"},
37
+ "group": {"environmentName": "local", "port": 3001}}), encoding="utf-8")
38
+ return path
39
+
40
+
41
+ def test_component_table_constants():
42
+ logger.start("test component table constants")
43
+ assert ConstantsSrcComponent.COMPONENT_SCHEMA_NAME == 'component'
44
+ assert ConstantsSrcComponent.COMPONENT_TABLE_NAME == 'component_table'
45
+ assert ConstantsSrcComponent.COMPONENT_COLUMN_NAME == 'component_id'
46
+ logger.end("test successful")
47
+
48
+
49
+ def test_get_component_id_from_json(json_path):
50
+ logger.start("test get_component_id_from_json")
51
+ assert ComponentLocal.get_component_id_from_json("event", json_path) == EVENT_COMPONENT_ID
52
+ logger.end("test successful")
53
+
54
+
55
+ def test_get_component_id_from_json_without_component_id(json_path):
56
+ logger.start("test get_component_id_from_json without componentId")
57
+ assert ComponentLocal.get_component_id_from_json("group", json_path) is None
58
+ logger.end("test successful")
59
+
60
+
61
+ def test_get_component_id_from_json_unknown_component(json_path):
62
+ logger.start("test get_component_id_from_json unknown component")
63
+ assert ComponentLocal.get_component_id_from_json(UNKNOWN_COMPONENT_NAME, json_path) is None
64
+ logger.end("test successful")
65
+
66
+
67
+ def test_get_component_id_by_name(component_local):
68
+ logger.start("test get_component_id_by_name")
69
+ assert component_local.get_component_id_by_name("event") == EVENT_COMPONENT_ID
70
+ component_local.select_one_value_by_column_and_value.assert_called_once_with(
71
+ select_clause_value='component_id', column_name='name', column_value="event", order_by='component_id')
72
+ logger.end("test successful")
73
+
74
+
75
+ def test_get_component_id_by_name_empty_name(component_local):
76
+ logger.start("test get_component_id_by_name empty name")
77
+ with pytest.raises(ValueError):
78
+ component_local.get_component_id_by_name("")
79
+ logger.end("test successful")
80
+
81
+
82
+ def test_get_component_id_prefers_json(component_local, json_path):
83
+ logger.start("test get_component_id prefers the JSON")
84
+ assert component_local.get_component_id("event", json_path=json_path) == EVENT_COMPONENT_ID
85
+ component_local.select_one_value_by_column_and_value.assert_not_called()
86
+ logger.end("test successful")
87
+
88
+
89
+ def test_get_component_id_falls_back_to_database(component_local, json_path):
90
+ logger.start("test get_component_id falls back to the database")
91
+ assert component_local.get_component_id("group", json_path=json_path) == EVENT_COMPONENT_ID
92
+ component_local.select_one_value_by_column_and_value.assert_called_once()
93
+ logger.end("test successful")
94
+
95
+
96
+ def test_get_component_id_unknown_component(component_local):
97
+ logger.start("test get_component_id unknown component")
98
+ component_local.select_one_value_by_column_and_value.return_value = None
99
+ assert component_local.get_component_id(UNKNOWN_COMPONENT_NAME) is None
100
+ logger.end("test successful")
101
+
102
+
103
+ # If we use only a call to some_test(), this can cause unexpected behavior, for example
104
+ # it can cause the test to be run multiple times simultaneously. This is why we use the following
105
+ # Which cause the test to be run only once with pytest:
106
+ if __name__ == "__main__":
107
+ pytest.main(sys.argv[1:])
@@ -0,0 +1,17 @@
1
+ from logger_local.LoggerComponentEnum import LoggerComponentEnum
2
+
3
+
4
+ class ComponentTestsConstants:
5
+ # The TEST component_id of component-local in component.component_table
6
+ COMPONENT_TEST_COMPONENT_ID: int = 307
7
+ COMPONENT_TEST_COMPONENT_NAME = "Component Tests"
8
+ COMPONENT_DEVELOPER_EMAIL_ADDRESS = "shirlee.g@circ.zone"
9
+
10
+ COMPONENT_LOCAL_PYTHON_TEST_LOGGER_OBJECT = {
11
+ # At this point of time we do not support camelCase in logger-local
12
+ 'component_id': COMPONENT_TEST_COMPONENT_ID,
13
+ 'component_name': COMPONENT_TEST_COMPONENT_NAME,
14
+ 'component_category': LoggerComponentEnum.ComponentCategory.Unit_Test.value, # noqa E501
15
+ 'testing_framework': LoggerComponentEnum.testingFramework.pytest.value,
16
+ 'developer_email_address': COMPONENT_DEVELOPER_EMAIL_ADDRESS
17
+ }
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: component-local
3
+ Version: 0.0.1b3800
4
+ Summary: PyPI component-local Python Package owned by Circlez.ai
5
+ Home-page: https://github.com/circles-zone/component-main-local-python-restapi-serverless-com
6
+ Author: Circles
7
+ Author-email: info@circlez.ai
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: python-sdk-remote
12
+ Requires-Dist: logger-local
13
+ Requires-Dist: database-mysql-local
14
+ Requires-Dist: smart-datastore-local
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: summary
23
+
24
+ PyPI component-local Python Package owned by Circlez.ai
25
+ JIRA Work Item: https://circles-zone.atlassian.net/browse/BU-3800
26
+ GHA: https://github.com/circles-zone/component-main-local-python-restapi-serverless-com/actions
@@ -0,0 +1,11 @@
1
+ component_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ component_local/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ component_local/src/component_local.py,sha256=H5QKoZD0HcH8rGuMM5XckSqaLyoq19XIwUjAv6bHIZI,3031
4
+ component_local/src/constants_src_component_local.py,sha256=Po_goI1J8Cr-RJHCGOY8ETbrjzrTYOiksTcGzkyRXmU,1051
5
+ component_local/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ component_local/tests/component_local_test.py,sha256=5NRKCWrpWgGarOk3_G0krAdoF8xPfq0pLc6iOX9Zawg,4493
7
+ component_local/tests/constants_tests_component_local.py,sha256=HZ_mmNQ74iKzpq_EClmjz1uI063vm-vVVKXw61p8uGI,823
8
+ component_local-0.0.1b3800.dist-info/METADATA,sha256=V-HLicXGTy_kL70gKqxj-eGuy7P6KPyB9sieF-qEJIA,929
9
+ component_local-0.0.1b3800.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
10
+ component_local-0.0.1b3800.dist-info/top_level.txt,sha256=pCrhck9pWML37LaFnDbl_cl09wFYZSr2oB47x-skF8U,16
11
+ component_local-0.0.1b3800.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ component_local