Background Image
Table of Contents Table of Contents
Previous Page  357 / 478 Next Page
Information
Show Menu
Previous Page 357 / 478 Next Page
Page Background

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

(

email

=

'wrong@owner.com

'

)

correct_user

=

User

.

objects

.

create

(

email

=

'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

,

email

):

owner

=

User

.

objects

.

get

(

email

=

email

)

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

(

email

=

'a@b.com

'

)

[

...

]

And we get to an OK:

Another Pass, Outside-In

|

329