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

We specify we’re going to use a CSS class from Bootstrap called

.has-error

to

mark our error text. We’ll see that Bootstrap has some useful styling for those

As predicted, we are reusing the

check_for_row_in_list_table

helper

function when we want to confirm that list item submission

does

work.

The technique of keeping helper methods in a parent class is meant to prevent dupli‐

cation across your functional test code. The daywe decide to change the implementation

of how our list table works, we want to make sure we only have to change our FT code

in one place, not in dozens of places across loads of FTs…

And we’re off!

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

element: {"method":"css selector","selector":".has-error"}' ; Stacktrace:

I’ll let you do your own “first-cut FT” commit.

Using Model-Layer Validation

There are two levels at which you can do validation in Django. One is at the model level,

and the other is higher up at the forms level. I like to use the lower level whenever

possible, partially because I’m a bit too fond of databases and database integrity rules,

and partially because it’s safer—you can sometimes forget which formyou use to validate

input, but you’re always going to use the same database.

Refactoring Unit Tests into Several Files

We’re going to want to add another test for our model, but before we do so, it’s time to

tidy up our unit tests in a similar way to the functional tests. A difference will be that,

because the

lists

app contains real application code as well as tests, we’ll separate out

the tests into their own folder:

$

mkdir lists/tests

$

touch lists/tests/__init__.py

$

git mv lists/tests.py lists/tests/test_all.py

$

git status

$

git add lists/tests

$

python3 manage.py test lists

[...]

Ran 10 tests in 0.034s

OK

$

git commit -m"Move unit tests into a folder with single file"

Using Model-Layer Validation

|

175