Exemple #1
0
    def test_refresh(self):
        args = list(GCE_PARAMS) + [GoogleAuthType.GCE]
        cred = GoogleOAuth2Credential(*args)
        cred._refresh_token = mock.Mock()

        # Test getting an unexpired access token.
        tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
        cred.token = {'access_token': 'Access Token!',
                      'expire_time': _utc_timestamp(tomorrow)}
        cred.access_token
        self.assertFalse(cred._refresh_token.called)

        # Test getting an expired access token.
        yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
        cred.token = {'access_token': 'Access Token!',
                      'expire_time': _utc_timestamp(yesterday)}
        cred.access_token
        self.assertTrue(cred._refresh_token.called)
    def test_refresh(self):
        args = list(GCE_PARAMS) + [GoogleAuthType.GCE]
        cred = GoogleOAuth2Credential(*args)
        cred._refresh_token = mock.Mock()

        # Test getting an unexpired access token.
        tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
        cred.token = {'access_token': 'Access Token!',
                      'expire_time': _utc_timestamp(tomorrow)}
        cred.access_token
        self.assertFalse(cred._refresh_token.called)

        # Test getting an expired access token.
        yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
        cred.token = {'access_token': 'Access Token!',
                      'expire_time': _utc_timestamp(yesterday)}
        cred.access_token
        self.assertTrue(cred._refresh_token.called)
 def test_token_request(self):
     request_body = {'code': 'asdf', 'client_id': self.conn.user_id,
                     'client_secret': self.conn.key,
                     'redirect_uri': self.conn.redirect_uri,
                     'grant_type': 'authorization_code'}
     new_token = self.conn._token_request(request_body)
     self.assertEqual(new_token['access_token'],
                      STUB_IA_TOKEN['access_token'])
     exp = STUB_UTCNOW + datetime.timedelta(
         seconds=STUB_IA_TOKEN['expires_in'])
     self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
Exemple #4
0
 def test_token_request(self):
     request_body = {'code': 'asdf', 'client_id': self.conn.user_id,
                     'client_secret': self.conn.key,
                     'redirect_uri': self.conn.redirect_uri,
                     'grant_type': 'authorization_code'}
     new_token = self.conn._token_request(request_body)
     self.assertEqual(new_token['access_token'],
                      STUB_IA_TOKEN['access_token'])
     exp = STUB_UTCNOW + datetime.timedelta(
         seconds=STUB_IA_TOKEN['expires_in'])
     self.assertEqual(new_token['expire_time'], _utc_timestamp(exp))
Exemple #5
0
 def test_token_request(self):
     request_body = {
         "code": "asdf",
         "client_id": self.conn.user_id,
         "client_secret": self.conn.key,
         "redirect_uri": self.conn.redirect_uri,
         "grant_type": "authorization_code",
     }
     new_token = self.conn._token_request(request_body)
     self.assertEqual(new_token["access_token"],
                      STUB_IA_TOKEN["access_token"])
     exp = STUB_UTCNOW + datetime.timedelta(
         seconds=STUB_IA_TOKEN["expires_in"])
     self.assertEqual(new_token["expire_time"], _utc_timestamp(exp))
    'access_token': 'installedapp',
    'token_type': 'Bearer',
    'expires_in': 3600,
    'refresh_token': 'refreshrefresh'
}

STUB_REFRESH_TOKEN = {
    'access_token': 'refreshrefresh',
    'token_type': 'Bearer',
    'expires_in': 3600
}

STUB_TOKEN_FROM_FILE = {
    'access_token': 'token_from_file',
    'token_type': 'Bearer',
    'expire_time': _utc_timestamp(STUB_UTCNOW +
                                  datetime.timedelta(seconds=3600)),
    'expires_in': 3600
}


class MockJsonResponse(object):
    def __init__(self, body):
        self.object = body


class GoogleTestCase(LibcloudTestCase):
    """
    Assists in making Google tests hermetic and deterministic.

    Add anything that needs to be mocked here. Create a patcher with the
    suffix '_patcher'.
Exemple #7
0
    'access_token': 'installedapp',
    'token_type': 'Bearer',
    'expires_in': 3600,
    'refresh_token': 'refreshrefresh'
}

STUB_REFRESH_TOKEN = {
    'access_token': 'refreshrefresh',
    'token_type': 'Bearer',
    'expires_in': 3600
}

STUB_TOKEN_FROM_FILE = {
    'access_token': 'token_from_file',
    'token_type': 'Bearer',
    'expire_time': _utc_timestamp(STUB_UTCNOW +
                                  datetime.timedelta(seconds=3600)),
    'expires_in': 3600
}


class MockJsonResponse(object):
    def __init__(self, body):
        self.object = body


class GoogleTestCase(LibcloudTestCase):
    """
    Assists in making Google tests hermetic and deterministic.

    Add anything that needs to be mocked here. Create a patcher with the
    suffix '_patcher'.