jaseci 1.4.1.8__py3-none-any.whl → 1.4.2__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.

@@ -4,6 +4,26 @@ from jaseci.utils.utils import TestCaseHelper
4
4
  import jaseci.jsorc.live_actions as jla
5
5
  import jaseci.jsorc.remote_actions as jra
6
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)
7
27
 
8
28
 
9
29
  class JacActionsTests(TestCaseHelper, TestCase):
@@ -11,6 +31,9 @@ class JacActionsTests(TestCaseHelper, TestCase):
11
31
 
12
32
  def setUp(self):
13
33
  super().setUp()
34
+ jra.remote_actions = {}
35
+ jra.registered_apis = []
36
+ jra.registered_endpoints = []
14
37
 
15
38
  def tearDown(self):
16
39
  super().tearDown()
@@ -71,6 +94,445 @@ class JacActionsTests(TestCaseHelper, TestCase):
71
94
 
72
95
  assert kwargs["json"] == payload
73
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
+
74
536
  def test_setup_decorated_as_startup(self):
75
537
  @jla.jaseci_action(act_group=["ex"], allow_remote=True)
76
538
  def setup(param: str = ""):
jaseci/prim/ability.py CHANGED
@@ -80,12 +80,6 @@ class Ability(Element, JacCode, Interp):
80
80
  else:
81
81
  try:
82
82
  result = func(*param_list["args"], **param_list["kwargs"])
83
- except TypeError as e:
84
- params = str(inspect.signature(func))
85
- interp.rt_error(
86
- f"Invalid arguments {param_list} to action call {self.name}! Valid paramters are {params}.",
87
- jac_ast,
88
- )
89
83
  except Exception as e:
90
84
  interp.rt_error(e, jac_ast, True)
91
85
  t = time.time() - ts
jaseci/prim/edge.py CHANGED
@@ -103,8 +103,13 @@ class Edge(Element, Anchored):
103
103
  """
104
104
  Write self through hook to persistent storage
105
105
  """
106
+
106
107
  if self.is_fast():
107
108
  self._persist = False
109
+ if self.from_node_id:
110
+ self.from_node().save()
111
+ if self.to_node_id:
112
+ self.to_node().save()
108
113
  super().save()
109
114
 
110
115
  def destroy(self):
jaseci/prim/node.py CHANGED
@@ -52,16 +52,23 @@ class Node(Element, Anchored):
52
52
  for k in self.fast_edges.keys():
53
53
  for v in self.fast_edges[k]:
54
54
  link_order = [v[0], self.jid] if v[1] == FROM else [self.jid, v[0]]
55
- edge = Edge(
56
- m_id=self._m_id, h=self._h, kind="edge", name=k, auto_save=False
57
- )
58
- edge.from_node_id = link_order[0]
59
- edge.to_node_id = link_order[1]
60
- edge.bidirected = v[1] == BI
61
- edge.jid = v[2] if len(v) > 2 else uuid.uuid4().urn
62
- edge.context = v[3] if len(v) > 3 else {}
63
- edge.save()
64
- self._fast_edge_ids.add_obj(edge)
55
+ edge = self._h.get_obj(self._m_id, v[2])
56
+ if edge:
57
+ v[3] = edge.context
58
+ else:
59
+ edge = Edge(
60
+ m_id=self._m_id, h=self._h, kind="edge", name=k, auto_save=False
61
+ )
62
+ edge.from_node_id = link_order[0]
63
+ edge.to_node_id = link_order[1]
64
+ edge.bidirected = v[1] == BI
65
+ edge.jid = v[2] if len(v) > 2 else uuid.uuid4().urn
66
+ edge.context = v[3] if len(v) > 3 else {}
67
+ # old `edge.save()` might be confusing
68
+ # this line doesn't mean it has to be saved on db
69
+ # it only needs to be available on cache (memory, redis)
70
+ self._h.commit_obj_to_cache(edge, True)
71
+ self._fast_edge_ids.add_obj(edge, bypass=True)
65
72
 
66
73
  def smart_add_edge(self, obj):
67
74
  # make sure fast edges built
jaseci/prim/sentinel.py CHANGED
@@ -145,7 +145,10 @@ class Sentinel(Element, JacCode, SentinelInterp):
145
145
  """Returns the architype that matches object"""
146
146
  ret = self.arch_ids.get_obj_by_name(name=obj.name, kind=obj.kind)
147
147
  if ret is None:
148
- self.rt_error(f"Unable to find architype for {obj.name}, {obj.kind}")
148
+ self.rt_subtle_error(
149
+ f"Unable to find architype for {obj.name}, {obj.kind}",
150
+ self._cur_jac_ast,
151
+ )
149
152
  return ret
150
153
 
151
154
  def run_tests(self, specific=None, profiling=False, detailed=False, silent=False):
@@ -1186,3 +1186,108 @@ struct_types = """
1186
1186
  report [a.basic.apple.apple, a.basic.apple.orange];
1187
1187
  }
1188
1188
  """
1189
+
1190
+
1191
+ simple_graph = """
1192
+ node a1 {has val = 0;}
1193
+ node a2 {has val = 0;}
1194
+ node a3 {has val = 0;}
1195
+ node b1 {has val = 0;}
1196
+ node b2 {has val = 0;}
1197
+ edge e1 {has val = 0;}
1198
+ edge e2 {has val = 0;}
1199
+ edge e3 {has val = 0;}
1200
+
1201
+ walker sample {
1202
+ root {
1203
+ take --> node::a1 else: take spawn here +[e1]+> node::a1;
1204
+ take --> node::b1 else: take spawn here ++> node::b1;
1205
+ }
1206
+
1207
+ a1: take --> node::a2 else {
1208
+ report --> node::a2;
1209
+ report -[e2]-> node::a2;
1210
+ take spawn here +[e2]+> node::a2;
1211
+ }
1212
+ a2: take --> node::a3 else: take spawn here +[e3]+> node::a3;
1213
+ b1: take --> node::b2 else: take spawn here ++> node::b2;
1214
+ }
1215
+
1216
+ walker sample2 {
1217
+ root {
1218
+ take --> node::a1;
1219
+ take --> node::b1;
1220
+ }
1221
+ a1: take --> node::a2;
1222
+ a2: take --> node::a3;
1223
+ a3: here.val = 1;
1224
+ b1: take --> node::b2;
1225
+ b2: here.val = 1;
1226
+ }
1227
+
1228
+ walker sample3 {
1229
+ root {
1230
+ take --> node::a1;
1231
+ take --> node::b1;
1232
+ }
1233
+ a1 {
1234
+ -[e2]->.edge[0].val = 1;
1235
+ take --> node::a2;
1236
+ }
1237
+ a2 {
1238
+ take --> node::a3;
1239
+ here not --> node::a3;
1240
+ }
1241
+ a3: here.val = 2;
1242
+ b1: take --> node::b2;
1243
+ }
1244
+ """
1245
+
1246
+ simple_graph2 = """
1247
+ node a1 {has val = 0;}
1248
+ edge e1 {has val = 0;}
1249
+
1250
+ walker sample {
1251
+ root: report spawn here <+[e1]+ node::a1;
1252
+ }
1253
+
1254
+ walker sample2 {
1255
+ root: report <-[e1]- node::a1.edge[0].val;
1256
+ a1 {
1257
+ --> node::root.edge[0].val = 4;
1258
+ report -[e1]->.edge[0].val;
1259
+ take --> node::root;
1260
+ }
1261
+ }
1262
+
1263
+ walker sample3 {
1264
+ root {
1265
+ report <-[e1]- node::a1.edge[0].val;
1266
+ take <-[e1]- node::a1;
1267
+ }
1268
+
1269
+ a1: report -[e1]->.edge[0].val;
1270
+ }
1271
+
1272
+ walker sample4 {
1273
+ root {
1274
+ <-- node::a1.edge[0].val = 6;
1275
+ report <-[e1]- node::a1.edge[0].val;
1276
+ take <-[e1]- node::a1;
1277
+ }
1278
+ a1: report -[e1]-> node::root.edge[0].val;
1279
+ }
1280
+
1281
+ walker sample5 {
1282
+ root: report <-[e1]-.edge[0].val;
1283
+ a1 {
1284
+ report -[e1]-> node::root.edge[0].val;
1285
+ take -[e1]-> node::root;
1286
+ }
1287
+ }
1288
+
1289
+ walker sample6 {
1290
+ root: <-[e1]- node::a1.edge[0].val = 8;
1291
+ a1: report --> node::root.edge[0].val;
1292
+ }
1293
+ """
@@ -42,6 +42,7 @@ class StripeTests(CoreTest):
42
42
  stripe.Subscription.modify = Mock()
43
43
  stripe.Invoice.retrieve = Mock()
44
44
  stripe.SubscriptionItem.create_usage_record = Mock()
45
+ stripe.SubscriptionItem.list_usage_record_summaries = Mock()
45
46
  stripe.checkout.Session.create = Mock()
46
47
  stripe.billing_portal.Session.create = Mock()
47
48
 
@@ -194,6 +195,10 @@ class StripeTests(CoreTest):
194
195
  def test_stripe_create_usage_report(self, ret):
195
196
  stripe.SubscriptionItem.create_usage_record.assert_called()
196
197
 
198
+ @jac_testcase("stripe.jac", "list_usage_report")
199
+ def test_stripe_list_usage_report(self, ret):
200
+ stripe.SubscriptionItem.list_usage_record_summaries.assert_called()
201
+
197
202
  @jac_testcase("stripe.jac", "create_checkout_session")
198
203
  def test_stripe_create_checkout_session(self, ret):
199
204
  stripe.checkout.Session.create.assert_called_once_with(