Chapter 12. Splitting Our Tests into Multiple Files, and a Generic Wait Helper
The next feature we might like to implement is a little input validation. But as we start writing new tests, weâll notice that itâs getting hard to find our way around a single functional_tests.py, and tests.py, so weâll reorganise them into multiple filesâa little refactor of our tests, if you will.
Weâll also build a generic explicit wait helper.
Start on a 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 are meant to help stop us from making 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 (ch11l001)
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 Test-Driven Development with Python, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.