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

And then we change the implementation:

accounts/authentication.py.

@@ -1,8 +1,8 @@

import requests

+from django.conf import settings

from django.contrib.auth import get_user_model

User = get_user_model()

PERSONA_VERIFY_URL =

'https://verifier.login.persona.org/verify'

-DOMAIN = 'localhost'

@@ -11,7 +11,7 @@ class PersonaAuthenticationBackend(object):

def authenticate(self, assertion):

response = requests.post(

PERSONA_VERIFY_URL,

- data={'assertion': assertion, 'audience': DOMAIN}

+ data={'assertion': assertion, 'audience': settings.DOMAIN}

)

if response.ok and response.json()['status'] == 'okay':

email = response.json()['email']

Rerunning the tests just to be sure:

$

python3 manage.py test accounts

[...]

Ran 14 tests in 0.053s

OK

Next we update our fabfile to make it adjust the domain in

settings.py

, removing the

cumbersome two-line

sed

on

ALLOWED_HOSTS

:

deploy_tools/fabfile.py.

def

_update_settings

(

source_folder

,

site_name

):

settings_path

=

source_folder

+

'/superlists/settings.py'

sed

(

settings_path

,

"DEBUG = True"

,

"DEBUG = False"

)

sed

(

settings_path

,

'DOMAIN = "localhost"'

,

'DOMAIN = "

%s

"'

%

(

site_name

,))

secret_key_file

=

source_folder

+

'/superlists/secret_key.py'

if

not

exists

(

secret_key_file

):

[

...

]

We redeploy, and spot the

sed

in the output:

$

fab deploy --host=superlists-staging.ottg.eu

[...]

[superlists-staging.ottg.eu] run: sed -i.bak -r -e

s/DOMAIN =

"localhost"/DOMAIN = "superlists-staging.ottg.eu"/g

"$(echo

/home/harry/sites/superlists-staging.ottg.eu/source/superlists/settings.py)"

[...]

310

|

Chapter 17: Test Fixtures, Logging, and Server-Side Debugging