element: {"method":"link text","selector":"Reticulate splines"}' ; Stacktrace:
---------------------------------------------------------------------
Ran 7 tests in 77.613s
FAILED (errors=1)
Well, no further, but at least we didn’t break anything. Time for a commit:
$
git add lists
$
git diff --staged
$
git commit -m "url, placeholder view, and first-cut templates for my_lists"
Moving Down to the Next Layer: What the View Passes to the
Template
lists/tests/test_views.py (ch18l011).
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
[
...
]
class
MyListsTest
(
TestCase
):
def
test_my_lists_url_renders_my_lists_template
(
self
):
[
...
]
def
test_passes_correct_owner_to_template
(
self
):
User
.
objects
.
create
(
=
'wrong@owner.com'
)
correct_user
=
User
.
objects
.
create
(
=
'a@b.com'
)
response
=
self
.
client
.
get
(
'/lists/users
/a@b.com/'
)
self
.
assertEqual
(
response
.
context
[
'owner'
],
correct_user
)
Gives:
KeyError: 'owner'
So:
lists/views.py (ch18l012).
from
django.contrib.auth
import
get_user_model
User
=
get_user_model
()
[
...
]
def
my_lists
(
request
,
):
owner
=
User
.
objects
.
get
(
=
)
return
render
(
request
,
'my_lists.html'
, {
'owner'
:
owner
})
That gets our new test passing, but we’ll also see an error from the previous test. We just
need to add a user for it as well:
lists/tests/test_views.py (ch18l013).
def
test_my_lists_url_renders_my_lists_template
(
self
):
User
.
objects
.
create
(
=
'a@b.com'
)
[
...
]
And we get to an OK:
Another Pass, Outside-In
|
329