@@ -25,9 +25,9 @@ to at least try out some of the ideas near the end.
25
25
26
26
27
27
I'm going to use an example from the domain of logistics where we need to sync
28
- to a cargo provider's API, but you can really imagine any old API--a payment
29
- gateway, an SMS notifications engine, a cloud storage provider. Or you can
30
- imagine an external dependency that's nothing to do with the web at all, just
28
+ shipments to a cargo provider's API, but you can really imagine any old API--a
29
+ payment gateway, an SMS notifications engine, a cloud storage provider. Or you
30
+ can imagine an external dependency that's nothing to do with the web at all, just
31
31
any kind of external I/O dependency that's hard to unit test.
32
32
33
33
@@ -59,8 +59,8 @@ class Shipment:
59
59
60
60
61
61
We want to sync our shipments model with a third party, the cargo freight
62
- company, via their API. We have a couple of use cases, new shipment creation ,
63
- and checking for updated etas:
62
+ company, via their API. We have a couple of use cases: creating new shipments ,
63
+ and checking for updated etas.
64
64
65
65
66
66
Let's say we have some sort of controller function that's in charge of doing this. It
@@ -95,7 +95,7 @@ def sync_to_api(shipment):
95
95
96
96
Not too bad!
97
97
98
- In a case like this, the typical reaction is to reach for mocks,
98
+ How do we test it? In a case like this, the typical reaction is to reach for mocks,
99
99
and _ as long as things stay simple_ , it's pretty manageable
100
100
101
101
@@ -193,7 +193,7 @@ matter too much, the hope is that this sort of test ugliness is familiar.
193
193
194
194
And this is only the beginning, we've shown an API integration that only cares
195
195
about writes, but what about reads? Say we want to poll our third party api
196
- now and again to get updated etas for ours shipments. Depending on the eta, we
196
+ now and again to get updated etas for our shipments. Depending on the eta, we
197
197
have some business logic about notifying people of delays...
198
198
199
199
@@ -395,9 +395,8 @@ def test_can_update_a_shipment():
395
395
That relies on your third- party api having a decent sandbox that you can test against.
396
396
You' ll need to think about:
397
397
398
- * how do you clean up? running dozens of tests dozens of times a day in dev
399
- and CI will start filling the sandbox with test data. s i can' t, how much
400
- data will start piling up in the sandbox
398
+ * how do you clean up? Running dozens of tests dozens of times a day in dev
399
+ and CI will start filling the sandbox with test data.
401
400
402
401
* is the sandbox slow and annoying to test against? are devs going to be
403
402
annoyed at waiting for integration tests to finish on their machines, or
@@ -436,7 +435,7 @@ on the internet I suppose, but still.
436
435
437
436
So when might you think about doing this?
438
437
439
- * if the integration is not core to your application, ie it' s an incidental feature
438
+ * if the integration is not core to your application, i.e it' s an incidental feature
440
439
* if the bulk of the code you write, and the feedback you want, is not about
441
440
integration issues, but about other things in your app
442
441
* if you really can' t figure out how to fix the problems with your integration
@@ -527,7 +526,7 @@ that mock on _any_ test that might use the third party adapter.
527
526
528
527
> Making the dependency explicit and using DI solves these problems
529
528
530
- Again, we' re in dangerous territory here. Python people are skeptical
529
+ Again, we' re in dangerous territory here. Python people are skeptical
531
530
of DI , and neither of these problems is _that_ big of a deal. But
532
531
DI does buy us some nice things, so read on with an open mind.
533
532
@@ -590,8 +589,8 @@ def test_create_shipment_syncs_to_api():
590
589
591
590
592
591
593
- So far you may think the pros isn ' t enough of a wow to justify the con?
594
- Well, if we take it one step further and really commit, you may yet get
592
+ So far you may think the pros aren ' t enough of a wow to justify the con?
593
+ Well, if we take it one step further and really commit to DI , you may yet get
595
594
on board.
596
595
597
596
@@ -637,11 +636,11 @@ def test_create_shipment_syncs_to_api():
637
636
638
637
Why bother with this?
639
638
640
- # ### handrolled fakes for unit tests, the tradeoffs
639
+ # ### Handrolled fakes for unit tests, the tradeoffs
641
640
642
641
# #### Pros:
643
642
* tests can be more readable, no more `mock.call_args == call(foo,bar)` stuff
644
- * 👉Our fake exercises design pressure on our Adapter' s API👈
643
+ * 👉Our fake exerts design pressure on our Adapter' s API👈
645
644
646
645
# #### Cons:
647
646
* more code in tests
0 commit comments