diff --git a/chapter_03_abstractions.asciidoc b/chapter_03_abstractions.asciidoc index b85981fb..8f7af2a8 100644 --- a/chapter_03_abstractions.asciidoc +++ b/chapter_03_abstractions.asciidoc @@ -784,7 +784,7 @@ story we care about. ((("PyCon talk on Mocking Pitfalls"))) ((("Jung, Ed"))) Steve Freeman has a great example of overmocked tests in his talk -https://oreil.ly/jAmtr["Test-Driven Development"]. +https://youtu.be/yuEbZYKgZas?si=ZpBoivlDH13XTG9p&t=294["Test-Driven Development: That's Not What We Meant"]. You should also check out this PyCon talk, https://oreil.ly/s3e05["Mocking and Patching Pitfalls"], by our esteemed tech reviewer, Ed Jung, which also addresses mocking and its alternatives. diff --git a/chapter_05_high_gear_low_gear.asciidoc b/chapter_05_high_gear_low_gear.asciidoc index bfb1366e..a6d8550d 100644 --- a/chapter_05_high_gear_low_gear.asciidoc +++ b/chapter_05_high_gear_low_gear.asciidoc @@ -48,7 +48,7 @@ does to our test pyramid: [source,sh] [role="skip"] ---- -$ grep -c test_ **/test_*.py +$ grep -c test_ */*/test_*.py tests/unit/test_allocate.py:4 tests/unit/test_batches.py:8 tests/unit/test_services.py:3 @@ -310,7 +310,7 @@ function on `FakeRepository`: [source,python] [role="skip"] ---- -class FakeRepository(set): +class FakeRepository(repository.AbstractRepository): @staticmethod def for_batch(ref, sku, qty, eta=None): diff --git a/chapter_06_uow.asciidoc b/chapter_06_uow.asciidoc index 9420e0ad..24c9a2a2 100644 --- a/chapter_06_uow.asciidoc +++ b/chapter_06_uow.asciidoc @@ -169,11 +169,11 @@ def insert_batch(session, ref, sku, qty, eta): def get_allocated_batch_ref(session, orderid, sku): - [[orderlineid]] = session.execute( + [[orderlineid]] = session.execute( #<1> "SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku", dict(orderid=orderid, sku=sku), ) - [[batchref]] = session.execute( + [[batchref]] = session.execute( #<1> "SELECT b.reference FROM allocations JOIN batches AS b ON batch_id = b.id" " WHERE orderline_id=:orderlineid", dict(orderlineid=orderlineid), @@ -182,7 +182,15 @@ def get_allocated_batch_ref(session, orderid, sku): ---- ==== -// TODO: that double-unpacking is freaking ppl out. maybe [(orderlineid, )] ? +<1> The `[[orderlineid]] =` syntax is a little too-clever-by-half, apologies. + What's happening is that `session.execute` returns a list of rows, + where each row is a tuple of column values; + in our specific case, it's a list of one row, + which is a tuple with one column value in. + The double-square-bracket on the left hand side + is doing (double) assignment-unpacking to get the single value + back out of these two nested sequences. + It becomes readable once you've used it a few times! === Unit of Work and Its Context Manager diff --git a/chapter_09_all_messagebus.asciidoc b/chapter_09_all_messagebus.asciidoc index df129145..0ef9a65d 100644 --- a/chapter_09_all_messagebus.asciidoc +++ b/chapter_09_all_messagebus.asciidoc @@ -845,10 +845,9 @@ class FakeUnitOfWorkWithFakeMessageBus(FakeUnitOfWork): super().__init__() self.events_published = [] # type: List[events.Event] - def publish_events(self): - for product in self.products.seen: - while product.events: - self.events_published.append(product.events.pop(0)) + def collect_new_events(self): + self.events_published += super().collect_new_events() + return [] ---- ==== diff --git a/code b/code index 3ed6ff0f..734df09a 160000 --- a/code +++ b/code @@ -1 +1 @@ -Subproject commit 3ed6ff0fab52e14edba6ced4b258af68c521115f +Subproject commit 734df09afc65ba43c851271def147c70ac3c3b98 diff --git a/part1.asciidoc b/part1.asciidoc index a44eecf2..2d357b7d 100644 --- a/part1.asciidoc +++ b/part1.asciidoc @@ -32,7 +32,7 @@ To do that, we present four key design patterns: * The <>, an abstraction over the idea of persistent storage -* The <> pattern to clearly define where our +* The <> to clearly define where our use cases begin and end [role="pagebreak-before"] @@ -60,7 +60,7 @@ Three appendices are further explorations of the content from Part I: code: how we build and run the Docker images, where we manage configuration info, and how we run different types of tests. -* <> is a "proof is in the pudding" kind of content, showing +* <> is a "proof of the pudding" kind of content, showing how easy it is to swap out our entire infrastructure--the Flask API, the ORM, and Postgres—for a totally different I/O model involving a CLI and CSVs. diff --git a/preface.asciidoc b/preface.asciidoc index 12c91f8a..d8b98e78 100644 --- a/preface.asciidoc +++ b/preface.asciidoc @@ -347,7 +347,7 @@ Ben Judson, James Gregory, Łukasz Lechowicz, Clinton Roy, Vitorino Araújo, Susan Goodbody, Josh Harwood, Daniel Butler, Liu Haibin, Jimmy Davies, Ignacio Vergara Kausel, Gaia Canestrani, Renne Rocha, pedroabi, Ashia Zawaduk, Jostein Leira, Brandon Rhodes, Jazeps Basko, simkimsia, Adrien Brunet, Sergey Nosko, -Dmitry Bychkov, +Dmitry Bychkov, dayres2, programmer-ke, asjhita, Filip Lajszczak, and many more; our apologies if we missed you on this list. Super-mega-thanks to our editor Corbin Collins for his gentle chivvying, and @@ -356,6 +356,4 @@ the production staff, Katherine Tozer, Sharon Wilkey, Ellen Troutman-Zaig, and Rebecca Demarest, for your dedication, professionalism, and attention to detail. This book is immeasurably improved thanks to you. -// TODO thanks to rest of OR team. - Any errors remaining in the book are our own, naturally. diff --git a/theme/asciidoctor-clean.custom.css b/theme/asciidoctor-clean.custom.css index 00a945c5..ac11c462 100644 --- a/theme/asciidoctor-clean.custom.css +++ b/theme/asciidoctor-clean.custom.css @@ -89,3 +89,4 @@ table { width: 55vw!important; font-size: 3vw; } +}