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

Our first FT is now in its own file, and should be just one class and one test method:

functional_tests/test_simple_list_creation.py (ch10l004).

from

.base

import

FunctionalTest

from

selenium

import

webdriver

from

selenium.webdriver.common.keys

import

Keys

class

NewVisitorTest

(

FunctionalTest

):

def

test_can_start_a_list_and_retrieve_it_later

(

self

):

[

...

]

I used a relative import (

from .base

). Some people like to use them a lot in Django

code (eg, your views might import models using

from .models import List

, instead

of

from list.models

). Ultimately this is a matter of personal preference. I prefer to use

relative imports only when I’m super-super sure that the relative position of the thing

I’m importing won’t change. That applies in this case because I know for sure all the

tests will sit next to

base.py

, which they inherit from.

The layout and styling FT should now be one file and one class:

functional_tests/test_layout_and_styling.py (ch10l005).

from

.base

import

FunctionalTest

class

LayoutAndStylingTest

(

FunctionalTest

):

[

...

]

Lastly our new validation test is in a file of its own too:

functional_tests/test_list_item_validation.py (ch10l006).

from

unittest

import

skip

from

.base

import

FunctionalTest

class

ItemValidationTest

(

FunctionalTest

):

@skip

def

test_cannot_add_empty_list_items

(

self

):

[

...

]

And we can test everything worked by rerunning

manage.py test function

al_tests

, and checking once again that all three tests are run:

Ran 3 tests in 11.577s

OK

Now we can remove our skip:

functional_tests/test_list_item_validation.py (ch10l007).

class

ItemValidationTest

(

FunctionalTest

):

def

test_cannot_add_empty_list_items

(

self

):

[

...

]

Validation FT: Preventing Blank Items

|

173