Skip to content

Commit 114f32f

Browse files
committed
Change to using new-style markup for section headings in 15
1 parent 3333a1c commit 114f32f

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

chapter_15_advanced_forms.asciidoc

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[[chapter_15_advanced_forms]]
2-
More Advanced Forms
3-
-------------------
2+
== More Advanced Forms
43

54
.🚧 Warning, Chapter update in progress
65
*******************************************************************************
@@ -26,8 +25,7 @@ want to skip ahead, that's OK too. Make sure you take a quick look at the aside
2625
on developer stupidity, and the recap on testing views at the end.
2726

2827

29-
Another FT for Duplicate Items
30-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
=== Another FT for Duplicate Items
3129

3230

3331

@@ -67,7 +65,7 @@ enough that it's practical to keep them in different methods:
6765

6866
[subs="specialcharacters,macros"]
6967
----
70-
$ pass:quotes[*python manage.py test functional_tests.test_list_item_validation*]
68+
$ pass:quotes[*python manage.py test functional_tests.test_list_item_validation*]
7169
[...]
7270
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
7371
element: .has-error
@@ -81,15 +79,14 @@ just the failing one, I hear you ask? Why, yes indeed:
8179
[subs="specialcharacters,macros"]
8280
----
8381
$ pass:quotes[*python manage.py test functional_tests.\
84-
test_list_item_validation.ItemValidationTest.test_cannot_add_duplicate_items*]
82+
test_list_item_validation.ItemValidationTest.test_cannot_add_duplicate_items*]
8583
[...]
8684
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
8785
element: .has-error
8886
----
8987

9088

91-
Preventing Duplicates at the Model Layer
92-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89+
==== Preventing Duplicates at the Model Layer
9390

9491

9592
((("model-layer validation", "preventing duplicate items")))Here's
@@ -110,7 +107,7 @@ def test_duplicate_items_are_invalid(self):
110107
----
111108
====
112109

113-
And, while it occurs to us, we add another test to make sure we don't
110+
And, while it occurs to us, we add another test to make sure we don't
114111
overdo it on our integrity constraints:
115112

116113

@@ -128,7 +125,7 @@ def test_CAN_save_same_item_to_different_lists(self):
128125
----
129126
====
130127

131-
I always like to put a little comment for tests which are checking
128+
I always like to put a little comment for tests which are checking
132129
that a particular use case should 'not' raise an error; otherwise,
133130
it can be hard to see what's being tested:
134131

@@ -228,13 +225,12 @@ class Item(models.Model):
228225
----
229226
====
230227

231-
You might want to take a quick peek at the
228+
You might want to take a quick peek at the
232229
https://docs.djangoproject.com/en/1.11/ref/models/options/[Django docs on model
233230
`Meta` attributes] at this point.
234231

235232

236-
A Little Digression on Queryset Ordering and String Representations
237-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
233+
==== A Little Digression on Queryset Ordering and String Representations
238234

239235
//TODO: actually, this error will never appear with the new migrations
240236
// framework. could drop this whole section?
@@ -425,14 +421,13 @@ OK
425421
// TODO: in theory we should do a migration now.
426422

427423
[[rewrite-model-test]]
428-
Rewriting the Old Model Test
429-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
424+
==== Rewriting the Old Model Test
430425

431426

432427
That long-winded model test did serendipitously help us find an unexpected
433428
bug, but now it's time to rewrite it. I wrote it in a very verbose style to
434429
introduce the Django ORM, but in fact, now that we have the explicit test for
435-
ordering, we can get the same coverage from a couple of much shorter tests.
430+
ordering, we can get the same coverage from a couple of much shorter tests.
436431
Delete `test_saving_and_retrieving_items` and replace with this:
437432

438433
[role="sourcecode"]
@@ -456,7 +451,7 @@ class ListAndItemModelsTest(TestCase):
456451
[...]
457452
----
458453
====
459-
454+
460455
That's more than enough really--a check of the default values of attributes
461456
on a freshly initialized model object is enough to sanity-check that we've
462457
probably set some fields up in 'models.py'. The "item is related to list" test
@@ -494,8 +489,7 @@ OK
494489
----
495490

496491

497-
Some Integrity Errors Do Show Up on Save
498-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
492+
==== Some Integrity Errors Do Show Up on Save
499493

500494

501495

@@ -505,7 +499,7 @@ final aside before we move on. Do you remember I mentioned in
505499
on save? It all depends on whether the integrity constraint is actually being
506500
enforced by the database.
507501

508-
Try running `makemigrations` and you'll see that Django wants to add the
502+
Try running `makemigrations` and you'll see that Django wants to add the
509503
`unique_together` constraint to the database itself, rather than just having
510504
it as an application-layer constraint:
511505

@@ -577,8 +571,7 @@ $ pass:[<strong>git commit -am "Implement duplicate item validation at model lay
577571
----
578572

579573

580-
Experimenting with Duplicate Item Validation at the Views Layer
581-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
574+
=== Experimenting with Duplicate Item Validation at the Views Layer
582575

583576

584577
((("duplicate items testing", "at the views layer", secondary-sortas="views layer")))Let's
@@ -648,8 +641,7 @@ from unittest import skip
648641
====
649642

650643

651-
A More Complex Form to Handle Uniqueness Validation
652-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
644+
=== A More Complex Form to Handle Uniqueness Validation
653645

654646
((("duplicate items testing", "complex form for")))((("uniqueness validation", seealso="duplicate items testing")))The
655647
form to create a new list only needs to know one thing, the new item text.
@@ -695,7 +687,7 @@ class ExistingListItemFormTest(TestCase):
695687
====
696688

697689
Next we iterate through a few TDD cycles until we get a form with a
698-
custom constructor, which just ignores its `for_list` argument.
690+
custom constructor, which just ignores its `for_list` argument.
699691
(I won't show them all, but I'm sure you'll do them, right? Remember, the Goat
700692
sees all.)
701693

@@ -742,7 +734,7 @@ AssertionError: True is not false
742734
----
743735

744736
The next step requires a little knowledge of Django's internals, but you
745-
can read up on it in the Django docs on
737+
can read up on it in the Django docs on
746738
https://docs.djangoproject.com/en/1.11/ref/models/instances/#validating-objects[model
747739
validation] and
748740
https://docs.djangoproject.com/en/1.11/ref/forms/validation/[form validation].
@@ -788,8 +780,7 @@ $ *git commit -a*
788780
----
789781

790782

791-
Using the Existing List Item Form in the List View
792-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
783+
=== Using the Existing List Item Form in the List View
793784

794785
((("duplicate items testing", "in the list view", secondary-sortas="list view", id="DITlist15")))Now
795786
let's see if we can put this form to work in our view.
@@ -879,7 +870,7 @@ And that 'almost' fixes everything, except for an unexpected fail:
879870
TypeError: save() missing 1 required positional argument: 'for_list'
880871
----
881872

882-
Our custom save method from the parent `ItemForm` is no longer needed.
873+
Our custom save method from the parent `ItemForm` is no longer needed.
883874
Let's make a quick unit test for that:
884875

885876
//IDEA: add the form class names here so ppl know which test_form_save and save()
@@ -961,14 +952,13 @@ testing views over the last few chapters.((("", startref="DITlist15")))
961952

962953

963954

964-
Wrapping Up: What We've Learned About Testing Django
965-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
955+
=== Wrapping Up: What We've Learned About Testing Django
966956

967957
((("class-based generic views (CBGVs)", "key tests and assertions")))((("Django framework", "class-based generic views")))We're
968958
now at a point where our app looks a lot more like a "standard"
969959
Django app, and it implements the three common Django layers: models,
970960
forms, and views. We no longer have any "training wheels&#x201d;-style tests,
971-
and our code looks pretty much like code we'd be happy to see in a
961+
and our code looks pretty much like code we'd be happy to see in a
972962
real app.
973963

974964
We have one unit test file for each of our key source code files. Here's

0 commit comments

Comments
 (0)