Add some tests.

This commit is contained in:
juanifioren 2015-02-11 15:37:51 -03:00
parent 010e27a007
commit 09fbaa7b3d
7 changed files with 83 additions and 9 deletions

View file

@ -19,7 +19,7 @@ Install the package using pip.
.. code:: bash
pip install git+https://github.com/juanifioren/django-openid-provider.git#egg=openid_provider
pip install git+https://github.com/juanifioren/django-oidc-provider.git#egg=openid_provider
Add it to your apps.
@ -216,6 +216,16 @@ You can copy the sample html here and edit them with your own styles.
<h3>{{ error }}</h3>
<p>{{ description }}</p>
*************
Running tests
*************
Just run them as normal Django tests.
.. code:: bash
$ python manage.py test openid_provider
************
Contributing
************

View file

View file

@ -0,0 +1,29 @@
from django.core.urlresolvers import reverse
from django.test import RequestFactory
from django.test import TestCase
from openid_provider.tests.utils import *
from openid_provider.views import *
class CodeFlowTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.user = create_fake_user()
self.client = create_fake_client(response_type='code')
def test_authorize_invalid_parameters(self):
"""
If the request fails due to a missing, invalid, or mismatching
redirection URI, or if the client identifier is missing or invalid,
the authorization server SHOULD inform the resource owner of the error.
See: https://tools.ietf.org/html/rfc6749#section-4.1.2.1
"""
url = reverse('openid_provider:authorize')
request = self.factory.get(url)
response = AuthorizeView.as_view()(request)
self.assertEqual(response.status_code, 200)
self.assertEqual(bool(response.content), True)

View file

@ -0,0 +1,36 @@
from django.contrib.auth.models import User
from openid_provider.models import *
def create_fake_user():
"""
Create a test user.
Return a User object.
"""
user = User()
user.username = 'johndoe'
user.email = 'johndoe@example.com'
user.set_password('1234')
user.save()
return user
def create_fake_client(response_type):
"""
Create a test client, response_type argument MUST be:
'code', 'id_token' or 'id_token token'.
Return a Client object.
"""
client = Client()
client.name = 'Some Client'
client.client_id = '123'
client.client_secret = '456'
client.response_type = response_type
client.redirect_uris = ['http://example.com/']
client.save()
return client

View file

@ -1,12 +1,12 @@
from django.conf.urls import patterns, include, url
from django.views.decorators.csrf import csrf_exempt
from openid_provider.views import *
urlpatterns = patterns('',
url(r'^authorize/$', AuthorizeView.as_view(), name='authorize'),
url(r'^token/$', csrf_exempt(TokenView.as_view()), name='token'),
url(r'^userinfo/$', csrf_exempt(userinfo), name='userinfo'),
url(r'^authorize/$', AuthorizeView.as_view(), name='authorize'),
url(r'^token/$', csrf_exempt(TokenView.as_view()), name='token'),
url(r'^userinfo/$', csrf_exempt(userinfo), name='userinfo'),
)

View file

@ -1,5 +1,4 @@
from django.contrib.auth.views import redirect_to_login
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import render
from django.template.loader import render_to_string

View file

@ -8,14 +8,14 @@ with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='django-openid-provider',
version='0.1',
name='django-oidc-provider',
version='0.0.0',
packages=['openid_provider'],
include_package_data=True,
license='MIT License',
description='A simple OpenID Connect Provider implementation for Djangonauts.',
long_description=README,
url='http://github.com/juanifioren/django-openid-provider',
url='http://github.com/juanifioren/django-oidc-provider',
author='Juan Ignacio Fiorentino',
author_email='juanifioren@gmail.com',
classifiers=[