diff --git a/rowers/integrations/integrations.py b/rowers/integrations/integrations.py index 686277cf..4857f80f 100644 --- a/rowers/integrations/integrations.py +++ b/rowers/integrations/integrations.py @@ -128,13 +128,17 @@ class SyncIntegration(metaclass=ABCMeta): try: expires_in = token_json['expires_in'] except KeyError: # pragma: no cover - expires_in = 0 + try: + expires_at = arrow.get(token_json['expires_at']).timestamp() + expires_in = expires_at - arrow.now().timestamp() + except KeyError: # pragma: no cover + expires_in = 0 try: expires_in = int(expires_in) except (ValueError, TypeError): # pragma: no cover expires_in = 0 - else: # pragma: no cover - raise NoTokenError("Failed to obtain token") + else: # pragma: no cover + raise NoTokenError("Failed to obtain token") return [thetoken, expires_in, refresh_token] diff --git a/rowers/integrations/strava.py b/rowers/integrations/strava.py index f4e08439..82cb0561 100644 --- a/rowers/integrations/strava.py +++ b/rowers/integrations/strava.py @@ -313,8 +313,8 @@ class StravaIntegration(SyncIntegration): def token_refresh(self, *args, **kwargs): return super(StravaIntegration, self).token_refresh(*args, **kwargs) - def set_strava_athlete_id(): - r = self.rower() + def set_strava_athlete_id(self, *args, **kwargs): + r = self.rower if (r.stravatoken == '') or (r.stravatoken is None): # pragma: no cover s = "Token doesn't exist. Need to authorize" return custom_exception_handler(401, s) diff --git a/rowers/tests/mocks.py b/rowers/tests/mocks.py index e65d770a..64f9d64e 100644 --- a/rowers/tests/mocks.py +++ b/rowers/tests/mocks.py @@ -1366,7 +1366,7 @@ def mocked_requests(*args, **kwargs): - + if stravatester.match(args[0]): if stravaworkoutlisttester.match(args[0]): return MockResponse(stravaworkoutlist,200) diff --git a/rowers/tests/test_imports.py b/rowers/tests/test_imports.py index 52f000e3..1d5a383a 100644 --- a/rowers/tests/test_imports.py +++ b/rowers/tests/test_imports.py @@ -1165,7 +1165,8 @@ class StravaObjects(DjangoTestCase): self.assertEqual(response.status_code, 200) @patch('rowers.integrations.integrations.requests.post', side_effect=mocked_requests) - def test_strava_callback(self, mock_post): + @patch('rowers.integrations.strava.requests.get', side_effect=mocked_requests) + def test_strava_callback(self, mock_post, mock_get): response = self.c.get('/stravacall_back?code=absdef23&scope=read',follow=True) self.assertEqual(response.status_code, 200)