|
| 1 | +import csv |
| 2 | +import subprocess |
| 3 | +import uuid |
| 4 | + |
| 5 | + |
| 6 | +def random_ref(prefix): |
| 7 | + return prefix + "-" + uuid.uuid4().hex[:10] |
| 8 | + |
| 9 | + |
| 10 | +def test_cli_app_reads_csvs_with_batches_and_orders_and_outputs_allocations(make_csv): |
| 11 | + sku1, sku2 = random_ref("s1"), random_ref("s2") |
| 12 | + batch1, batch2, batch3 = random_ref("b1"), random_ref("b2"), random_ref("b3") |
| 13 | + order_ref = random_ref("o") |
| 14 | + make_csv("batches.csv", [ |
| 15 | + ["ref", "sku", "qty", "eta"], |
| 16 | + [batch1, sku1, 100, ""], |
| 17 | + [batch2, sku2, 100, "2011-01-01"], |
| 18 | + [batch3, sku2, 100, "2011-01-02"], |
| 19 | + ]) |
| 20 | + orders_csv = make_csv("orders.csv", [ |
| 21 | + ["orderid", "sku", "qty"], |
| 22 | + [order_ref, sku1, 3], |
| 23 | + [order_ref, sku2, 12], |
| 24 | + ]) |
| 25 | + |
| 26 | + subprocess.run(["allocate-from-csv", orders_csv.parent]) |
| 27 | + |
| 28 | + expected_output_csv = orders_csv.parent / "allocations.csv" |
| 29 | + with open(expected_output_csv) as f: |
| 30 | + rows = list(csv.reader(f)) |
| 31 | + assert rows == [ |
| 32 | + ["orderid", "sku", "qty", "batchref"], |
| 33 | + [order_ref, sku1, "3", batch1], |
| 34 | + [order_ref, sku2, "12", batch2], |
| 35 | + ] |
0 commit comments