Skip to content

Commit 30a0155

Browse files
committed
Fixes for tests in 13
1 parent d36b0c3 commit 30a0155

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

chapter_13_database_layer_validation.asciidoc

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ class ListAndItemModelsTest(TestCase):
112112
----
113113
====
114114

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-
123115
This is a new unit testing technique: when we want to check that doing
124116
something will raise an error, we can use the `self.assertRaises` context
125117
manager. We could have used something like this instead:
@@ -145,6 +137,15 @@ AssertionError: ValidationError not raised
145137
----
146138

147139

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+
148149
A Django Quirk: Model Save Doesn't Run Validation
149150
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
150151

@@ -598,7 +599,7 @@ Let's put an early return in the FT to separate
598599
what we got working from those that still need to be dealt with:
599600

600601
[role="sourcecode"]
601-
.src/functional_tests/test_list_item_validation.py (ch13l???)
602+
.src/functional_tests/test_list_item_validation.py (ch13l030-3)
602603
====
603604
[source,python]
604605
----
@@ -608,8 +609,7 @@ class ItemValidationTest(FunctionalTest):
608609
self.browser.find_element(By.ID, "id_new_item").send_keys(Keys.ENTER)
609610
self.wait_for_row_in_list_table("1: Buy milk")
610611
611-
return
612-
# TODO fix the remaining test scenarios
612+
return # TODO re-enable the rest of this test.
613613
614614
# Perversely, she now decides to submit a second blank list item
615615
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
695695
----
696696
$ pass:quotes[*python src/manage.py test functional_tests*]
697697
[...]
698-
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate
699-
element: .invalid-feedback; [...]
700-
[...]
701698
AssertionError: '2: Use peacock feathers to make a fly' not found in ['1: Buy
702699
peacock feathers']
703700
----
704701

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+
705705
NOTE: In this section we're performing a refactor at the application level.
706706
We execute our application-level refactor by changing or adding unit tests,
707707
and then adjusting our code.
@@ -843,7 +843,7 @@ OK
843843
Let's try a full FT run: they're all passing!
844844

845845
----
846-
Ran 4 tests in 20 s
846+
Ran 4 tests in 9.951s
847847
848848
OK
849849
----
@@ -857,8 +857,26 @@ $ *git commit -am "Refactor list view to handle new item POSTs"*
857857
----
858858

859859

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+
862880

863881
[role="scratchpad"]
864882
*****

0 commit comments

Comments
 (0)