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

Figure 7-1. Our homepage, looking a little ugly…

But we can test the implementation of our aesthetics—just enough to reassure ourselves

that things are working. For example, we’re going to use Cascading Style Sheets (CSS)

for our styling, and they are loaded as static files. Static files can be a bit tricky to con‐

figure (especially, as we’ll see later, when you move off your own PC and onto a hosting

site), so we’ll want some kind of simple “smoke test” that the CSS has loaded. We don’t

have to test fonts and colours and every single pixel, but we can do a quick check that

the main input box is aligned the way we want it on each page, and that will give us

confidence that the rest of the styling for that page is probably loaded too.

We start with a new test method inside our functional test:

functional_tests/tests.py (ch07l001).

class

NewVisitorTest

(

LiveServerTestCase

):

[

...

]

def

test_layout_and_styling

(

self

):

# Edith goes to the home page

self

.

browser

.

get

(

self

.

live_server_url

)

self

.

browser

.

set_window_size

(

1024

,

768

)

# She notices the input box is nicely centered

inputbox

=

self

.

browser

.

find_element_by_id

(

'id_new_item'

)

self

.

assertAlmostEqual

(

inputbox

.

location

[

'x'

]

+

inputbox

.

size

[

'width'

]

/

2

,

512

,

delta

=

5

)

116

|

Chapter 7: Prettification: Layout and Styling, and What to Test About It