import cookielib
import urllib
import urlparse
-import unittest
+from django.test.simple import TestCase
from sgmllib import SGMLParser
from django.test.client import Client
REFRESH_RE = re.compile(r'\d;\s*url=')
-class SocialAuthTestsCase(unittest.TestCase):
+class SocialAuthTestsCase(TestCase):
"""Base class for social auth tests"""
SERVER_NAME = None
SERVER_PORT = None
client_kwargs['SERVER_PORT'] = self.SERVER_PORT
self.jar = None
self.client = Client(**client_kwargs)
+ from social_auth import backends
+ self.old_PIPELINE = backends.PIPELINE
+ backends.PIPELINE = (
+ 'social_auth.backends.pipeline.social.social_auth_user',
+ 'social_auth.backends.pipeline.associate.associate_by_email',
+ 'social_auth.backends.pipeline.user.get_username',
+ 'social_auth.backends.pipeline.user.create_user',
+ 'social_auth.backends.pipeline.social.associate_user',
+ 'social_auth.backends.pipeline.social.load_extra_data',
+ 'social_auth.backends.pipeline.user.update_user_details',
+ )
super(SocialAuthTestsCase, self).__init__(*args, **kwargs)
+ def tearDown(self):
+ from social_auth import backends
+ backends.PIPELINE = self.old_PIPELINE
+ super(SocialAuthTestsCase, self).tearDown()
+
def test_backend_cache(self):
"""Ensure that the backend for the testcase gets cached."""
try:
from social_auth import backends
backends.BACKENDS = {}
self.client.get(self.reverse('socialauth_begin', self.name))
- self.assertTrue(self.name in backends.BACKENDS)
+ self.assertTrue(self.name in backends.BACKENDSCACHE)
def get_content(self, url, data=None, use_cookies=False):
"""Return content for given url, if data is not None, then a POST
from social_auth.utils import setting
from social_auth.tests.base import SocialAuthTestsCase, FormParserByID, \
RefreshParser
+from django.test.utils import override_settings
class TwitterTestCase(SocialAuthTestsCase):
class TwitterTestLogin(TwitterTestCase):
+ @override_settings(SOCIAL_AUTH_PIPELINE = (
+ 'social_auth.backends.pipeline.social.social_auth_user',
+ 'social_auth.backends.pipeline.associate.associate_by_email',
+ 'social_auth.backends.pipeline.user.get_username',
+ 'social_auth.backends.pipeline.misc.save_status_to_session',
+ 'social_auth.backends.pipeline.social.associate_user',
+ 'social_auth.backends.pipeline.social.load_extra_data',
+ 'social_auth.backends.pipeline.user.update_user_details',
+ ))
def test_login_succeful(self):
response = self.client.get(self.reverse('socialauth_begin', 'twitter'))
# social_auth must redirect to service page
# Open first redirect page, it contains user login form because
# we don't have cookie to send to twitter
login_content = self.get_content(response['Location'])
- parser = FormParserByID('login_form')
+ parser = FormParserByID('oauth_form')
parser.feed(login_content)
auth = {'session[username_or_email]': self.user,
'session[password]': self.passwd}