@@ -112,14 +112,6 @@ class ListAndItemModelsTest(TestCase):
112
112
----
113
113
====
114
114
115
- TIP: If you're new to Python, you may never have seen the `with` statement.
116
- It's used with what are called "context managers", which wrap a block of code,
117
- usually with some kind of setup, cleanup, or error-handling code.
118
- There's a good write-up in the
119
- https://docs.python.org/release/2.5/whatsnew/pep-343.html[Python 2.5 release notes].
120
- ((("with statements")))
121
- ((("Python 3", "with statements")))
122
-
123
115
This is a new unit testing technique: when we want to check that doing
124
116
something will raise an error, we can use the `self.assertRaises` context
125
117
manager. We could have used something like this instead:
@@ -145,6 +137,15 @@ AssertionError: ValidationError not raised
145
137
----
146
138
147
139
140
+ TIP: If you're new to Python, you may never have seen the `with` statement.
141
+ It's used with what are called "context managers", which wrap a block of code,
142
+ usually with some kind of setup, cleanup, or error-handling code.
143
+ There's a good write-up in the
144
+ https://docs.python.org/release/2.5/whatsnew/pep-343.html[Python 2.5 release notes].
145
+ ((("with statements")))
146
+ ((("Python 3", "with statements")))
147
+
148
+
148
149
A Django Quirk: Model Save Doesn't Run Validation
149
150
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
150
151
@@ -598,7 +599,7 @@ Let's put an early return in the FT to separate
598
599
what we got working from those that still need to be dealt with:
599
600
600
601
[role="sourcecode"]
601
- .src/functional_tests/test_list_item_validation.py (ch13l??? )
602
+ .src/functional_tests/test_list_item_validation.py (ch13l030-3 )
602
603
====
603
604
[source,python]
604
605
----
@@ -608,8 +609,7 @@ class ItemValidationTest(FunctionalTest):
608
609
self.browser.find_element(By.ID, "id_new_item").send_keys(Keys.ENTER)
609
610
self.wait_for_row_in_list_table("1: Buy milk")
610
611
611
- return
612
- # TODO fix the remaining test scenarios
612
+ return # TODO re-enable the rest of this test.
613
613
614
614
# Perversely, she now decides to submit a second blank list item
615
615
self.browser.find_element(By.ID, "id_new_item").send_keys(Keys.ENTER)
@@ -695,13 +695,13 @@ This will immediately break our original functional test, because the
695
695
----
696
696
$ pass:quotes[*python src/manage.py test functional_tests*]
697
697
[...]
698
- selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
699
- element: .invalid-feedback; [...]
700
- [...]
701
698
AssertionError: '2: Use peacock feathers to make a fly' not found in ['1: Buy
702
699
peacock feathers']
703
700
----
704
701
702
+ The FTs are warning us that our attempted refactor has introduced a regression.
703
+ Let's try and finish the refactor as soon as we can, and get back to green.
704
+
705
705
NOTE: In this section we're performing a refactor at the application level.
706
706
We execute our application-level refactor by changing or adding unit tests,
707
707
and then adjusting our code.
843
843
Let's try a full FT run: they're all passing!
844
844
845
845
----
846
- Ran 4 tests in 20 s
846
+ Ran 4 tests in 9.951s
847
847
848
848
OK
849
849
----
@@ -857,8 +857,26 @@ $ *git commit -am "Refactor list view to handle new item POSTs"*
857
857
----
858
858
859
859
860
- We can remove the early return
861
- now.
860
+ We can remove the early return now.
861
+
862
+
863
+ [role="sourcecode"]
864
+ .src/functional_tests/test_list_item_validation.py (ch13l033-1)
865
+ ====
866
+ [source,diff]
867
+ ----
868
+ @@ -24,8 +24,6 @@ class ItemValidationTest(FunctionalTest):
869
+ self.browser.find_element(By.ID, "id_new_item").send_keys(Keys.ENTER)
870
+ self.wait_for_row_in_list_table("1: Buy milk")
871
+
872
+ - return # TODO re-enable the rest of this test.
873
+ -
874
+ # Perversely, she now decides to submit a second blank list item
875
+ ----
876
+ ====
877
+
878
+ And from our scratchpad:
879
+
862
880
863
881
[role="scratchpad"]
864
882
*****
0 commit comments