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

def

home_page

(

request

):

return

HttpResponse

()

• Tests again:

self.assertTrue(response.content.startswith(b'<html>'))

AssertionError: False is not true

• Code again:

lists/views.py.

def

home_page

(

request

):

return

HttpResponse

(

'<html>'

)

• Tests:

AssertionError: b'<title>To-Do lists</title>' not found in b'<html>'

• Code:

lists/views.py.

def

home_page

(

request

):

return

HttpResponse

(

'<html><title>To-Do lists</title>'

)

• Tests—almost there?

self.assertTrue(response.content.endswith(b'</html>'))

AssertionError: False is not true

• Come on, one last effort:

lists/views.py.

def

home_page

(

request

):

return

HttpResponse

(

'<html><title>To-Do lists</title></html>'

)

• Surely?

$

python3 manage.py test

Creating test database for alias 'default'...

..

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

Ran 2 tests in 0.001s

OK

Destroying test database for alias 'default'...

Yes! Now, let’s run our functional tests. Don’t forget to spin up the dev server again, if

it’s not still running. It feels like the final heat of the race here, surely this is it … could

it be?

32

|

Chapter 3: Testing a Simple Home Page with Unit Tests