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

The Moment of Truth: Will the FT Pass?

I think we’re just about ready to try our functional test! Let’s just wire up our base

template. Firstly, it needs to show a different message for logged-in and non-logged-in

users:

lists/templates/base.html.

<nav

class=

"navbar navbar-default"

role=

"navigation"

>

<a

class=

"navbar-brand"

href=

"/"

>

Superlists

</a>

{% if user.email %}

<a

class=

"btn navbar-btn navbar-right"

id=

"id_logout"

href=

"#"

>

Log out

</a>

<span

class=

"navbar-text navbar-right"

>

Logged in as {{ user.email }}

</span>

{% else %}

<a

class=

"btn navbar-btn navbar-right"

id=

"id_login"

href=

"#"

>

Sign in

</a>

{% endif %}

</nav>

Lovely. Then we wire up our various context variables for the call to

initialize

:

lists/templates/base.html.

<script>

/*global $, Superlists, navigator */

$

(

document

).

ready

(

function

() {

var

user

=

"{{ user.email }}"

||

null

;

var

token

=

"{{ csrf_token }}"

;

var

urls

=

{

login

:

"{% url 'persona_login' %}"

,

logout

:

"TODO"

,

};

Superlists

.

Accounts

.

initialize

(

navigator

,

user

,

token

,

urls

);

});

</script>

So how does our FT get along?

$

python3 manage.py test functional_tests.test_login

Creating test database for alias 'default'...

[...]

Ran 1 test in 26.382s

OK

Woohoo!

I’ve been waiting to do a commit up until this moment, just to make sure everything

works. At this point, you could make a series of separate commits—one for the login

view, one for the auth backend, one for the user model, one for wiring up the template.

Or you could decide that, since they’re all interrelated, and none will work without the

others, you may as well just have one big commit:

$

git status

$

git add .

$

git diff --staged

$

git commit -am "Custom Persona auth backend + custom user model"

298

|

Chapter 16: Server-Side Authentication and Mocking in Python