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

We’re past the first step, but now we have to bring the rest of the application code in line

with the change. We need to find any occurrences of the old

id

(

id_new_item

) and

name

(

item_text

) and replace them too, with

id_text

and

text

, respectively:

$

grep -r id_new_item lists/

lists/static/base.css:#id_new_item {

That’s one change, and similarly for the

name

:

$

grep -Ir item_text lists

lists/views.py: item = Item(text=request.POST['item_text'], list=list_)

lists/views.py: item = Item(text=request.POST['item_text'],

lists/tests/test_views.py: data={'item_text': 'A new list item'}

lists/tests/test_views.py: data={'item_text': 'A new list item'}

lists/tests/test_views.py: response = self.client.post('/lists/new',

data={'item_text': ''})

[...]

Once we’re done, we rerun the unit tests to check everything still works:

$

python3 manage.py test lists

Creating test database for alias 'default'...

.................

---------------------------------------------------------------------

Ran 17 tests in 0.126s

OK

Destroying test database for alias 'default'...

And the functional tests too:

$

python3 manage.py test functional_tests

[...]

File "/workspace/superlists/functional_tests/test_simple_list_creation.py",

line 40, in test_can_start_a_list_and_retrieve_it_later

return self.browser.find_element_by_id('id_text')

File "/workspace/superlists/functional_tests/base.py", line 31, in

get_item_input_box

return self.browser.find_element_by_id('id_text')

selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate

element: {"method":"id","selector":"id_text"}' ; Stacktrace:

[...]

FAILED (errors=3)

Not quite! Let’s look at where this is happening—if you check the line number from one

of the failures, you’ll see that each time after we’ve submitted a first item, the input box

has disappeared from the lists page.

Checking

views.py

and the

new_list

viewwe can see it’s because if we detect a validation

error, we’re not actually passing the form to the

home.html

template:

202

|

Chapter 11: A Simple Form