]> git.parisson.com Git - django-social-auth.git/commitdiff
fixed twitter tests
authorAndrii Kostenko <andrey@kostenko.name>
Thu, 23 Feb 2012 15:02:27 +0000 (17:02 +0200)
committerAndrii Kostenko <andrey@kostenko.name>
Thu, 23 Feb 2012 15:02:27 +0000 (17:02 +0200)
social_auth/tests/base.py
social_auth/tests/twitter.py

index 26695eae1b9da9d1c9b8069400449c0a4072cda4..b8dd5643a05ffe969d14a38c214e22f2ca7548d5 100644 (file)
@@ -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
index ee5cc2342e5c82f75d522249a41f2706b58c952e..a2672a32c5a5620738de181376093128fd079ad9 100644 (file)
@@ -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}