示例#1
0
 def test_fetch_access_token_with_token_not_expired(self):
     external_account = ExternalAccountFactory()
     self.user.external_accounts.append(external_account)
     external_account.expires_at = datetime.utcnow() + relativedelta.relativedelta(minutes=6)
     external_account.oauth_key = "fake-token"
     external_account.save()
     self.node_settings.set_auth(external_account, self.user)
     assert_equal(self.node_settings.fetch_access_token(), "fake-token")
示例#2
0
    def test_fetch_access_token_with_token_expired(self, mock_refresh):
        external_account = ExternalAccountFactory()
        self.user.external_accounts.append(external_account)
        external_account.expires_at = datetime.utcnow() + relativedelta.relativedelta(minutes=4)
        external_account.oauth_key = "fake-token"
        external_account.refresh_token = "refresh-fake-token"
        external_account.save()

        fake_token = {"access_token": "new-access-token", "refresh_token": "new-refresh-token", "expires_at": 1234.5}
        mock_refresh.return_value = fake_token
        self.node_settings.set_auth(external_account, self.user)
        self.node_settings.fetch_access_token()
        mock_refresh.assert_called_once()
        assert_equal(external_account.oauth_key, "new-access-token")
        assert_equal(external_account.refresh_token, "new-refresh-token")
        assert_equal(external_account.expires_at, datetime.utcfromtimestamp(1234.5))