Merge pull request #606 from dhermes/fix-up-system-tests-httplib2
Use transport helpers in system tests
This commit is contained in:
@@ -14,25 +14,25 @@
|
||||
|
||||
import json
|
||||
|
||||
import httplib2
|
||||
from six.moves import http_client
|
||||
from six.moves import urllib
|
||||
import unittest2
|
||||
|
||||
from oauth2client import GOOGLE_TOKEN_INFO_URI
|
||||
from oauth2client.client import GoogleCredentials
|
||||
from oauth2client.contrib.gce import AppAssertionCredentials
|
||||
import oauth2client
|
||||
from oauth2client import client
|
||||
from oauth2client import transport
|
||||
from oauth2client.contrib import gce
|
||||
|
||||
|
||||
class TestComputeEngine(unittest2.TestCase):
|
||||
|
||||
def test_application_default(self):
|
||||
default_creds = GoogleCredentials.get_application_default()
|
||||
self.assertIsInstance(default_creds, AppAssertionCredentials)
|
||||
default_creds = client.GoogleCredentials.get_application_default()
|
||||
self.assertIsInstance(default_creds, gce.AppAssertionCredentials)
|
||||
|
||||
def test_token_info(self):
|
||||
credentials = AppAssertionCredentials([])
|
||||
http = httplib2.Http()
|
||||
credentials = gce.AppAssertionCredentials([])
|
||||
http = transport.get_http_object()
|
||||
|
||||
# First refresh to get the access token.
|
||||
self.assertIsNone(credentials.access_token)
|
||||
@@ -41,9 +41,9 @@ class TestComputeEngine(unittest2.TestCase):
|
||||
|
||||
# Then check the access token against the token info API.
|
||||
query_params = {'access_token': credentials.access_token}
|
||||
token_uri = (GOOGLE_TOKEN_INFO_URI + '?' +
|
||||
token_uri = (oauth2client.GOOGLE_TOKEN_INFO_URI + '?' +
|
||||
urllib.parse.urlencode(query_params))
|
||||
response, content = http.request(token_uri)
|
||||
response, content = transport.request(http, token_uri)
|
||||
self.assertEqual(response.status, http_client.OK)
|
||||
|
||||
content = content.decode('utf-8')
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import httplib2
|
||||
from six.moves import http_client
|
||||
|
||||
import oauth2client
|
||||
from oauth2client import client
|
||||
from oauth2client.service_account import ServiceAccountCredentials
|
||||
from oauth2client import service_account
|
||||
from oauth2client import transport
|
||||
|
||||
|
||||
JSON_KEY_PATH = os.getenv('OAUTH2CLIENT_TEST_JSON_KEY_PATH')
|
||||
@@ -56,8 +56,8 @@ def _require_environ():
|
||||
|
||||
|
||||
def _check_user_info(credentials, expected_email):
|
||||
http = credentials.authorize(httplib2.Http())
|
||||
response, content = http.request(USER_INFO)
|
||||
http = credentials.authorize(transport.get_http_object())
|
||||
response, content = transport.request(http, USER_INFO)
|
||||
if response.status != http_client.OK:
|
||||
raise ValueError('Expected 200 OK response.')
|
||||
|
||||
@@ -68,14 +68,14 @@ def _check_user_info(credentials, expected_email):
|
||||
|
||||
|
||||
def run_json():
|
||||
credentials = ServiceAccountCredentials.from_json_keyfile_name(
|
||||
JSON_KEY_PATH, scopes=SCOPE)
|
||||
factory = service_account.ServiceAccountCredentials.from_json_keyfile_name
|
||||
credentials = factory(JSON_KEY_PATH, scopes=SCOPE)
|
||||
service_account_email = credentials._service_account_email
|
||||
_check_user_info(credentials, service_account_email)
|
||||
|
||||
|
||||
def run_p12():
|
||||
credentials = ServiceAccountCredentials.from_p12_keyfile(
|
||||
credentials = service_account.ServiceAccountCredentials.from_p12_keyfile(
|
||||
P12_KEY_EMAIL, P12_KEY_PATH, scopes=SCOPE)
|
||||
_check_user_info(credentials, P12_KEY_EMAIL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user