Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Fixup djopenid example
Browse files Browse the repository at this point in the history
  • Loading branch information
ziima committed Nov 14, 2018
1 parent 651ea5d commit 14e7658
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
8 changes: 4 additions & 4 deletions examples/djopenid/README
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ SETUP

1. Install the OpenID library, version 2.0.0 or later.

2. Install Django 0.95.1.
2. Install Django.

If you find that the examples run on even newer versions of
If you find that the examples doesn't run on newer versions of
Django, please let us know!

3. Modify djopenid/settings.py appropriately; you may wish to change
Expand All @@ -23,11 +23,11 @@ SETUP

4. In examples/djopenid/ run:

python manage.py syncdb
python manage.py migrate

5. To run the example consumer or server, run

python manage.py runserver PORT
python manage.py runserver [PORT]

where PORT is the port number on which to listen.

Expand Down
56 changes: 56 additions & 0 deletions examples/djopenid/consumer/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Test the consumer."""
from __future__ import unicode_literals

import django
from django.test import TestCase
from openid.fetchers import setDefaultFetcher, HTTPResponse
from openid.yadis.constants import YADIS_CONTENT_TYPE

# Allow django tests to run through discover
django.setup()


EXAMPLE_XRDS = b'''<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<XRD>
<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/server</Type>
<URI>http://example.com/</URI>
</Service>
</XRD>
</xrds:XRDS>'''


class FakeFetcher(object):
"""Fake fetcher for tests."""

def __init__(self):
self.response = None

def fetch(self, *args, **kwargs):
return self.response


class TestStartOpenID(TestCase):
"""Test 'startOpenID' view."""

def setUp(self):
self.fetcher = FakeFetcher()
setDefaultFetcher(self.fetcher)

def tearDown(self):
setDefaultFetcher(None)

def test_get(self):
response = self.client.get('/consumer/')
self.assertContains(response, ' example consumer ')

def test_post(self):
self.fetcher.response = HTTPResponse('http://example.com/', 200, {'content-type': YADIS_CONTENT_TYPE},
EXAMPLE_XRDS)

response = self.client.post('/consumer/', {'openid_identifier': 'http://example.com/'})

# Renders a POST form
self.assertContains(response, 'http://example.com/')
self.assertContains(response, 'openid.identity')
4 changes: 2 additions & 2 deletions examples/djopenid/consumer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def startOpenID(request):

# Compute the trust root and return URL values to build the
# redirect information.
trust_root = util.request.build_absolute_uri(reverse('consumer:index'))
return_to = util.request.build_absolute_uri(reverse('consumer:return_to'))
trust_root = request.build_absolute_uri(reverse('consumer:index'))
return_to = request.build_absolute_uri(reverse('consumer:return_to'))

# Send the browser to the server either by sending a redirect
# URL or by generating a POST form.
Expand Down
6 changes: 3 additions & 3 deletions examples/djopenid/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
}

SECRET_KEY = 'u^bw6lmsa6fah0$^lz-ct$)y7x7#ag92-z+y45-8!(jk0lkavy'
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

TEMPLATES = [
{
Expand All @@ -34,10 +36,8 @@
]

MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.common.CommonMiddleware',
)

ROOT_URLCONF = 'djopenid.urls'
Expand Down

0 comments on commit 14e7658

Please sign in to comment.