Permalink
Browse files

Added unit test for login with username and password

  • Loading branch information...
1 parent 9f56abe commit c62a11e1fd42ad633346247820e347d476aec382 Simon Willison committed May 23, 2009
Showing with 26 additions and 5 deletions.
  1. +1 −1 django_openid/tests/__init__.py
  2. +25 −4 django_openid/tests/auth_tests.py
@@ -1,3 +1,3 @@
from signing_tests import *
from consumer_tests import *
-#from auth_tests import *
+from auth_tests import *
@@ -1,7 +1,9 @@
from django.test import TestCase
+from django.test.client import Client
from django.http import Http404
-from django_openid.consumer import Consumer
+from django_openid.registration import RegistrationConsumer
from django_openid import signed
+from django.contrib.auth.models import User
from request_factory import RequestFactory
from openid_mocks import *
@@ -15,12 +17,31 @@ class AuthTest(TestCase):
def setUp(self):
# Create user accounts associated with OpenIDs
self.no_openids = User.objects.create(username = 'no-openids')
+ self.no_openids.set_password('password')
+ self.no_openids.save()
self.one_openid = User.objects.create(username = 'one-openid')
self.one_openid.openids.create(openid = 'http://a.example.com/')
self.two_openid = User.objects.create(username = 'two-openids')
self.two_openid.openids.create(openid = 'http://b.example.com/')
self.two_openid.openids.create(openid = 'http://c.example.com/')
- def testLogin(self):
- pass
-
+ def tearDown(self):
+ [user.delete() for user in User.objects.filter(username__in = (
+ 'no-openids', 'one-openid', 'two-openids'
+ ))]
+
+ def testLoginWithPassword(self):
+ client = Client()
+ response = client.post('/openid/login/', {
+ 'username': 'no-openids',
+ 'password': 'incorrect-password',
+ })
+ # Should get the login page again
+ self.assert_('login' in response.template_name)
+
+ response = client.post('/openid/login/', {
+ 'username': 'no-openids',
+ 'password': 'password',
+ })
+ # Should be a redirect
+ self.assert_(response.has_header('Location'))

0 comments on commit c62a11e

Please sign in to comment.