sefrone-api-e2e 1.2.1__tar.gz → 1.2.3__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.
Files changed (28) hide show
  1. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/PKG-INFO +1 -1
  2. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/api_e2e_manager.py +62 -0
  3. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/runner_rest_api.py +48 -4
  4. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e.egg-info/PKG-INFO +1 -1
  5. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/setup.py +1 -1
  6. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/README.md +0 -0
  7. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/__init__.py +0 -0
  8. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/0_check_features.yaml +0 -0
  9. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/1_normal_auth_flow.yaml +0 -0
  10. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/2_account_endpoints.yaml +0 -0
  11. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/3_admin_account_endpoints.yaml +0 -0
  12. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/4_workspace_endpoints.yaml +0 -0
  13. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/5_apikey_endpoints.yaml +0 -0
  14. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/6_project_endpoints.yaml +0 -0
  15. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e/Scenarios/Auth/7_email_2fa_flow.yaml +0 -0
  16. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/e2e_scenarios_manager.py +0 -0
  17. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/env_patch.py +0 -0
  18. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/json_mock_server.py +0 -0
  19. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/runner_assets.py +0 -0
  20. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/runner_email_mock.py +0 -0
  21. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/runner_satim_mock.py +0 -0
  22. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/runner_webhook_mock.py +0 -0
  23. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e/step_runner.py +0 -0
  24. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e.egg-info/SOURCES.txt +0 -0
  25. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e.egg-info/dependency_links.txt +0 -0
  26. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e.egg-info/requires.txt +0 -0
  27. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/sefrone_api_e2e.egg-info/top_level.txt +0 -0
  28. {sefrone_api_e2e-1.2.1 → sefrone_api_e2e-1.2.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sefrone_api_e2e
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: A Python package to provide e2e testing helpers for sefrone API projects
5
5
  Home-page: https://bitbucket.org/sefrone/sefrone_pypi
6
6
  Author: Sefrone
@@ -396,6 +396,68 @@ class ApiE2ETestsManager:
396
396
  i = close_paren + 1
397
397
  if i < len(expr) and expr[i] == ".":
398
398
  i += 1
399
+ elif prop == "where":
400
+ close_paren = expr.find(")", end_pos)
401
+ if close_paren == -1:
402
+ raise ValueError(f"Unclosed parenthesis in: {expr}")
403
+ condition_str = expr[end_pos + 1:close_paren].strip()
404
+ if not isinstance(val, list):
405
+ raise KeyError(f"Cannot call where() on {type(val).__name__}")
406
+ cond_operators = ["not in", ">=", "<=", ">", "<", "==", "!=", "in", "include"]
407
+ cond_op = None
408
+ cond_left = cond_right = ""
409
+ for cop in cond_operators:
410
+ if f" {cop} " in condition_str:
411
+ cond_op = cop
412
+ cond_left, cond_right = [p.strip() for p in condition_str.split(f" {cop} ", 1)]
413
+ break
414
+ if not cond_op:
415
+ raise ValueError(f"Unsupported where() condition: '{condition_str}'")
416
+ def _parse_where_literal(s):
417
+ if (s.startswith("'") and s.endswith("'")) or (s.startswith('"') and s.endswith('"')):
418
+ return s[1:-1]
419
+ elif re.match(r'^-?\d+\.\d+$', s):
420
+ return float(s)
421
+ elif re.match(r'^-?\d+$', s):
422
+ return int(s)
423
+ elif s.lower() == 'true':
424
+ return True
425
+ elif s.lower() == 'false':
426
+ return False
427
+ elif s.lower() == 'none':
428
+ return None
429
+ return s
430
+ right_literal = _parse_where_literal(cond_right)
431
+ filtered = []
432
+ for item in val:
433
+ if isinstance(item, dict) and cond_left in item:
434
+ item_val = item[cond_left]
435
+ match = False
436
+ if cond_op == "==" :
437
+ match = item_val == right_literal
438
+ elif cond_op == "!=":
439
+ match = item_val != right_literal
440
+ elif cond_op == ">":
441
+ match = item_val > right_literal
442
+ elif cond_op == "<":
443
+ match = item_val < right_literal
444
+ elif cond_op == ">=":
445
+ match = item_val >= right_literal
446
+ elif cond_op == "<=":
447
+ match = item_val <= right_literal
448
+ elif cond_op == "in":
449
+ match = item_val in right_literal
450
+ elif cond_op == "not in":
451
+ match = item_val not in right_literal
452
+ elif cond_op == "include":
453
+ match = right_literal in item_val
454
+ if match:
455
+ filtered.append(item)
456
+ val = filtered
457
+ current_path += f".where({condition_str})"
458
+ i = close_paren + 1
459
+ if i < len(expr) and expr[i] == ".":
460
+ i += 1
399
461
  else:
400
462
  raise ValueError(f"Unsupported function '{prop}()': {expr}")
401
463
  elif isinstance(val, dict) and prop in val:
@@ -1,5 +1,6 @@
1
1
  import hashlib
2
2
  import os
3
+ import random
3
4
  import secrets
4
5
  import time
5
6
  from typing import Any
@@ -66,20 +67,63 @@ class RestApiRunner(StepRunner):
66
67
  def _handle_randomize(self, step: dict, ctx: RunContext) -> StepResult:
67
68
  spec = step["randomize"]
68
69
  if isinstance(spec, dict):
69
- for key, length in spec.items():
70
- if not isinstance(length, int) or length <= 0:
71
- length = 8
72
- ctx.store_value(key, self._random_string(length))
70
+ for key, value in spec.items():
71
+ ctx.store_value(key, self._generate_random_value(value))
73
72
  elif isinstance(spec, list):
74
73
  for key in spec:
75
74
  ctx.store_value(key, self._random_string(8))
76
75
  return StepResult.passed()
77
76
 
77
+ def _generate_random_value(self, spec) -> str:
78
+ """
79
+ Generate a random value from a spec:
80
+
81
+ - ``int`` (e.g. ``8``) → random hex string of that length (backward-compat)
82
+ - ``{type: string, length: N}`` → random hex string of length N
83
+ - ``{type: string, length: N, chars: digits}`` → digits-only string of length N
84
+ - ``{type: string, length: N, chars: hex}`` → hex string of length N (default)
85
+ - ``{type: number, min: N, max: M}`` → random integer in [min, max] (inclusive)
86
+ - ``{type: float, min: N, max: M}`` → random float in [min, max]
87
+ """
88
+ if isinstance(spec, int):
89
+ length = spec if spec > 0 else 8
90
+ return self._random_string(length)
91
+
92
+ if isinstance(spec, dict):
93
+ kind = str(spec.get("type", "string")).lower()
94
+
95
+ if kind == "string":
96
+ length = int(spec.get("length", 8))
97
+ if length <= 0:
98
+ length = 8
99
+ chars = str(spec.get("chars", "hex")).lower()
100
+ if chars == "digits":
101
+ return self._random_digits(length)
102
+ return self._random_string(length)
103
+
104
+ if kind == "number":
105
+ min_val = int(spec.get("min", 0))
106
+ max_val = int(spec.get("max", 9999))
107
+ return str(random.randint(min_val, max_val))
108
+
109
+ if kind == "float":
110
+ min_val = float(spec.get("min", 0.0))
111
+ max_val = float(spec.get("max", 1.0))
112
+ precision = int(spec.get("precision", 2))
113
+ return str(round(random.uniform(min_val, max_val), precision))
114
+
115
+ # fallback
116
+ return self._random_string(8)
117
+
78
118
  @staticmethod
79
119
  def _random_string(length: int = 8) -> str:
80
120
  n_bytes = (length + 1) // 2
81
121
  return secrets.token_hex(n_bytes)[:length]
82
122
 
123
+ @staticmethod
124
+ def _random_digits(length: int = 8) -> str:
125
+ return "".join(str(random.randint(0, 9)) for _ in range(length))
126
+
83
127
  # ------------------------------------------------------------------ #
84
128
  # HTTP
85
129
  # ------------------------------------------------------------------ #
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sefrone_api_e2e
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: A Python package to provide e2e testing helpers for sefrone API projects
5
5
  Home-page: https://bitbucket.org/sefrone/sefrone_pypi
6
6
  Author: Sefrone
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="sefrone_api_e2e",
8
- version="1.2.1",
8
+ version="1.2.3",
9
9
  author="Sefrone",
10
10
  author_email="contact@sefrone.com",
11
11
  description="A Python package to provide e2e testing helpers for sefrone API projects",