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

CHAPTER 10

Input Validation and Test Organisation

Over the next few chapters we’ll talk about testing and implementing validation of user

inputs. We’ll also take the opportunity to do a little tidying up—both in our application

code, and also in our tests.

Validation FT: Preventing Blank Items

As our first few users start using the site, we’ve noticed they sometimes make mistakes

that mess up their lists, like accidentally submitting blank list items, or accidentally

inputting two identical items to a list. Computers aremeant to help stop us frommaking

silly mistakes, so let’s see if we can get our site to help.

Here’s the outline of an FT:

functional_tests/tests.py (ch10l001).

def

test_cannot_add_empty_list_items

(

self

):

# Edith goes to the home page and accidentally tries to submit

# an empty list item. She hits Enter on the empty input box

# The home page refreshes, and there is an error message saying

# that list items cannot be blank

# She tries again with some text for the item, which now works

# Perversely, she now decides to submit a second blank list item

# She receives a similar warning on the list page

# And she can correct it by filling some text in

self

.

fail

(

'write me!'

)

That’s all very well, but before we go any further—our functional tests file is beginning

to get a little crowded. Let’s split it out into several files, in which each has a single test

method.

169