@@ -159,7 +159,7 @@ and wait until we're back to a fully passing test suite before refactoring.
159
159
160
160
Kent Beck has a book-length exploration of the tradeoffs
161
161
of refactor-now vs refactor-later, called
162
- https://learning .oreilly.com/library/view/tidy-first/9781098151232/[Tidy First?]
162
+ https://www .oreilly.com/library/view/tidy-first/9781098151232/[Tidy First?]
163
163
**********************************************************************
164
164
165
165
@@ -262,6 +262,9 @@ class FunctionalTest(StaticLiveServerTestCase):
262
262
NOTE: Keeping helper methods in a base `FunctionalTest` class
263
263
is one useful way of preventing duplication in FTs.
264
264
Later in the book (in <<chapter_page_pattern>>) we'll use the "Page pattern",
265
+ // CSANAD: is this reference to the chapter "The Token Social Bit, the Page
266
+ // Pattern, and an Exercise for the Reader" as chapter_page_pattern
267
+ // still clear in print?
265
268
which is related, but prefers composition over inheritance--always a good thing.
266
269
267
270
Our first FT is now in its own file,
@@ -291,7 +294,7 @@ Some people like to use them a lot in Django code
291
294
(e.g., your views might import models using `from .models import List`,
292
295
instead of `from list.models`).
293
296
Ultimately this is a matter of personal preference.
294
- I prefer to use relative imports only when I'm super-super
297
+ I prefer to use relative imports only when I'm super-super confident
295
298
that the relative position of the thing I'm importing won't change.
296
299
That applies in this case because I know for sure
297
300
all the tests will sit next to _base.py_, which they inherit from.
@@ -378,14 +381,16 @@ AssertionError: write me!
378
381
Brilliant--no need to sit around waiting for all the FTs
379
382
when we're only interested in a single one.
380
383
Although we need to remember to run all of them now and again, to check for regressions.
381
- Later in the book we'll see how to give that task over to an automated Continuous Integration loop.
382
- For now, let's commit!
384
+ Later in the book we'll set up a Continuous Integration (CI) server to run all the tests automatically,
385
+ for example every time we push to master.
386
+ For now, a good prompt for running all the tests is "just before you do a commit",
387
+ so let's get into that habit now:
383
388
384
389
[subs="specialcharacters,quotes"]
385
390
----
386
391
$ *git status*
387
392
$ *git add src/functional_tests*
388
- $ *git commit -m "Moved Fts into their own individual files"*
393
+ $ *git commit -m "Moved FTs into their own individual files"*
389
394
----
390
395
391
396
Great. We've split our functional tests nicely out into different files.
@@ -547,6 +552,8 @@ Like this:
547
552
((("Python 3", "lambda functions")))
548
553
`lambda` in Python is the syntax for making a one-line, throwaway function--it
549
554
saves you from having to use `def..():` and an indented block:
555
+ // CSANAD: the `def..` and the `():` renders apart from each other, on two
556
+ // lines. I couldn't find out how to keep them together.
550
557
551
558
[role="skipme"]
552
559
[source,python]
@@ -561,9 +568,10 @@ saves you from having to use `def..():` and an indented block:
561
568
5
562
569
----
563
570
564
- In our case, we're using it to transform a bit of code that would otherwise be
565
- executed immediately into a function that we can pass as an argument,
571
+ In our case, we're using it to transform a bit of code-- that would otherwise be
572
+ executed immediately-- into a function that we can pass as an argument,
566
573
and that can be executed later, and multiple times:
574
+ // CSANAD: I think it's easier to read like this.
567
575
568
576
[role="skipme"]
569
577
[source,python]
@@ -621,18 +629,24 @@ FAILED (errors=1)
621
629
The order of the traceback is a little confusing, but we can more or less follow
622
630
through what happened:
623
631
624
- <1> At line 15 in our FT, we go into our `self.wait_for` helper,
625
- passing it the `lambda`-ified version of the `assertEqual`.
632
+ <1> In our FT, we call our `self.wait_for` helper, where we pass
633
+ the `lambda`-ified version of `assertEqual`.
626
634
627
635
<2> We go into `self.wait_for` in _base.py_,
628
- where we can see that we 're inside `fn()`,
629
- which is the name for our lambda inside the helper .
636
+ where we're calling (and returning) `fn()`, which refers to the passed
637
+ lambda function encapsulating our test assertion .
630
638
631
639
<3> To explain where the exception has actually come from,
632
640
the traceback takes us back into _test_list_item_validation.py_
633
641
and inside the body of the `lambda` function,
634
- and tells us that it the attempt to find the `.invalid-feedback` element
642
+ and tells us that it was attempt to find the `.invalid-feedback` element
635
643
that failed.
644
+ // CSANAD: I changed two things here:
645
+ // First, I think it's better to remove the specific line number which may
646
+ // vary due to personal formatting preferences (and following the pep8 puts
647
+ // this on line 16 for me)
648
+ // Secondly, we say we go into self.wait_for in step#2. Here, in step#1 we
649
+ // are only calling it. Overall, I tried making it clearer a bit.
636
650
637
651
638
652
((("functional programming")))
@@ -767,7 +781,8 @@ $ *cp src/lists/tests/test_views.py src/lists/tests/test_models.py*
767
781
----
768
782
769
783
And strip _test_models.py_ down
770
- to being just the one test--it means it needs far fewer imports:
784
+ to being just the one test:
785
+ // CSANAD: the imports are unchanged, only the view-related tests are removed
771
786
772
787
[role="sourcecode"]
773
788
.src/lists/tests/test_models.py (ch11l016)
@@ -792,10 +807,10 @@ Whereas _test_views.py_ just loses one class:
792
807
----
793
808
--- a/src/lists/tests/test_views.py
794
809
+++ b/src/lists/tests/test_views.py
795
- @@ -103,34 +104,3 @@ class ListViewTest(TestCase):
796
- self.assertNotContains(response, "other list item 1")
797
- self.assertNotContains(response, "other list item 2")
810
+ 33 +74,3 @@ class NewItemTest(TestCase):
811
+ )
798
812
813
+ self.assertRedirects(response, f"/lists/{correct_list.id}/")
799
814
-
800
815
-
801
816
-class ListAndItemModelsTest(TestCase):
0 commit comments