[Python-modules-commits] [python-social-auth] 84/89: add passing response to AuthCancel exception, if it available

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:15:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.15
in repository python-social-auth.

commit 769bd902f0a9424c48827721a64efe2768b7a197
Author: st4lk <myhappydo at gmail.com>
Date:   Sat Apr 2 22:14:37 2016 +0300

    add passing response to AuthCancel exception, if it available
---
 social/backends/evernote.py            |  2 +-
 social/backends/weixin.py              |  2 +-
 social/exceptions.py                   |  4 ++++
 social/tests/backends/test_evernote.py |  6 ++++--
 social/tests/backends/test_facebook.py | 24 +++++++++++++++++++++++-
 social/utils.py                        |  2 +-
 6 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/social/backends/evernote.py b/social/backends/evernote.py
index 2fde3e5..6a66585 100644
--- a/social/backends/evernote.py
+++ b/social/backends/evernote.py
@@ -50,7 +50,7 @@ class EvernoteOAuth(BaseOAuth1):
         except HTTPError as err:
             # Evernote returns a 401 error when AuthCanceled
             if err.response.status_code == 401:
-                raise AuthCanceled(self)
+                raise AuthCanceled(self, response=err.response)
             else:
                 raise
 
diff --git a/social/backends/weixin.py b/social/backends/weixin.py
index b1308f3..1b5c2d5 100644
--- a/social/backends/weixin.py
+++ b/social/backends/weixin.py
@@ -89,7 +89,7 @@ class WeixinOAuth2(BaseOAuth2):
             )
         except HTTPError as err:
             if err.response.status_code == 400:
-                raise AuthCanceled(self)
+                raise AuthCanceled(self, response=err.response)
             else:
                 raise
         except KeyError:
diff --git a/social/exceptions.py b/social/exceptions.py
index 88e1155..aa174c9 100644
--- a/social/exceptions.py
+++ b/social/exceptions.py
@@ -41,6 +41,10 @@ class AuthFailed(AuthException):
 
 class AuthCanceled(AuthException):
     """Auth process was canceled by user."""
+    def __init__(self, *args, **kwargs):
+        self.response = kwargs.pop('response', None)
+        super(AuthCanceled, self).__init__(*args, **kwargs)
+
     def __str__(self):
         return 'Authentication process canceled'
 
diff --git a/social/tests/backends/test_evernote.py b/social/tests/backends/test_evernote.py
index f839073..1cf1b35 100644
--- a/social/tests/backends/test_evernote.py
+++ b/social/tests/backends/test_evernote.py
@@ -34,12 +34,14 @@ class EvernoteOAuth1CanceledTest(EvernoteOAuth1Test):
     access_token_status = 401
 
     def test_login(self):
-        with self.assertRaises(AuthCanceled):
+        with self.assertRaises(AuthCanceled) as cm:
             self.do_login()
+        self.assertTrue(cm.exception.response is not None)
 
     def test_partial_pipeline(self):
-        with self.assertRaises(AuthCanceled):
+        with self.assertRaises(AuthCanceled) as cm:
             self.do_partial_pipeline()
+        self.assertTrue(cm.exception.response is not None)
 
 
 class EvernoteOAuth1ErrorTest(EvernoteOAuth1Test):
diff --git a/social/tests/backends/test_facebook.py b/social/tests/backends/test_facebook.py
index fc1aa5f..166d753 100644
--- a/social/tests/backends/test_facebook.py
+++ b/social/tests/backends/test_facebook.py
@@ -1,6 +1,6 @@
 import json
 
-from social.exceptions import AuthUnknownError
+from social.exceptions import AuthUnknownError, AuthCanceled
 
 from social.tests.backends.oauth import OAuth2Test
 
@@ -42,3 +42,25 @@ class FacebookOAuth2WrongUserDataTest(FacebookOAuth2Test):
     def test_partial_pipeline(self):
         with self.assertRaises(AuthUnknownError):
             self.do_partial_pipeline()
+
+
+class FacebookOAuth2AuthCancelTest(FacebookOAuth2Test):
+    access_token_status = 400
+    access_token_body = json.dumps({
+        'error': {
+            'message': "redirect_uri isn't an absolute URI. Check RFC 3986.",
+            'code': 191,
+            'type': 'OAuthException',
+            'fbtrace_id': '123Abc'
+        }
+    })
+
+    def test_login(self):
+        with self.assertRaises(AuthCanceled) as cm:
+            self.do_login()
+        self.assertIn('error', cm.exception.response.json())
+
+    def test_partial_pipeline(self):
+        with self.assertRaises(AuthCanceled) as cm:
+            self.do_partial_pipeline()
+        self.assertIn('error', cm.exception.response.json())
diff --git a/social/utils.py b/social/utils.py
index 0a473af..0b5a507 100644
--- a/social/utils.py
+++ b/social/utils.py
@@ -229,7 +229,7 @@ def handle_http_errors(func):
             return func(*args, **kwargs)
         except requests.HTTPError as err:
             if err.response.status_code == 400:
-                raise AuthCanceled(args[0])
+                raise AuthCanceled(args[0], response=err.response)
             elif err.response.status_code == 503:
                 raise AuthUnreachableProvider(args[0])
             else:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git



More information about the Python-modules-commits mailing list