From c72b661f461046a19ec984a43aa5c43baed12c7c Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 25 Feb 2021 01:34:22 +0000 Subject: [PATCH 1/7] book is no longer preorder --- index.html | 4 ++-- pages/index.html | 4 ++-- rss.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 4dff04a..255239f 100644 --- a/index.html +++ b/index.html @@ -70,7 +70,7 @@

The Book

  • - Preorder print books on + Buy print books on Amazon.com or Amazon.co.uk. @@ -81,7 +81,7 @@

    The Book

  • Or - read it for free on this site (license: CC-By-NC-ND). + read it for free on this site (license: CC-By-NC-ND).
  • diff --git a/pages/index.html b/pages/index.html index ac58d8b..940aa2e 100644 --- a/pages/index.html +++ b/pages/index.html @@ -35,7 +35,7 @@

    The Book

  • - Preorder print books on + Buy print books on Amazon.com or Amazon.co.uk. @@ -46,7 +46,7 @@

    The Book

  • Or - read it for free on this site (license: CC-By-NC-ND). + read it for free on this site (license: CC-By-NC-ND).
  • diff --git a/rss.xml b/rss.xml index 18c0aa2..e92ce73 100644 --- a/rss.xml +++ b/rss.xml @@ -7,7 +7,7 @@ Simple patterns for building complex apps https://www.cosmicpython.com - Wed, 20 Jan 2021 10:08:39 -0000 + Wed, 20 Jan 2021 10:10:24 -0000 Sat, 4 Jan 2020 19:15:54 -0500 From febc00049143ec8ba05fc109caa8e42d166db995 Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 25 Feb 2021 01:35:06 +0000 Subject: [PATCH 2/7] book updates for black --- book/appendix_csvs.html | 136 +++++++++--------- book/appendix_django.html | 44 +++--- book/appendix_project_structure.html | 26 ++-- book/chapter_01_domain_model.html | 70 ++++++---- book/chapter_02_repository.html | 32 ++--- book/chapter_03_abstractions.html | 42 +++--- book/chapter_04_service_layer.html | 146 ++++++++++---------- book/chapter_05_high_gear_low_gear.html | 52 ++++--- book/chapter_06_uow.html | 72 +++++----- book/chapter_07_aggregate.html | 56 ++++---- book/chapter_08_events_and_message_bus.html | 74 +++++----- book/chapter_09_all_messagebus.html | 90 ++++++------ book/chapter_10_commands.html | 37 ++--- book/chapter_11_external_events.html | 52 ++++--- book/chapter_12_cqrs.html | 117 +++++++++------- book/chapter_13_dependency_injection.html | 92 ++++++------ book/preface.html | 6 +- 17 files changed, 596 insertions(+), 548 deletions(-) diff --git a/book/appendix_csvs.html b/book/appendix_csvs.html index 1ea5de4..2c6ed68 100644 --- a/book/appendix_csvs.html +++ b/book/appendix_csvs.html @@ -168,33 +168,31 @@

    Appendix C: Swapping Out the Infrastructure: Do Everythin
    -
    def test_cli_app_reads_csvs_with_batches_and_orders_and_outputs_allocations(
    -        make_csv
    -):
    -    sku1, sku2 = random_ref('s1'), random_ref('s2')
    -    batch1, batch2, batch3 = random_ref('b1'), random_ref('b2'), random_ref('b3')
    -    order_ref = random_ref('o')
    -    make_csv('batches.csv', [
    -        ['ref', 'sku', 'qty', 'eta'],
    -        [batch1, sku1, 100, ''],
    -        [batch2, sku2, 100, '2011-01-01'],
    -        [batch3, sku2, 100, '2011-01-02'],
    +
    def test_cli_app_reads_csvs_with_batches_and_orders_and_outputs_allocations(make_csv):
    +    sku1, sku2 = random_ref("s1"), random_ref("s2")
    +    batch1, batch2, batch3 = random_ref("b1"), random_ref("b2"), random_ref("b3")
    +    order_ref = random_ref("o")
    +    make_csv("batches.csv", [
    +        ["ref", "sku", "qty", "eta"],
    +        [batch1, sku1, 100, ""],
    +        [batch2, sku2, 100, "2011-01-01"],
    +        [batch3, sku2, 100, "2011-01-02"],
         ])
    -    orders_csv = make_csv('orders.csv', [
    -        ['orderid', 'sku', 'qty'],
    +    orders_csv = make_csv("orders.csv", [
    +        ["orderid", "sku", "qty"],
             [order_ref, sku1, 3],
             [order_ref, sku2, 12],
         ])
     
         run_cli_script(orders_csv.parent)
     
    -    expected_output_csv = orders_csv.parent / 'allocations.csv'
    +    expected_output_csv = orders_csv.parent / "allocations.csv"
         with open(expected_output_csv) as f:
             rows = list(csv.reader(f))
         assert rows == [
    -        ['orderid', 'sku', 'qty', 'batchref'],
    -        [order_ref, sku1, '3', batch1],
    -        [order_ref, sku2, '12', batch2],
    +        ["orderid", "sku", "qty", "batchref"],
    +        [order_ref, sku1, "3", batch1],
    +        [order_ref, sku2, "12", batch2],
         ]
    @@ -215,48 +213,46 @@

    Appendix C: Swapping Out the Infrastructure: Do Everythin from datetime import datetime from pathlib import Path -from allocation import model +from allocation.domain import model + def load_batches(batches_path): batches = [] with batches_path.open() as inf: reader = csv.DictReader(inf) for row in reader: - if row['eta']: - eta = datetime.strptime(row['eta'], '%Y-%m-%d').date() + if row["eta"]: + eta = datetime.strptime(row["eta"], "%Y-%m-%d").date() else: eta = None - batches.append(model.Batch( - ref=row['ref'], - sku=row['sku'], - qty=int(row['qty']), - eta=eta - )) + batches.append( + model.Batch( + ref=row["ref"], sku=row["sku"], qty=int(row["qty"]), eta=eta + ) + ) return batches - def main(folder): - batches_path = Path(folder) / 'batches.csv' - orders_path = Path(folder) / 'orders.csv' - allocations_path = Path(folder) / 'allocations.csv' + batches_path = Path(folder) / "batches.csv" + orders_path = Path(folder) / "orders.csv" + allocations_path = Path(folder) / "allocations.csv" batches = load_batches(batches_path) - with orders_path.open() as inf, allocations_path.open('w') as outf: + with orders_path.open() as inf, allocations_path.open("w") as outf: reader = csv.DictReader(inf) writer = csv.writer(outf) - writer.writerow(['orderid', 'sku', 'batchref']) + writer.writerow(["orderid", "sku", "batchref"]) for row in reader: - orderid, sku = row['orderid'], row['sku'] - qty = int(row['qty']) + orderid, sku = row["orderid"], row["sku"] + qty = int(row["qty"]) line = model.OrderLine(orderid, sku, qty) batchref = model.allocate(line, batches) writer.writerow([line.orderid, line.sku, batchref]) - -if __name__ == '__main__': +if __name__ == "__main__": main(sys.argv[1])

    @@ -276,35 +272,33 @@

    Appendix C: Swapping Out the Infrastructure: Do Everythin
    -
    def test_cli_app_also_reads_existing_allocations_and_can_append_to_them(
    -        make_csv
    -):
    -    sku = random_ref('s')
    -    batch1, batch2 = random_ref('b1'), random_ref('b2')
    -    old_order, new_order = random_ref('o1'), random_ref('o2')
    -    make_csv('batches.csv', [
    -        ['ref', 'sku', 'qty', 'eta'],
    -        [batch1, sku, 10, '2011-01-01'],
    -        [batch2, sku, 10, '2011-01-02'],
    +
    def test_cli_app_also_reads_existing_allocations_and_can_append_to_them(make_csv):
    +    sku = random_ref("s")
    +    batch1, batch2 = random_ref("b1"), random_ref("b2")
    +    old_order, new_order = random_ref("o1"), random_ref("o2")
    +    make_csv("batches.csv", [
    +        ["ref", "sku", "qty", "eta"],
    +        [batch1, sku, 10, "2011-01-01"],
    +        [batch2, sku, 10, "2011-01-02"],
         ])
    -    make_csv('allocations.csv', [
    -        ['orderid', 'sku', 'qty', 'batchref'],
    +    make_csv("allocations.csv", [
    +        ["orderid", "sku", "qty", "batchref"],
             [old_order, sku, 10, batch1],
         ])
    -    orders_csv = make_csv('orders.csv', [
    -        ['orderid', 'sku', 'qty'],
    +    orders_csv = make_csv("orders.csv", [
    +        ["orderid", "sku", "qty"],
             [new_order, sku, 7],
         ])
     
         run_cli_script(orders_csv.parent)
     
    -    expected_output_csv = orders_csv.parent / 'allocations.csv'
    +    expected_output_csv = orders_csv.parent / "allocations.csv"
         with open(expected_output_csv) as f:
             rows = list(csv.reader(f))
         assert rows == [
    -        ['orderid', 'sku', 'qty', 'batchref'],
    -        [old_order, sku, '10', batch1],
    -        [new_order, sku, '7', batch2],
    +        ["orderid", "sku", "qty", "batchref"],
    +        [old_order, sku, "10", batch1],
    +        [new_order, sku, "7", batch2],
         ]
    @@ -334,10 +328,9 @@

    class CsvRepository(repository.AbstractRepository):
    -
         def __init__(self, folder):
    -        self._batches_path = Path(folder) / 'batches.csv'
    -        self._allocations_path = Path(folder) / 'allocations.csv'
    +        self._batches_path = Path(folder) / "batches.csv"
    +        self._allocations_path = Path(folder) / "allocations.csv"
             self._batches = {}  # type: Dict[str, model.Batch]
             self._load()
     
    @@ -351,22 +344,20 @@ 

    with self._batches_path.open() as f: reader = csv.DictReader(f) for row in reader: - ref, sku = row['ref'], row['sku'] - qty = int(row['qty']) - if row['eta']: - eta = datetime.strptime(row['eta'], '%Y-%m-%d').date() + ref, sku = row["ref"], row["sku"] + qty = int(row["qty"]) + if row["eta"]: + eta = datetime.strptime(row["eta"], "%Y-%m-%d").date() else: eta = None - self._batches[ref] = model.Batch( - ref=ref, sku=sku, qty=qty, eta=eta - ) + self._batches[ref] = model.Batch(ref=ref, sku=sku, qty=qty, eta=eta) if self._allocations_path.exists() is False: return with self._allocations_path.open() as f: reader = csv.DictReader(f) for row in reader: - batchref, orderid, sku = row['batchref'], row['orderid'], row['sku'] - qty = int(row['qty']) + batchref, orderid, sku = row["batchref"], row["orderid"], row["sku"] + qty = int(row["qty"]) line = model.OrderLine(orderid, sku, qty) batch = self._batches[batchref] batch._allocations.add(line) @@ -387,14 +378,13 @@

    @@ -452,7 +442,7 @@

    + @@ -224,7 +300,7 @@

    Appendix C: Swapping Out the Infrastructure: Do Everythin if row["eta"]: eta = datetime.strptime(row["eta"], "%Y-%m-%d").date() else: - eta = None + eta = None batches.append( model.Batch( ref=row["ref"], sku=row["sku"], qty=int(row["qty"]), eta=eta @@ -349,9 +425,9 @@

    if row["eta"]: eta = datetime.strptime(row["eta"], "%Y-%m-%d").date() else: - eta = None + eta = None self._batches[ref] = model.Batch(ref=ref, sku=sku, qty=qty, eta=eta) - if self._allocations_path.exists() is False: + if self._allocations_path.exists() is False: return with self._allocations_path.open() as f: reader = csv.DictReader(f) @@ -442,80 +518,9 @@

    -