Skip to content

Commit 4f87e58

Browse files
committed
start working on tests
1 parent bc3b7a6 commit 4f87e58

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

chapter_22_outside_in.asciidoc

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ some things may not be quite right yet.
1111
*******************************************************************************
1212

1313

14-
15-
16-
1714
((("Test-Driven Development (TDD)", "outside-in technique", id="TTDoutside22")))
1815
In this chapter I'd like to talk about a technique called Outside-In TDD.
1916
It's pretty much what we've been doing all along.
@@ -88,29 +85,29 @@ write our FT to look for a "My Lists" page:
8885

8986

9087
[role="sourcecode"]
91-
.functional_tests/test_my_lists.py (ch19l001-1)
88+
.src/functional_tests/test_my_lists.py (ch22l001)
9289
====
9390
[source,python]
9491
----
9592
def test_logged_in_users_lists_are_saved_as_my_lists(self):
9693
# Edith is a logged-in user
97-
self.create_pre_authenticated_session('[email protected]')
94+
self.create_pre_authenticated_session("[email protected]")
9895
9996
# She goes to the home page and starts a list
10097
self.browser.get(self.live_server_url)
101-
self.add_list_item('Reticulate splines')
102-
self.add_list_item('Immanentize eschaton')
98+
self.add_list_item("Reticulate splines")
99+
self.add_list_item("Immanentize eschaton")
103100
first_list_url = self.browser.current_url
104101
105102
# She notices a "My lists" link, for the first time.
106-
self.browser.find_element_by_link_text('My lists').click()
103+
self.browser.find_element_by_link_text("My lists").click()
107104
108105
# She sees that her list is in there, named according to its
109106
# first list item
110107
self.wait_for(
111-
lambda: self.browser.find_element_by_link_text('Reticulate splines')
108+
lambda: self.browser.find_element_by_link_text("Reticulate splines")
112109
)
113-
self.browser.find_element_by_link_text('Reticulate splines').click()
110+
self.browser.find_element_by_link_text("Reticulate splines").click()
114111
self.wait_for(
115112
lambda: self.assertEqual(self.browser.current_url, first_list_url)
116113
)
@@ -130,7 +127,7 @@ appear on the My Lists page as well. The FT continues, and while we're at it,
130127
we check that only logged-in users can see the "My Lists" page:
131128

132129
[role="sourcecode"]
133-
.functional_tests/test_my_lists.py (ch19l001-2)
130+
.src/functional_tests/test_my_lists.py (ch22l002)
134131
====
135132
[source,python]
136133
----
@@ -141,24 +138,24 @@ we check that only logged-in users can see the "My Lists" page:
141138
142139
# She decides to start another list, just to see
143140
self.browser.get(self.live_server_url)
144-
self.add_list_item('Click cows')
141+
self.add_list_item("Click cows")
145142
second_list_url = self.browser.current_url
146143
147144
# Under "my lists", her new list appears
148-
self.browser.find_element_by_link_text('My lists').click()
145+
self.browser.find_element_by_link_text("My lists").click()
149146
self.wait_for(
150-
lambda: self.browser.find_element_by_link_text('Click cows')
147+
lambda: self.browser.find_element_by_link_text("Click cows")
151148
)
152-
self.browser.find_element_by_link_text('Click cows').click()
149+
self.browser.find_element_by_link_text("Click cows").click()
153150
self.wait_for(
154151
lambda: self.assertEqual(self.browser.current_url, second_list_url)
155152
)
156153
157154
# She logs out. The "My lists" option disappears
158-
self.browser.find_element_by_link_text('Log out').click()
155+
self.browser.find_element_by_link_text("Log out").click()
159156
self.wait_for(lambda: self.assertEqual(
160-
self.browser.find_elements_by_link_text('My lists'),
161-
[]
157+
self.browser.find_elements_by_link_text("My lists"),
158+
[],
162159
))
163160
----
164161
====
@@ -168,7 +165,7 @@ text into the right input box. We define it in 'base.py':
168165

169166

170167
[role="sourcecode small-code"]
171-
.functional_tests/base.py (ch22l003)
168+
.src/functional_tests/base.py (ch22l003)
172169
====
173170
[source,python]
174171
----
@@ -189,7 +186,7 @@ And while we're at it we can use it in a few of the other FTs, like this:
189186

190187

191188
[role="sourcecode currentcontents dofirst-ch22l004"]
192-
.functional_tests/test_list_item_validation.py
189+
.src/functional_tests/test_list_item_validation.py
193190
====
194191
[source,python]
195192
----
@@ -226,7 +223,7 @@ Here's the minimal code change:
226223
* TODO: update this link for latest bootstrap / style nicely
227224

228225
[role="sourcecode small-code"]
229-
.lists/templates/base.html (ch22l005)
226+
.src/lists/templates/base.html (ch22l005)
230227
====
231228
[source,html]
232229
----
@@ -262,7 +259,7 @@ Again, we can go outside-in, starting at the presentation layer with just the
262259
URL and nothing else:
263260

264261
[role="sourcecode"]
265-
.lists/templates/base.html (ch22l006)
262+
.src/lists/templates/base.html (ch22l006)
266263
====
267264
[source,html]
268265
----
@@ -282,7 +279,7 @@ functions.
282279
As always, we start with a test:
283280

284281
[role="sourcecode"]
285-
.lists/tests/test_views.py (ch19l003)
282+
.src/lists/tests/test_views.py (ch19l003)
286283
====
287284
[source,python]
288285
----
@@ -303,7 +300,7 @@ And we fix it, still at the presentation level, in 'urls.py':
303300

304301

305302
[role="sourcecode"]
306-
.lists/urls.py (ch19l004)
303+
.src/lists/urls.py (ch19l004)
307304
====
308305
[source,python]
309306
----
@@ -333,7 +330,7 @@ We move in from the presentation layer to the views layer, and create a
333330
minimal placeholder:
334331

335332
[role="sourcecode"]
336-
.lists/views.py (ch22l005)
333+
.src/lists/views.py (ch22l005)
337334
====
338335
[source,python]
339336
----
@@ -345,7 +342,7 @@ def my_lists(request, email):
345342
And a minimal template:
346343

347344
[role="sourcecode"]
348-
.lists/templates/my_lists.html (ch22l006)
345+
.src/lists/templates/my_lists.html (ch22l006)
349346
====
350347
[source,html]
351348
----
@@ -389,7 +386,7 @@ Also, the "My Lists" page doesn't need the new item form,
389386
so we'll put that into a block too, making it optional:
390387

391388
[role="sourcecode"]
392-
.lists/templates/base.html (ch19l007-1)
389+
.src/lists/templates/base.html (ch19l007-1)
393390
====
394391
[source,diff]
395392
----
@@ -413,7 +410,7 @@ so we'll put that into a block too, making it optional:
413410
====
414411

415412
[role="sourcecode"]
416-
.lists/templates/base.html (ch19l007-2)
413+
.src/lists/templates/base.html (ch19l007-2)
417414
====
418415
[source,html]
419416
----
@@ -445,7 +442,7 @@ Designing Our API Using the Template
445442
be empty...
446443

447444
[role="sourcecode"]
448-
.lists/templates/my_lists.html
445+
.src/lists/templates/my_lists.html
449446
====
450447
[source,html]
451448
----
@@ -460,7 +457,7 @@ be empty...
460457
And then we can just work inside the `extra_content` block:
461458

462459
[role="sourcecode"]
463-
.lists/templates/my_lists.html
460+
.src/lists/templates/my_lists.html
464461
====
465462
[source,html]
466463
----
@@ -530,7 +527,7 @@ Moving Down to the Next Layer: What the View Passes to the Template
530527
our views layer needs to respond to the requirements we've laid out in the template layer, by giving it the objects it needs. In this case, the list owner:
531528

532529
[role="sourcecode"]
533-
.lists/tests/test_views.py (ch19l011)
530+
.src/lists/tests/test_views.py (ch19l011)
534531
====
535532
[source,python]
536533
----
@@ -559,7 +556,7 @@ KeyError: 'owner'
559556
So:
560557

561558
[role="sourcecode"]
562-
.lists/views.py (ch19l012)
559+
.src/lists/views.py (ch19l012)
563560
====
564561
[source,python]
565562
----
@@ -578,7 +575,7 @@ the previous test. We just need to add a user for it as well:
578575

579576

580577
[role="sourcecode"]
581-
.lists/tests/test_views.py (ch19l013)
578+
.src/lists/tests/test_views.py (ch19l013)
582579
====
583580
[source,python]
584581
----
@@ -609,7 +606,7 @@ Here's a first crack at writing the test:
609606

610607

611608
[role="sourcecode"]
612-
.lists/tests/test_views.py (ch22l014)
609+
.src/lists/tests/test_views.py (ch22l014)
613610
====
614611
[source,python]
615612
----
@@ -637,7 +634,7 @@ AttributeError: 'List' object has no attribute 'owner'
637634
To fix this, we can try writing code like this:
638635

639636
[role="sourcecode"]
640-
.lists/views.py (ch22l015)
637+
.src/lists/views.py (ch22l015)
641638
====
642639
[source,python]
643640
----

tests/update_source_repo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
2-
import subprocess
3-
import os
42
import getpass
5-
from chapters import CHAPTERS
3+
import os
4+
import subprocess
65

6+
from chapters import CHAPTERS
77

88
REMOTE = "local" if getpass.getuser() == "harry" else "origin"
99
BASE_FOLDER = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -22,6 +22,7 @@ def fetch_if_possible(target_dir):
2222
if (
2323
"Name or service not known" in stderr.decode()
2424
or "Could not resolve" in stderr.decode()
25+
or "github.com port 22: Undefined error" in stderr.decode()
2526
):
2627
# no internet
2728
print("No Internet")

0 commit comments

Comments
 (0)