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 json
|
||||||
|
|
||||||
import httplib2
|
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
import unittest2
|
import unittest2
|
||||||
|
|
||||||
from oauth2client import GOOGLE_TOKEN_INFO_URI
|
import oauth2client
|
||||||
from oauth2client.client import GoogleCredentials
|
from oauth2client import client
|
||||||
from oauth2client.contrib.gce import AppAssertionCredentials
|
from oauth2client import transport
|
||||||
|
from oauth2client.contrib import gce
|
||||||
|
|
||||||
|
|
||||||
class TestComputeEngine(unittest2.TestCase):
|
class TestComputeEngine(unittest2.TestCase):
|
||||||
|
|
||||||
def test_application_default(self):
|
def test_application_default(self):
|
||||||
default_creds = GoogleCredentials.get_application_default()
|
default_creds = client.GoogleCredentials.get_application_default()
|
||||||
self.assertIsInstance(default_creds, AppAssertionCredentials)
|
self.assertIsInstance(default_creds, gce.AppAssertionCredentials)
|
||||||
|
|
||||||
def test_token_info(self):
|
def test_token_info(self):
|
||||||
credentials = AppAssertionCredentials([])
|
credentials = gce.AppAssertionCredentials([])
|
||||||
http = httplib2.Http()
|
http = transport.get_http_object()
|
||||||
|
|
||||||
# First refresh to get the access token.
|
# First refresh to get the access token.
|
||||||
self.assertIsNone(credentials.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.
|
# Then check the access token against the token info API.
|
||||||
query_params = {'access_token': credentials.access_token}
|
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))
|
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)
|
self.assertEqual(response.status, http_client.OK)
|
||||||
|
|
||||||
content = content.decode('utf-8')
|
content = content.decode('utf-8')
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import httplib2
|
|
||||||
from six.moves import http_client
|
from six.moves import http_client
|
||||||
|
|
||||||
import oauth2client
|
import oauth2client
|
||||||
from oauth2client import client
|
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')
|
JSON_KEY_PATH = os.getenv('OAUTH2CLIENT_TEST_JSON_KEY_PATH')
|
||||||
@@ -56,8 +56,8 @@ def _require_environ():
|
|||||||
|
|
||||||
|
|
||||||
def _check_user_info(credentials, expected_email):
|
def _check_user_info(credentials, expected_email):
|
||||||
http = credentials.authorize(httplib2.Http())
|
http = credentials.authorize(transport.get_http_object())
|
||||||
response, content = http.request(USER_INFO)
|
response, content = transport.request(http, USER_INFO)
|
||||||
if response.status != http_client.OK:
|
if response.status != http_client.OK:
|
||||||
raise ValueError('Expected 200 OK response.')
|
raise ValueError('Expected 200 OK response.')
|
||||||
|
|
||||||
@@ -68,14 +68,14 @@ def _check_user_info(credentials, expected_email):
|
|||||||
|
|
||||||
|
|
||||||
def run_json():
|
def run_json():
|
||||||
credentials = ServiceAccountCredentials.from_json_keyfile_name(
|
factory = service_account.ServiceAccountCredentials.from_json_keyfile_name
|
||||||
JSON_KEY_PATH, scopes=SCOPE)
|
credentials = factory(JSON_KEY_PATH, scopes=SCOPE)
|
||||||
service_account_email = credentials._service_account_email
|
service_account_email = credentials._service_account_email
|
||||||
_check_user_info(credentials, service_account_email)
|
_check_user_info(credentials, service_account_email)
|
||||||
|
|
||||||
|
|
||||||
def run_p12():
|
def run_p12():
|
||||||
credentials = ServiceAccountCredentials.from_p12_keyfile(
|
credentials = service_account.ServiceAccountCredentials.from_p12_keyfile(
|
||||||
P12_KEY_EMAIL, P12_KEY_PATH, scopes=SCOPE)
|
P12_KEY_EMAIL, P12_KEY_PATH, scopes=SCOPE)
|
||||||
_check_user_info(credentials, P12_KEY_EMAIL)
|
_check_user_info(credentials, P12_KEY_EMAIL)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user