[med-svn] [python-fitbit] 01/02: Imported Upstream version 0.2.4
Dylan Aïssi
bob.dybian-guest at moszumanska.debian.org
Wed Dec 7 22:06:23 UTC 2016
This is an automated email from the git hooks/post-receive script.
bob.dybian-guest pushed a commit to branch master
in repository python-fitbit.
commit fe2a47b95f3c592cb079686ea2bd95a835ba39da
Author: Dylan Aïssi <bob.dybian at gmail.com>
Date: Wed Dec 7 23:06:07 2016 +0100
Imported Upstream version 0.2.4
---
CHANGELOG.rst | 4 ++++
fitbit/__init__.py | 4 ++--
fitbit/api.py | 6 +++++-
fitbit_tests/test_auth.py | 6 ++++++
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index d5b1fa8..a7be7ab 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,7 @@
+0.2.4 (2016-11-10)
+==================
+* Call a hook if it exists when tokens are refreshed
+
0.2.3 (2016-07-06)
==================
* Refresh token when it expires
diff --git a/fitbit/__init__.py b/fitbit/__init__.py
index d2b77ca..be97389 100644
--- a/fitbit/__init__.py
+++ b/fitbit/__init__.py
@@ -17,8 +17,8 @@ __author_email__ = 'bpitcher at orcasinc.com'
__copyright__ = 'Copyright 2012-2015 ORCAS'
__license__ = 'Apache 2.0'
-__version__ = '0.2.3'
-__release__ = '0.2.3'
+__version__ = '0.2.4'
+__release__ = '0.2.4'
# Module namespace.
diff --git a/fitbit/api.py b/fitbit/api.py
index d3f8bd5..1984135 100644
--- a/fitbit/api.py
+++ b/fitbit/api.py
@@ -29,7 +29,7 @@ class FitbitOauth2Client(object):
refresh_token_url = request_token_url
def __init__(self, client_id, client_secret,
- access_token=None, refresh_token=None,
+ access_token=None, refresh_token=None, refresh_cb=None,
*args, **kwargs):
"""
Create a FitbitOauth2Client object. Specify the first 7 parameters if
@@ -47,6 +47,7 @@ class FitbitOauth2Client(object):
'access_token': access_token,
'refresh_token': refresh_token
}
+ self.refresh_cb = refresh_cb
self.oauth = OAuth2Session(client_id)
def _request(self, method, url, **kwargs):
@@ -163,6 +164,9 @@ class FitbitOauth2Client(object):
auth=requests.auth.HTTPBasicAuth(self.client_id, self.client_secret)
)
+ if self.refresh_cb:
+ self.refresh_cb(self.token)
+
return self.token
diff --git a/fitbit_tests/test_auth.py b/fitbit_tests/test_auth.py
index be1de74..c7395d2 100644
--- a/fitbit_tests/test_auth.py
+++ b/fitbit_tests/test_auth.py
@@ -65,9 +65,11 @@ class Auth2Test(TestCase):
# 1. first call to _request causes a HTTPUnauthorized
# 2. the token_refresh call is faked
# 3. the second call to _request returns a valid value
+ refresh_cb = mock.MagicMock()
kwargs = self.client_kwargs
kwargs['access_token'] = 'fake_access_token'
kwargs['refresh_token'] = 'fake_refresh_token'
+ kwargs['refresh_cb'] = refresh_cb
fb = Fitbit(**kwargs)
with mock.patch.object(FitbitOauth2Client, '_request') as r:
@@ -88,15 +90,18 @@ class Auth2Test(TestCase):
"fake_return_refresh_token", fb.client.token['refresh_token'])
self.assertEqual(1, rt.call_count)
self.assertEqual(2, r.call_count)
+ refresh_cb.assert_called_once_with(rt.return_value)
def test_auto_refresh_token_non_exception(self):
"""Test of auto_refersh when the exception doesn't fire"""
# 1. first call to _request causes a 401 expired token response
# 2. the token_refresh call is faked
# 3. the second call to _request returns a valid value
+ refresh_cb = mock.MagicMock()
kwargs = self.client_kwargs
kwargs['access_token'] = 'fake_access_token'
kwargs['refresh_token'] = 'fake_refresh_token'
+ kwargs['refresh_cb'] = refresh_cb
fb = Fitbit(**kwargs)
with mock.patch.object(FitbitOauth2Client, '_request') as r:
@@ -117,6 +122,7 @@ class Auth2Test(TestCase):
"fake_return_refresh_token", fb.client.token['refresh_token'])
self.assertEqual(1, rt.call_count)
self.assertEqual(2, r.call_count)
+ refresh_cb.assert_called_once_with(rt.return_value)
class fake_response(object):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-fitbit.git
More information about the debian-med-commit
mailing list