EnergyVenom commited on
Commit
11e21cd
·
verified ·
1 Parent(s): f56442a

Deploy 52e5bec: the scout skips the tests' own invoices

Browse files
coworker/platform/discovery.py CHANGED
@@ -94,6 +94,14 @@ def _names(field) -> list[str]:
94
  return [str(f) for f in field] if isinstance(field, (list, tuple)) else [str(field)]
95
 
96
 
 
 
 
 
 
 
 
 
97
  def sample_test_data(pod, area: dict) -> dict[str, list[str]]:
98
  """{key: [most frequent values]} for one area, from its latest records. Empty keys are left out. When the pod
99
  refuses the field list (an attribute it does not have: HTTP 400), the records are read whole and each key takes
@@ -106,14 +114,17 @@ def sample_test_data(pod, area: dict) -> dict[str, list[str]]:
106
  fields = {k: _names(f) for k, f in raw.items()}
107
  if spec.get("parent"):
108
  pkey = spec.get("parent_key") or ""
109
- rows = parents.get(spec["parent"]) or _items(pod, spec["parent"], {"limit": 3, "fields": pkey})
110
  items: list[dict] = []
111
- for p in rows[:3]:
112
- if p.get(pkey) not in (None, ""):
113
- path = spec["resource"].replace("{key}", str(p[pkey]))
114
- items += _items(pod, path, {"limit": 10, "fields": ",".join(wanted)}) or _items(pod, path, {"limit": 10})
 
 
115
  else:
116
- params = {"limit": SAMPLE, "fields": ",".join(sorted(set(wanted) | ({spec.get("key_field")} - {None})))}
 
117
  if spec.get("order_by"):
118
  params["orderBy"] = spec["order_by"]
119
  items = _items(pod, spec["resource"], params)
@@ -121,6 +132,8 @@ def sample_test_data(pod, area: dict) -> dict[str, list[str]]:
121
  items = _items(pod, spec["resource"], {k: v for k, v in params.items() if k != "orderBy"})
122
  if not items: # a field this pod does not have refuses the whole list: read the records whole
123
  items = _items(pod, spec["resource"], {"limit": SAMPLE})
 
 
124
  parents[spec["resource"]] = items
125
  for key, names in fields.items():
126
  vals = next((v for v in (_top(items, n) for n in names) if v), [])
 
94
  return [str(f) for f in field] if isinstance(field, (list, tuple)) else [str(field)]
95
 
96
 
97
+ OWN_PREFIX = "FPT-" # documents the test runs create (automation/src/fusion/ui.ts testNumber): never the pod's own data
98
+ PARENTS = 10 # parent records whose child rows are read, newest first, until one carries the values
99
+
100
+
101
+ def _own(item: dict, field: str | None) -> bool:
102
+ return bool(field) and str(item.get(field) or "").startswith(OWN_PREFIX)
103
+
104
+
105
  def sample_test_data(pod, area: dict) -> dict[str, list[str]]:
106
  """{key: [most frequent values]} for one area, from its latest records. Empty keys are left out. When the pod
107
  refuses the field list (an attribute it does not have: HTTP 400), the records are read whole and each key takes
 
114
  fields = {k: _names(f) for k, f in raw.items()}
115
  if spec.get("parent"):
116
  pkey = spec.get("parent_key") or ""
117
+ rows = parents.get(spec["parent"]) or _items(pod, spec["parent"], {"limit": PARENTS, "fields": pkey})
118
  items: list[dict] = []
119
+ # newest first, until a parent's rows carry the values: the newest invoices may be ones a test left without a line
120
+ for p in [r for r in rows if r.get(pkey) not in (None, "")][:PARENTS]:
121
+ path = spec["resource"].replace("{key}", str(p[pkey]))
122
+ items += _items(pod, path, {"limit": 10, "fields": ",".join(wanted)}) or _items(pod, path, {"limit": 10})
123
+ if all(any(_top(items, n) for n in names) for names in fields.values()):
124
+ break
125
  else:
126
+ own = spec.get("own_field")
127
+ params = {"limit": SAMPLE, "fields": ",".join(sorted(set(wanted) | ({spec.get("key_field"), own} - {None})))}
128
  if spec.get("order_by"):
129
  params["orderBy"] = spec["order_by"]
130
  items = _items(pod, spec["resource"], params)
 
132
  items = _items(pod, spec["resource"], {k: v for k, v in params.items() if k != "orderBy"})
133
  if not items: # a field this pod does not have refuses the whole list: read the records whole
134
  items = _items(pod, spec["resource"], {"limit": SAMPLE})
135
+ # the pod's own records only: the invoices our tests created would otherwise be "the latest records"
136
+ items = [i for i in items if not _own(i, own)]
137
  parents[spec["resource"]] = items
138
  for key, names in fields.items():
139
  vals = next((v for v in (_top(items, n) for n in names) if v), [])
coworker/platform/fusion_catalog.py CHANGED
@@ -25,7 +25,7 @@ AREAS: list[dict] = [
25
  "processes": ["Invoice entry", "Invoice validation and holds", "Invoice matching", "Credit memos", "Prepayments", "Payments"],
26
  "navigator": ["Payables > Invoices", "Payables > Payments"],
27
  "readiness": {"family": "erp", "product": "fins", "match": ["Payables", "Payment", "Supplier Invoice", "Invoice Imaging", "Withholding"]},
28
- "test_data": [{"resource": "invoices", "order_by": "InvoiceId:desc", "key_field": "InvoiceId",
29
  "fields": {"business_unit": "BusinessUnit", "supplier": "Supplier", "supplier_site": "SupplierSite",
30
  "currency": "InvoiceCurrency", "payment_terms": "PaymentTerms", "invoice_type": "InvoiceType"}},
31
  {"resource": "invoices/{key}/child/invoiceLines", "parent": "invoices", "parent_key": "InvoiceId",
 
25
  "processes": ["Invoice entry", "Invoice validation and holds", "Invoice matching", "Credit memos", "Prepayments", "Payments"],
26
  "navigator": ["Payables > Invoices", "Payables > Payments"],
27
  "readiness": {"family": "erp", "product": "fins", "match": ["Payables", "Payment", "Supplier Invoice", "Invoice Imaging", "Withholding"]},
28
+ "test_data": [{"resource": "invoices", "order_by": "InvoiceId:desc", "key_field": "InvoiceId", "own_field": "InvoiceNumber",
29
  "fields": {"business_unit": "BusinessUnit", "supplier": "Supplier", "supplier_site": "SupplierSite",
30
  "currency": "InvoiceCurrency", "payment_terms": "PaymentTerms", "invoice_type": "InvoiceType"}},
31
  {"resource": "invoices/{key}/child/invoiceLines", "parent": "invoices", "parent_key": "InvoiceId",
coworker/tests/test_discovery.py CHANGED
@@ -78,6 +78,20 @@ class TestDiscoveryRules(unittest.TestCase):
78
  child_calls = [path for path, _ in pod.calls if "/child/" in path]
79
  self.assertLessEqual(len(child_calls), 3)
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def test_a_missing_field_or_resource_leaves_the_key_out_instead_of_inventing_one(self):
82
  pod = ScriptedPod({"invoices": (200, [{"InvoiceId": 1, "Supplier": "Only Supplier"}]), "suppliers": (200, [{}])})
83
  td = discovery.sample_test_data(pod, self.area("AP"))
 
78
  child_calls = [path for path, _ in pod.calls if "/child/" in path]
79
  self.assertLessEqual(len(child_calls), 3)
80
 
81
+ def test_the_tests_own_invoices_are_not_the_pods_records(self):
82
+ """Seen on a real pod: the newest invoices were ones our tests had saved without a line, so the distribution
83
+ account was not found and three Payables scenarios stopped at their first line."""
84
+ ours = [{"InvoiceId": 900 + i, "InvoiceNumber": f"FPT-AP2-{i}", "Supplier": "Test Supplier", "BusinessUnit": "BU Test"} for i in range(5)]
85
+ real = [{**inv, "InvoiceNumber": f"INV-{inv['InvoiceId']}"} for inv in INVOICES]
86
+ lines = {f"invoices/{i['InvoiceId']}/child/invoiceLines": (200, []) for i in ours + real[:2]}
87
+ lines[f"invoices/{real[2]['InvoiceId']}/child/invoiceLines"] = (200, [{"DistributionCombination": "01-100-5000"}])
88
+ pod = ScriptedPod({"invoices": (200, ours + real), "suppliers": (200, [{}]), **lines})
89
+ td = discovery.sample_test_data(pod, self.area("AP"))
90
+ self.assertEqual(td["supplier"], ["Acme Supplies"]) # not the test's own supplier
91
+ self.assertNotIn("BU Test", td["business_unit"])
92
+ self.assertEqual(td["account"], ["01-100-5000"]) # found on the third real invoice, past two without lines
93
+ self.assertFalse(any("/90" in path for path, _ in pod.calls if "/child/" in path)) # our invoices were not read
94
+
95
  def test_a_missing_field_or_resource_leaves_the_key_out_instead_of_inventing_one(self):
96
  pod = ScriptedPod({"invoices": (200, [{"InvoiceId": 1, "Supplier": "Only Supplier"}]), "suppliers": (200, [{}])})
97
  td = discovery.sample_test_data(pod, self.area("AP"))