1
1
[[chapter_15_advanced_forms]]
2
2
== More Advanced Forms
3
3
4
- // TODO Harry write a paragraph about the server side validation
5
-
6
4
7
5
Now let's look at some more advanced forms usage. We've helped our users
8
6
to avoid blank list items, so now let's help them avoid duplicate items.
9
7
10
- This chapter goes into more intricate details of Django's form validation, and
11
- you have my official permission to skip it if you already know all about
12
- customising Django forms, or if you're reading this book for the TDD rather
13
- than for the Django.
8
+ Our validation constraint so far has been about preventing blank items,
9
+ and as you may remember, it turned out we can enforce that very easily in the frontend.
10
+ Avoiding duplicate items is less straightforward to do in the frontend,
11
+ (although not impossible of course),
12
+ so this chapter will lean more heavily on server-side validation,
13
+ and bubbling errors from the backend back up to the UI.
14
+
15
+ This chapter goes into more intricate details of Django's forms framework,
16
+ so you have my official permission to skip it
17
+ if you already know all about customising Django forms and how to display errors in the UI,
18
+ or if you're reading this book for the TDD rather than for the Django.
14
19
15
- If you're still learning Django, there's good stuff in here. If you
16
- want to skip ahead, that's OK too. Make sure you take a quick look at the aside
17
- on developer stupidity, and the recap on testing views at the end.
20
+ If you're still learning Django, there's good stuff in here!
21
+ If you want to skip ahead, that's OK too.
22
+ Make sure you take a quick look at the
23
+ <<testing-for-stupidity,aside on developer stupidity>>,
24
+ and the <<what-to-test-in-views,recap on testing views>> at the end.
18
25
19
26
20
27
=== Another FT for Duplicate Items
@@ -25,7 +32,9 @@ on developer stupidity, and the recap on testing views at the end.
25
32
((("functional tests (FTs)", "for duplicate items", secondary-sortas="duplicate items", id="FTduplicate15")))
26
33
((("duplicate items testing", "functional test for", id="DITfunctional15")))
27
34
((("user interactions", "preventing duplicate items", id="UIduplicate15")))
28
- We add a second test method to `ItemValidationTest`:
35
+ We add a second test method to `ItemValidationTest`,
36
+ and tell a little story about what we want to see happen
37
+ when a user tries to enter the same item twice into their to-do list:
29
38
30
39
[role="sourcecode"]
31
40
.src/functional_tests/test_list_item_validation.py (ch15l001)
@@ -53,11 +62,13 @@ def test_cannot_add_duplicate_items(self):
53
62
----
54
63
====
55
64
56
- Why have two test methods rather than extending one, or having a new file
57
- and class? It's a judgement call. These two feel closely related; they're
58
- both about validation on the same input field, so it feels right to
59
- keep them in the same file. On the other hand, they're logically separate
60
- enough that it's practical to keep them in different methods:
65
+ Why have two test methods rather than extending one,
66
+ or having a new file and class?
67
+ It's a judgement call. These two feel closely related;
68
+ they're both about validation on the same input field,
69
+ so it feels right to keep them in the same file.
70
+ On the other hand, they're logically separate enough
71
+ that it's practical to keep them in different methods:
61
72
62
73
63
74
[subs="specialcharacters,macros"]
@@ -907,6 +918,7 @@ a recap of the biggest (and highest-level) one, 'test_views' (the listing
907
918
shows just the key tests and assertions, and your order may vary):
908
919
// CSANAD: Why are we only showing ListViewTest? HomePageTest, NewListTest
909
920
921
+ [[what-to-test-in-views]]
910
922
.What to Test in Views
911
923
******************************************************************************
912
924
0 commit comments