From 0bf116745994cfe624c9a0cd9b4637e0ff8aab48 Mon Sep 17 00:00:00 2001 From: Andrii Kostenko Date: Thu, 23 Feb 2012 17:02:27 +0200 Subject: [PATCH] fixed twitter tests --- social_auth/tests/base.py | 22 +++++++++++++++++++--- social_auth/tests/twitter.py | 12 +++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/social_auth/tests/base.py b/social_auth/tests/base.py index 26695ea..b8dd564 100644 --- a/social_auth/tests/base.py +++ b/social_auth/tests/base.py @@ -3,7 +3,7 @@ import urllib2 import cookielib import urllib import urlparse -import unittest +from django.test.simple import TestCase from sgmllib import SGMLParser from django.test.client import Client @@ -14,7 +14,7 @@ USER_AGENT = 'Mozilla/5.0' 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 @@ -27,8 +27,24 @@ class SocialAuthTestsCase(unittest.TestCase): 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: @@ -39,7 +55,7 @@ class SocialAuthTestsCase(unittest.TestCase): 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 diff --git a/social_auth/tests/twitter.py b/social_auth/tests/twitter.py index ee5cc23..a2672a3 100644 --- a/social_auth/tests/twitter.py +++ b/social_auth/tests/twitter.py @@ -1,6 +1,7 @@ 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): @@ -17,6 +18,15 @@ 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 @@ -25,7 +35,7 @@ class TwitterTestLogin(TwitterTestCase): # 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} -- 2.39.5