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

url

(

r'^login$'

,

'accounts.views.persona_login'

,

name

=

'persona_login'

),

)

Will a minimal view do anything?

accounts/views.py.

from

django.contrib.auth

import

authenticate

def

persona_login

():

pass

Yep:

TypeError: persona_login() takes 0 positional arguments but 1 was given

And so:

accounts/views.py (ch16l008).

def

persona_login

(

request

):

pass

Then:

ValueError: The view accounts.views.persona_login didn't return an HttpResponse

object. It returned None instead.

accounts/views.py (ch16l009).

from

django.contrib.auth

import

authenticate

from

django.http

import

HttpResponse

def

persona_login

(

request

):

return

HttpResponse

()

And we’re back to:

AssertionError: Expected 'authenticate' to be called once. Called 0 times.

We try:

accounts/views.py.

def

persona_login

(

request

):

authenticate

()

return

HttpResponse

()

And sure enough, we get:

AssertionError: Expected call: authenticate(assertion='assert this')

Actual call: authenticate()

And then we can fix that too:

accounts/views.py.

def

persona_login

(

request

):

authenticate

(

assertion

=

request

.

POST

[

'assertion'

])

return

HttpResponse

()

OK so far. One Python function mocked and tested.

280

|

Chapter 16: Server-Side Authentication and Mocking in Python