jaseci 1.4.2.6__py3-none-any.whl → 2.0.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 jaseci might be problematic. Click here for more details.

Files changed (187) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -118
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -77
  16. jaseci/extens/act_lib/file_handler.py +0 -190
  17. jaseci/extens/act_lib/internal.py +0 -19
  18. jaseci/extens/act_lib/jaseci.py +0 -62
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -192
  22. jaseci/extens/act_lib/rand.py +0 -83
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -170
  25. jaseci/extens/act_lib/std.py +0 -236
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -338
  28. jaseci/extens/act_lib/task.py +0 -14
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -80
  46. jaseci/extens/act_lib/vector.py +0 -158
  47. jaseci/extens/act_lib/webtool.py +0 -29
  48. jaseci/extens/act_lib/zip.py +0 -34
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -171
  51. jaseci/extens/api/alias_api.py +0 -140
  52. jaseci/extens/api/architype_api.py +0 -197
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -85
  55. jaseci/extens/api/graph_api.py +0 -168
  56. jaseci/extens/api/health_api.py +0 -21
  57. jaseci/extens/api/interface.py +0 -269
  58. jaseci/extens/api/jac_api.py +0 -172
  59. jaseci/extens/api/jsorc_api.py +0 -317
  60. jaseci/extens/api/logger_api.py +0 -90
  61. jaseci/extens/api/master_api.py +0 -134
  62. jaseci/extens/api/object_api.py +0 -102
  63. jaseci/extens/api/prometheus_api.py +0 -75
  64. jaseci/extens/api/queue_api.py +0 -141
  65. jaseci/extens/api/sentinel_api.py +0 -271
  66. jaseci/extens/api/share_api.py +0 -64
  67. jaseci/extens/api/super_api.py +0 -65
  68. jaseci/extens/api/tests/__init__.py +0 -0
  69. jaseci/extens/api/tests/test_architype_api.py +0 -66
  70. jaseci/extens/api/tests/test_global_api.py +0 -179
  71. jaseci/extens/api/tests/test_graph_api.py +0 -64
  72. jaseci/extens/api/tests/test_logger_api.py +0 -43
  73. jaseci/extens/api/tests/test_object_api.py +0 -20
  74. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  75. jaseci/extens/api/tests/test_uncommon.py +0 -107
  76. jaseci/extens/api/tests/test_user_api.py +0 -32
  77. jaseci/extens/api/tests/test_walker_api.py +0 -316
  78. jaseci/extens/api/user_api.py +0 -166
  79. jaseci/extens/api/walker_api.py +0 -299
  80. jaseci/extens/api/webhook_api.py +0 -77
  81. jaseci/extens/svc/__init__.py +0 -0
  82. jaseci/extens/svc/elastic_svc.py +0 -366
  83. jaseci/extens/svc/kube_svc.py +0 -432
  84. jaseci/extens/svc/mail_svc.py +0 -156
  85. jaseci/extens/svc/prome_svc.py +0 -378
  86. jaseci/extens/svc/redis_svc.py +0 -63
  87. jaseci/extens/svc/storage_svc.py +0 -193
  88. jaseci/extens/svc/stripe_svc.py +0 -51
  89. jaseci/extens/svc/task_svc.py +0 -155
  90. jaseci/extens/svc/tasks.py +0 -302
  91. jaseci/jac/__init__.py +0 -0
  92. jaseci/jac/interpreter/__init__.py +0 -0
  93. jaseci/jac/interpreter/architype_interp.py +0 -219
  94. jaseci/jac/interpreter/interp.py +0 -1784
  95. jaseci/jac/interpreter/sentinel_interp.py +0 -260
  96. jaseci/jac/interpreter/tests/__init__.py +0 -0
  97. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  98. jaseci/jac/interpreter/walker_interp.py +0 -249
  99. jaseci/jac/ir/__init__.py +0 -0
  100. jaseci/jac/ir/ast.py +0 -73
  101. jaseci/jac/ir/ast_builder.py +0 -249
  102. jaseci/jac/ir/jac_code.py +0 -151
  103. jaseci/jac/ir/passes/__init__.py +0 -6
  104. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  105. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  106. jaseci/jac/ir/passes/ir_pass.py +0 -29
  107. jaseci/jac/ir/passes/printer_pass.py +0 -23
  108. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  109. jaseci/jac/ir/passes/schedule.py +0 -23
  110. jaseci/jac/ir/passes/stats_pass.py +0 -16
  111. jaseci/jac/jac.g4 +0 -450
  112. jaseci/jac/jac_parse/__init__.py +0 -0
  113. jaseci/jac/jac_parse/jacLexer.py +0 -809
  114. jaseci/jac/jac_parse/jacListener.py +0 -853
  115. jaseci/jac/jac_parse/jacParser.py +0 -9192
  116. jaseci/jac/jac_set.py +0 -120
  117. jaseci/jac/jsci_vm/__init__.py +0 -0
  118. jaseci/jac/jsci_vm/disasm.py +0 -94
  119. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  120. jaseci/jac/jsci_vm/machine.py +0 -188
  121. jaseci/jac/jsci_vm/op_codes.py +0 -82
  122. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  123. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  124. jaseci/jac/machine/__init__.py +0 -0
  125. jaseci/jac/machine/jac_scope.py +0 -86
  126. jaseci/jac/machine/jac_value.py +0 -227
  127. jaseci/jac/machine/machine_state.py +0 -386
  128. jaseci/jac/tests/__init__.py +0 -0
  129. jaseci/jac/tests/book_code.py +0 -624
  130. jaseci/jac/tests/test_book.py +0 -380
  131. jaseci/jac/tests/test_lang_14.py +0 -49
  132. jaseci/jsorc/__init__.py +0 -7
  133. jaseci/jsorc/jsorc.py +0 -642
  134. jaseci/jsorc/jsorc_settings.py +0 -211
  135. jaseci/jsorc/jsorc_utils.py +0 -298
  136. jaseci/jsorc/live_actions.py +0 -365
  137. jaseci/jsorc/manifests/__init__.py +0 -0
  138. jaseci/jsorc/manifests/database.yaml +0 -109
  139. jaseci/jsorc/manifests/elastic.yaml +0 -6029
  140. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  141. jaseci/jsorc/manifests/redis.yaml +0 -64
  142. jaseci/jsorc/memory.py +0 -258
  143. jaseci/jsorc/redis.py +0 -140
  144. jaseci/jsorc/remote_actions.py +0 -158
  145. jaseci/jsorc/tests/__init__.py +0 -0
  146. jaseci/jsorc/tests/test_actions.py +0 -542
  147. jaseci/jsorc/tests/test_jsorc.py +0 -112
  148. jaseci/prim/__init__.py +0 -0
  149. jaseci/prim/ability.py +0 -94
  150. jaseci/prim/architype.py +0 -90
  151. jaseci/prim/edge.py +0 -173
  152. jaseci/prim/element.py +0 -233
  153. jaseci/prim/graph.py +0 -27
  154. jaseci/prim/master.py +0 -67
  155. jaseci/prim/node.py +0 -533
  156. jaseci/prim/obj_mixins.py +0 -238
  157. jaseci/prim/sentinel.py +0 -282
  158. jaseci/prim/super_master.py +0 -31
  159. jaseci/prim/walker.py +0 -261
  160. jaseci/svc/__init__.py +0 -0
  161. jaseci/tests/__init__.py +0 -0
  162. jaseci/tests/infer.py +0 -39
  163. jaseci/tests/jac_test_code.py +0 -1293
  164. jaseci/tests/jac_test_progs.py +0 -774
  165. jaseci/tests/test_core.py +0 -153
  166. jaseci/tests/test_jac.py +0 -824
  167. jaseci/tests/test_node.py +0 -89
  168. jaseci/tests/test_progs.py +0 -702
  169. jaseci/tests/test_stack.py +0 -220
  170. jaseci/tests/test_stripe.py +0 -225
  171. jaseci/utils/__init__.py +0 -0
  172. jaseci/utils/actions/__init__.py +0 -0
  173. jaseci/utils/actions/actions_manager.py +0 -254
  174. jaseci/utils/actions/actions_optimizer.py +0 -517
  175. jaseci/utils/actions/actions_state.py +0 -95
  176. jaseci/utils/file_handler.py +0 -171
  177. jaseci/utils/gprof2dot.py +0 -3786
  178. jaseci/utils/id_list.py +0 -169
  179. jaseci/utils/json_handler.py +0 -70
  180. jaseci/utils/log_utils.py +0 -57
  181. jaseci/utils/test_core.py +0 -62
  182. jaseci/utils/utils.py +0 -387
  183. jaseci-1.4.2.6.dist-info/LICENSE +0 -21
  184. jaseci-1.4.2.6.dist-info/METADATA +0 -39
  185. jaseci-1.4.2.6.dist-info/RECORD +0 -185
  186. jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
  187. jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
@@ -1,542 +0,0 @@
1
- from unittest import TestCase
2
- from unittest.mock import patch
3
- from jaseci.utils.utils import TestCaseHelper
4
- import jaseci.jsorc.live_actions as jla
5
- import jaseci.jsorc.remote_actions as jra
6
- from jaseci.jsorc.live_actions import gen_remote_func_hook
7
- from pydantic import BaseModel
8
- from typing import Any, List, Mapping, Optional
9
-
10
-
11
- class RequestBody(BaseModel):
12
- a: str
13
- b: str
14
- c: str
15
- d: Optional[List[Any]] = None
16
- e: str = None
17
- f: str = ""
18
- g: Optional[Mapping[Any, Any]] = None
19
-
20
-
21
- def proc_req_body(route, body: RequestBody):
22
- if "d" in body.__dict__:
23
- body.__dict__["*d"] = body.__dict__.pop("d")
24
- if "g" in body.__dict__:
25
- body.__dict__["**g"] = body.__dict__.pop("g")
26
- return route(body)
27
-
28
-
29
- class JacActionsTests(TestCaseHelper, TestCase):
30
- """Unit tests for Jac language"""
31
-
32
- def setUp(self):
33
- super().setUp()
34
- jra.remote_actions = {}
35
- jra.registered_apis = []
36
- jra.registered_endpoints = []
37
-
38
- def tearDown(self):
39
- super().tearDown()
40
-
41
- def test_remote_action_example(self):
42
- from typing import Union
43
-
44
- @jla.jaseci_action(
45
- act_group=["use"], aliases=["enc_question"], allow_remote=True
46
- )
47
- def question_encode(question: Union[str, list]):
48
- pass
49
-
50
- @jla.jaseci_action(act_group=["use"], aliases=["enc_answer"], allow_remote=True)
51
- def answer_encode(answer: Union[str, list], context: Union[str, list] = None):
52
- pass
53
-
54
- @jla.jaseci_action(act_group=["use"], allow_remote=True)
55
- def cos_sim_score(q_emb: list, a_emb: list):
56
- pass
57
-
58
- @jla.jaseci_action(act_group=["use"], aliases=["qa_score"], allow_remote=True)
59
- def dist_score(q_emb: list, a_emb: list):
60
- pass
61
-
62
- jra.serv_actions()
63
- self.assertEqual(
64
- jra.remote_actions,
65
- {
66
- "use.answer_encode": ["answer", "context"],
67
- "use.cos_sim_score": ["q_emb", "a_emb"],
68
- "use.dist_score": ["q_emb", "a_emb"],
69
- "use.enc_answer": ["answer", "context"],
70
- "use.enc_question": [
71
- "question",
72
- ],
73
- "use.qa_score": ["q_emb", "a_emb"],
74
- "use.question_encode": ["question"],
75
- },
76
- )
77
-
78
- def test_live_action_globals(self):
79
- self.assertGreater(len(jla.live_actions), 25)
80
-
81
- @patch("requests.post")
82
- def test_remote_action_kwargs(self, mock_post):
83
- remote_action = gen_remote_func_hook(
84
- url="https://example.com/api/v1/endpoint",
85
- act_name="example.action",
86
- param_names=["param1", "param2"],
87
- )
88
- payload = {"param1": "value1"}
89
- remote_action(**payload)
90
-
91
- mock_post.assert_called_once()
92
-
93
- _, kwargs = mock_post.call_args
94
-
95
- assert kwargs["json"] == payload
96
-
97
- @patch("requests.post")
98
- def test_remote_action_with_args_only(self, mock_post):
99
- @jla.jaseci_action(act_group=["test"], allow_remote=True)
100
- def args(a, b, c, *d, e=None, f=""):
101
- return {"a": a, "b": b, "c": c, "*d": d, "e": e, "f": f}
102
-
103
- app = jra.serv_actions()
104
- self.assertEqual(
105
- jra.remote_actions,
106
- {"test.args": ["a", "b", "c", "*d", "e", "f"]},
107
- )
108
-
109
- remote_action = gen_remote_func_hook(
110
- url="https://example.com/api/v1/endpoint",
111
- act_name="test.args",
112
- param_names=["a", "b", "c", "*d", "e", "f"],
113
- )
114
-
115
- #################################################
116
- # --------------- complete call --------------- #
117
- #################################################
118
-
119
- remote_action(
120
- "1", # a
121
- "2", # b
122
- "3", # c
123
- "4", # inside "*d": [4]
124
- "5", # inside "*d": [4, 5]
125
- "6", # inside "*d": [4, 5, 6]
126
- e="1", # e
127
- f="2", # f
128
- )
129
-
130
- self.assertEqual(
131
- {
132
- "a": "1",
133
- "b": "2",
134
- "c": "3",
135
- "*d": ["4", "5", "6"],
136
- "e": "1",
137
- "f": "2",
138
- },
139
- mock_post.call_args[1]["json"],
140
- )
141
-
142
- #################################################
143
- # ---------------- no args call --------------- #
144
- #################################################
145
-
146
- remote_action(
147
- "1", # a
148
- "2", # b
149
- "3", # c
150
- e="1", # e
151
- f="2", # f
152
- )
153
-
154
- self.assertEqual(
155
- {
156
- "a": "1",
157
- "b": "2",
158
- "c": "3",
159
- "e": "1",
160
- "f": "2",
161
- },
162
- mock_post.call_args[1]["json"],
163
- )
164
-
165
- # --------------------------------------------- action call --------------------------------------------- #
166
-
167
- route = app.routes[-1].endpoint
168
-
169
- ########################################################
170
- # --------------- complete action call --------------- #
171
- ########################################################
172
-
173
- self.assertEqual(
174
- {
175
- "a": "1",
176
- "b": "2",
177
- "c": "3",
178
- "*d": ("4", "5", "6"),
179
- "e": "1",
180
- "f": "2",
181
- },
182
- proc_req_body(
183
- route,
184
- RequestBody(
185
- a="1",
186
- b="2",
187
- c="3",
188
- d=["4", "5", "6"],
189
- e="1",
190
- f="2",
191
- ),
192
- ),
193
- )
194
-
195
- ########################################################
196
- # ---------------- no args action call --------------- #
197
- ########################################################
198
-
199
- self.assertEqual(
200
- {
201
- "a": "1",
202
- "b": "2",
203
- "c": "3",
204
- "*d": (),
205
- "e": "1",
206
- "f": "2",
207
- },
208
- proc_req_body(
209
- route,
210
- RequestBody(
211
- a="1",
212
- b="2",
213
- c="3",
214
- e="1",
215
- f="2",
216
- ),
217
- ),
218
- )
219
-
220
- @patch("requests.post")
221
- def test_remote_action_with_kwargs_only(self, mock_post):
222
- @jla.jaseci_action(act_group=["test"], allow_remote=True)
223
- def kwargs(a, b, c, e=None, f="", **g):
224
- return {"a": a, "b": b, "c": c, "e": e, "f": f, "**g": g}
225
-
226
- app = jra.serv_actions()
227
- self.assertEqual(
228
- jra.remote_actions,
229
- {"test.kwargs": ["a", "b", "c", "e", "f", "**g"]},
230
- )
231
-
232
- remote_action = gen_remote_func_hook(
233
- url="https://example.com/api/v1/endpoint",
234
- act_name="test.kwargs",
235
- param_names=["a", "b", "c", "e", "f", "**g"],
236
- )
237
-
238
- #################################################
239
- # --------------- complete call --------------- #
240
- #################################################
241
-
242
- remote_action(
243
- "1", # a
244
- "2", # b
245
- "3", # c
246
- e="1", # e
247
- f="2", # f
248
- g="3", # inside "**g": {"g": 3}
249
- h="4", # inside "**g": {"g": 3, "h": 4}
250
- i="5", # inside "**g": {"g": 3, "h": 4, "i": 5}
251
- )
252
-
253
- self.assertEqual(
254
- {
255
- "a": "1",
256
- "b": "2",
257
- "c": "3",
258
- "e": "1",
259
- "f": "2",
260
- "**g": {"g": "3", "h": "4", "i": "5"},
261
- },
262
- mock_post.call_args[1]["json"],
263
- )
264
-
265
- #################################################
266
- # --------------- no kwargs call -------------- #
267
- #################################################
268
-
269
- remote_action(
270
- "1", # a
271
- "2", # b
272
- "3", # c
273
- e="1", # e
274
- f="2", # f
275
- )
276
-
277
- self.assertEqual(
278
- {"a": "1", "b": "2", "c": "3", "e": "1", "f": "2"},
279
- mock_post.call_args[1]["json"],
280
- )
281
-
282
- # --------------------------------------------- action call --------------------------------------------- #
283
-
284
- route = app.routes[-1].endpoint
285
-
286
- ########################################################
287
- # --------------- complete action call --------------- #
288
- ########################################################
289
-
290
- self.assertEqual(
291
- {
292
- "a": "1",
293
- "b": "2",
294
- "c": "3",
295
- "e": "1",
296
- "f": "2",
297
- "**g": {"g": "3", "h": "4", "i": "5"},
298
- },
299
- proc_req_body(
300
- route,
301
- RequestBody(
302
- a="1",
303
- b="2",
304
- c="3",
305
- e="1",
306
- f="2",
307
- g={"g": "3", "h": "4", "i": "5"},
308
- ),
309
- ),
310
- )
311
-
312
- ########################################################
313
- # --------------- no kwargs action call -------------- #
314
- ########################################################
315
-
316
- self.assertEqual(
317
- {
318
- "a": "1",
319
- "b": "2",
320
- "c": "3",
321
- "e": "1",
322
- "f": "2",
323
- "**g": {},
324
- },
325
- proc_req_body(route, RequestBody(a="1", b="2", c="3", e="1", f="2")),
326
- )
327
-
328
- @patch("requests.post")
329
- def test_remote_action_with_args_kwargs(self, mock_post):
330
- @jla.jaseci_action(act_group=["test"], allow_remote=True)
331
- def args_kwargs(a, b, c, *d, e=None, f="", **g):
332
- return {"a": a, "b": b, "c": c, "*d": d, "e": e, "f": f, "**g": g}
333
-
334
- app = jra.serv_actions()
335
- self.assertEqual(
336
- jra.remote_actions,
337
- {"test.args_kwargs": ["a", "b", "c", "*d", "e", "f", "**g"]},
338
- )
339
-
340
- remote_action = gen_remote_func_hook(
341
- url="https://example.com/api/v1/endpoint",
342
- act_name="test.args_kwargs",
343
- param_names=["a", "b", "c", "*d", "e", "f", "**g"],
344
- )
345
-
346
- #################################################
347
- # --------------- complete call --------------- #
348
- #################################################
349
-
350
- remote_action(
351
- "1", # a
352
- "2", # b
353
- "3", # c
354
- "4", # inside "*d": [4]
355
- "5", # inside "*d": [4, 5]
356
- "6", # inside "*d": [4, 5, 6]
357
- e="1", # e
358
- f="2", # f
359
- g="3", # inside "**g": {"g": 3}
360
- h="4", # inside "**g": {"g": 3, "h": 4}
361
- i="5", # inside "**g": {"g": 3, "h": 4, "i": 5}
362
- )
363
-
364
- self.assertEqual(
365
- {
366
- "a": "1",
367
- "b": "2",
368
- "c": "3",
369
- "*d": ["4", "5", "6"],
370
- "e": "1",
371
- "f": "2",
372
- "**g": {"g": "3", "h": "4", "i": "5"},
373
- },
374
- mock_post.call_args[1]["json"],
375
- )
376
-
377
- #################################################
378
- # --------------- no kwargs call -------------- #
379
- #################################################
380
-
381
- remote_action(
382
- "1", # a
383
- "2", # b
384
- "3", # c
385
- "4", # inside "*d": [4]
386
- "5", # inside "*d": [4, 5]
387
- "6", # inside "*d": [4, 5, 6]
388
- e="1", # e
389
- f="2", # f
390
- )
391
-
392
- self.assertEqual(
393
- {"a": "1", "b": "2", "c": "3", "*d": ["4", "5", "6"], "e": "1", "f": "2"},
394
- mock_post.call_args[1]["json"],
395
- )
396
-
397
- #################################################
398
- # ---------------- no args call --------------- #
399
- #################################################
400
-
401
- remote_action(
402
- "1", # a
403
- "2", # b
404
- "3", # c
405
- e="1", # e
406
- f="2", # f
407
- g="3", # inside "**g": {"g": 3}
408
- h="4", # inside "**g": {"g": 3, "h": 4}
409
- i="5", # inside "**g": {"g": 3, "h": 4, "i": 5}
410
- )
411
-
412
- self.assertEqual(
413
- {
414
- "a": "1",
415
- "b": "2",
416
- "c": "3",
417
- "e": "1",
418
- "f": "2",
419
- "**g": {"g": "3", "h": "4", "i": "5"},
420
- },
421
- mock_post.call_args[1]["json"],
422
- )
423
-
424
- #################################################
425
- # ---------- no args and kwargs call ---------- #
426
- #################################################
427
-
428
- remote_action(
429
- "1", # a
430
- "2", # b
431
- "3", # c
432
- e="1", # e
433
- f="2", # f
434
- )
435
-
436
- self.assertEqual(
437
- {"a": "1", "b": "2", "c": "3", "e": "1", "f": "2"},
438
- mock_post.call_args[1]["json"],
439
- )
440
-
441
- # --------------------------------------------- action call --------------------------------------------- #
442
-
443
- route = app.routes[-1].endpoint
444
-
445
- ########################################################
446
- # --------------- complete action call --------------- #
447
- ########################################################
448
-
449
- self.assertEqual(
450
- {
451
- "a": "1",
452
- "b": "2",
453
- "c": "3",
454
- "*d": ("4", "5", "6"),
455
- "e": "1",
456
- "f": "2",
457
- "**g": {"g": "3", "h": "4", "i": "5"},
458
- },
459
- proc_req_body(
460
- route,
461
- RequestBody(
462
- a="1",
463
- b="2",
464
- c="3",
465
- d=["4", "5", "6"],
466
- e="1",
467
- f="2",
468
- g={"g": "3", "h": "4", "i": "5"},
469
- ),
470
- ),
471
- )
472
-
473
- ########################################################
474
- # --------------- no kwargs action call -------------- #
475
- ########################################################
476
-
477
- self.assertEqual(
478
- {
479
- "a": "1",
480
- "b": "2",
481
- "c": "3",
482
- "*d": ("4", "5", "6"),
483
- "e": "1",
484
- "f": "2",
485
- "**g": {},
486
- },
487
- proc_req_body(
488
- route, RequestBody(a="1", b="2", c="3", d=["4", "5", "6"], e="1", f="2")
489
- ),
490
- )
491
-
492
- ########################################################
493
- # ---------------- no args action call --------------- #
494
- ########################################################
495
-
496
- self.assertEqual(
497
- {
498
- "a": "1",
499
- "b": "2",
500
- "c": "3",
501
- "*d": (),
502
- "e": "1",
503
- "f": "2",
504
- "**g": {"g": "3", "h": "4", "i": "5"},
505
- },
506
- proc_req_body(
507
- route,
508
- RequestBody(
509
- a="1",
510
- b="2",
511
- c="3",
512
- e="1",
513
- f="2",
514
- g={"g": "3", "h": "4", "i": "5"},
515
- ),
516
- ),
517
- )
518
-
519
- ########################################################
520
- # ---------- no args and kwargs action call ---------- #
521
- ########################################################
522
-
523
- self.assertEqual(
524
- {
525
- "a": "1",
526
- "b": "2",
527
- "c": "3",
528
- "*d": (),
529
- "e": "1",
530
- "f": "2",
531
- "**g": {},
532
- },
533
- proc_req_body(route, RequestBody(a="1", b="2", c="3", e="1", f="2")),
534
- )
535
-
536
- def test_setup_decorated_as_startup(self):
537
- @jla.jaseci_action(act_group=["ex"], allow_remote=True)
538
- def setup(param: str = ""):
539
- pass
540
-
541
- app = jra.serv_actions()
542
- assert len(app.__dict__["router"].__dict__["on_startup"]) == 1
@@ -1,112 +0,0 @@
1
- from jaseci.jsorc.jsorc import JsOrc
2
- from jaseci.utils.test_core import CoreTest
3
- from unittest.mock import patch, Mock
4
- from kubernetes import config as kubernetes_config, client
5
- from jaseci.jsorc.jsorc_settings import JsOrcSettings
6
- from .fixture.elastic_resources import ELASTIC_RESOURCES
7
- from urllib3.response import HTTPResponse
8
-
9
-
10
- def aggregate_k8s_resources(mocked):
11
- """Aggregate k8s resources from multiple mocked calls to kube"""
12
- resources = {}
13
- call_args_list = mocked.call_args_list
14
- for call_args in call_args_list:
15
- args, _ = call_args
16
- # arg1: kind, arg2: name
17
- kind = args[0]
18
- name = args[1]
19
- if kind not in resources:
20
- resources[kind] = []
21
- # The resource name for Namespace is different from run to run
22
- if kind != "Namespace":
23
- resources[kind].append(name)
24
-
25
- return resources
26
-
27
-
28
- class MockKubeTest(CoreTest):
29
- """Custom test class that mock the environment to be inside a k8s cluster"""
30
-
31
- @patch.object(client.ApiClient, "call_api")
32
- @patch.object(kubernetes_config, "load_incluster_config")
33
- def setUp(self, mock_config, mock_call_api):
34
- super().setUp()
35
- JsOrcSettings.KUBE_CONFIG["enabled"] = True
36
- JsOrcSettings.KUBE_CONFIG["namespace"] = "jsorc-unit-test"
37
- JsOrcSettings.ELASTIC_CONFIG["enabled"] = True
38
- self.kube = JsOrc.svc("kube")
39
-
40
-
41
- class JsOrcTest(MockKubeTest):
42
- """Unit test for JsOrc"""
43
-
44
- def setUp(self):
45
- super().setUp()
46
-
47
- def test_jsorc_elastic_create(self):
48
- self.call(
49
- self.smast,
50
- [
51
- "config_update",
52
- {"name": "ELASTIC_CONFIG", "field_key": "enabled", "field_value": True},
53
- ],
54
- )
55
- with patch.object(self.kube, "read") as mock_read, patch.object(
56
- self.kube, "patch"
57
- ) as mock_patch, patch.object(self.kube, "create") as mock_create:
58
- # resource do not exist
59
- mocked_response = HTTPResponse(status=404)
60
- mock_read.return_value = mocked_response
61
- mock_patch.return_value = Mock()
62
- mock_create.return_value = Mock()
63
-
64
- JsOrc.svc_reset("elastic")
65
-
66
- # Mocking elastic health check to show its up and running
67
- with patch("jaseci.extens.svc.elastic_svc.Elastic._get") as mocked_get:
68
- mocked_get.return_value = {"timed_out": False}
69
- JsOrc.regenerate()
70
-
71
- read_resources = aggregate_k8s_resources(mock_read)
72
- assert read_resources == ELASTIC_RESOURCES
73
-
74
- create_resources = aggregate_k8s_resources(mock_create)
75
- assert create_resources == ELASTIC_RESOURCES
76
-
77
- # No resources should be patched
78
- assert not mock_patch.called
79
-
80
- def test_jsorc_elastic_patch(self):
81
- self.call(
82
- self.smast,
83
- [
84
- "config_update",
85
- {"name": "ELASTIC_CONFIG", "field_key": "enabled", "field_value": True},
86
- ],
87
- )
88
- with patch.object(self.kube, "read") as mock_read, patch.object(
89
- self.kube, "patch"
90
- ) as mock_patch, patch.object(self.kube, "create") as mock_create:
91
- mock_read.return_value = Mock()
92
- mock_patch.return_value = Mock()
93
- mock_create.return_value = Mock()
94
-
95
- JsOrc.svc_reset("elastic")
96
-
97
- # Mocking elastic health check to show its up and running
98
- with patch("jaseci.extens.svc.elastic_svc.Elastic._get") as mocked_get:
99
- mocked_get.return_value = {"timed_out": False}
100
- JsOrc.regenerate()
101
-
102
- read_resources = aggregate_k8s_resources(mock_read)
103
- assert read_resources == ELASTIC_RESOURCES
104
-
105
- patch_resources = aggregate_k8s_resources(mock_patch)
106
- # No need to patch Namespace
107
- del ELASTIC_RESOURCES["Namespace"]
108
-
109
- assert patch_resources == ELASTIC_RESOURCES
110
-
111
- # No resources should be created
112
- assert not mock_create.called
jaseci/prim/__init__.py DELETED
File without changes