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

Get FTs to clean up after themselves

Adjust model so that items are associated

with different lists

Add unique URLs for each list

Add a URL for creating a new list via POST

Add URLs for adding a new item to an

existing list via POST

Each List Should Have Its Own URL

What shall we use as the unique identifier for our lists? Probably the simplest thing, for

now, is just to use the auto-generated

id

field from the database. Let’s change

List

ViewTest

so that the two tests point at new URLs.

We’ll also change the old

test_displays_all_items

test and call it

test_displays_on

ly_items_for_that_list

instead, and make it check that only the items for a specific

list are displayed:

lists/tests.py (ch06l033-1).

class

ListViewTest

(

TestCase

):

def

test_uses_list_template

(

self

):

list_

=

List

.

objects

.

create

()

response

=

self

.

client

.

get

(

'/lists/

%d

/'

%

(

list_

.

id

,))

self

.

assertTemplateUsed

(

response

,

'list.html'

)

def

test_displays_only_items_for_that_list

(

self

):

correct_list

=

List

.

objects

.

create

()

Item

.

objects

.

create

(

text

=

'itemey 1'

,

list

=

correct_list

)

Item

.

objects

.

create

(

text

=

'itemey 2'

,

list

=

correct_list

)

other_list

=

List

.

objects

.

create

()

Item

.

objects

.

create

(

text

=

'other list item 1'

,

list

=

other_list

)

Item

.

objects

.

create

(

text

=

'other list item 2'

,

list

=

other_list

)

response

=

self

.

client

.

get

(

'/lists/

%d

/'

%

(

correct_list

.

id

,))

self

.

assertContains

(

response

,

'itemey 1'

)

self

.

assertContains

(

response

,

'itemey 2'

)

self

.

assertNotContains

(

response

,

'other list item 1'

)

self

.

assertNotContains

(

response

,

'other list item 2'

)

102

|

Chapter 6: Getting to the Minimum Viable Site