HassamGani commited on
Generator: every customer gets a contact no other record shares, so a request naming only the contact points at one customer
Browse files- reorgbench/gen/company.py +8 -1
- tests/test_generator.py +11 -0
reorgbench/gen/company.py
CHANGED
|
@@ -85,7 +85,14 @@ def contact_of(g, c: str) -> str:
|
|
| 85 |
"""The customer's main contact, set once and kept on the record."""
|
| 86 |
a = g.accts[c]
|
| 87 |
if "contact" not in a.row:
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
if f"db.customers/{c}" in g.objects:
|
| 90 |
g.objects[f"db.customers/{c}"]["contact"] = a.row["contact"]
|
| 91 |
return a.row["contact"]
|
|
|
|
| 85 |
"""The customer's main contact, set once and kept on the record."""
|
| 86 |
a = g.accts[c]
|
| 87 |
if "contact" not in a.row:
|
| 88 |
+
# unique across every customer record in the world (a queue's jobs share it): requests name a customer by
|
| 89 |
+
# contact alone ("Noor Novak's account"), and two customers with one contact would make that ambiguous
|
| 90 |
+
used = {d.get("contact") for o, d in g.objects.items() if o.startswith("db.customers/")} | \
|
| 91 |
+
{x.row.get("contact") for x in g.accts.values()}
|
| 92 |
+
name = f"{g.rng.choice(_FIRST)} {g.rng.choice(_LAST)}"
|
| 93 |
+
while name in used:
|
| 94 |
+
name = f"{g.rng.choice(_FIRST)} {g.rng.choice(_LAST)}"
|
| 95 |
+
a.row["contact"] = name
|
| 96 |
if f"db.customers/{c}" in g.objects:
|
| 97 |
g.objects[f"db.customers/{c}"]["contact"] = a.row["contact"]
|
| 98 |
return a.row["contact"]
|
tests/test_generator.py
CHANGED
|
@@ -383,3 +383,14 @@ def test_a_merged_customer_can_be_closed_on_either_ticket():
|
|
| 383 |
assert not ck.check(w, None)
|
| 384 |
w.objects[f"tickets/{old}"]["data"] = {**w.data(f"tickets/{old}"), "status": "closed"}
|
| 385 |
assert ck.check(w, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
assert not ck.check(w, None)
|
| 384 |
w.objects[f"tickets/{old}"]["data"] = {**w.data(f"tickets/{old}"), "status": "closed"}
|
| 385 |
assert ck.check(w, None)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
@pytest.mark.parametrize("seed", [6, 11, 25])
|
| 389 |
+
def test_no_two_customers_share_a_contact(seed):
|
| 390 |
+
# probe BC: "hold off on Noor Novak's account" named two customers, because two records shared that contact
|
| 391 |
+
from collections import Counter
|
| 392 |
+
|
| 393 |
+
from reorgbench.gen.queue import generate_queue
|
| 394 |
+
t = generate_queue(seed)
|
| 395 |
+
named = Counter(d["contact"] for o, d in t.initial_objects.items() if o.startswith("db.customers/") and "contact" in d)
|
| 396 |
+
assert named and max(named.values()) == 1
|