Googleapiclient test fix (#1372)

* Fix tests with apiclient >= 2.1

* disable MacOS 11 job
This commit is contained in:
Jay Lee
2021-04-26 07:35:07 -04:00
committed by GitHub
parent b43ada4f83
commit eece358aec
4 changed files with 17 additions and 14 deletions

View File

@ -56,11 +56,11 @@ jobs:
goal: "build" goal: "build"
gamos: "macos" gamos: "macos"
platform: "x86_64" platform: "x86_64"
- os: macos-11.0 # - os: macos-11.0
jid: 12 #jid: 12
goal: "build" #goal: "build"
gamos: "macos" #gamos: "macos"
platform: "universal2" #platform: "universal2"
- os: windows-2019 - os: windows-2019
jid: 5 jid: 5
goal: "build" goal: "build"

View File

@ -8,6 +8,7 @@ from unittest.mock import patch
from gam import SetGlobalVariables from gam import SetGlobalVariables
import gam.gapi as gapi import gam.gapi as gapi
from gam.gapi import errors from gam.gapi import errors
import httplib2
def create_http_error(status, reason, message): def create_http_error(status, reason, message):
@ -21,10 +22,10 @@ def create_http_error(status, reason, message):
Returns: Returns:
googleapiclient.errors.HttpError googleapiclient.errors.HttpError
""" """
response = { response = httplib2.Response({
'status': status, 'status': status,
'content-type': 'application/json', 'content-type': 'application/json',
} })
content = { content = {
'error': { 'error': {
'code': status, 'code': status,

View File

@ -7,6 +7,7 @@ from unittest.mock import patch
import googleapiclient.errors import googleapiclient.errors
from gam.gapi import errors from gam.gapi import errors
import httplib2
def create_simple_http_error(status, reason, message): def create_simple_http_error(status, reason, message):
@ -15,10 +16,10 @@ def create_simple_http_error(status, reason, message):
def create_http_error(status, content): def create_http_error(status, content):
response = { response = httplib2.Response({
'status': status, 'status': status,
'content-type': 'application/json', 'content-type': 'application/json',
} })
content_as_bytes = json.dumps(content).encode('UTF-8') content_as_bytes = json.dumps(content).encode('UTF-8')
return googleapiclient.errors.HttpError(response, content_as_bytes) return googleapiclient.errors.HttpError(response, content_as_bytes)
@ -73,6 +74,7 @@ class ErrorsTest(unittest.TestCase):
def test_get_gapi_error_extracts_user_not_found(self): def test_get_gapi_error_extracts_user_not_found(self):
err = create_simple_http_error(404, 'notFound', err = create_simple_http_error(404, 'notFound',
'Resource Not Found: userKey.') 'Resource Not Found: userKey.')
print(err)
http_status, reason, message = errors.get_gapi_error_detail(err) http_status, reason, message = errors.get_gapi_error_detail(err)
self.assertEqual(http_status, 404) self.assertEqual(http_status, 404)
self.assertEqual(reason, errors.ErrorReason.USER_NOT_FOUND.value) self.assertEqual(reason, errors.ErrorReason.USER_NOT_FOUND.value)
@ -158,7 +160,7 @@ class ErrorsTest(unittest.TestCase):
def test_get_gapi_error_extracts_single_error_with_message(self): def test_get_gapi_error_extracts_single_error_with_message(self):
status_code = 999 status_code = 999
response = {'status': status_code} response = httplib2.Response({'status': status_code})
# This error does not have an "errors" key describing each error. # This error does not have an "errors" key describing each error.
content = {'error': {'code': status_code, 'message': 'unknown error'}} content = {'error': {'code': status_code, 'message': 'unknown error'}}
content_as_bytes = json.dumps(content).encode('UTF-8') content_as_bytes = json.dumps(content).encode('UTF-8')
@ -172,7 +174,7 @@ class ErrorsTest(unittest.TestCase):
def test_get_gapi_error_exits_code_4_on_malformed_error_with_unknown_description( def test_get_gapi_error_exits_code_4_on_malformed_error_with_unknown_description(
self): self):
status_code = 999 status_code = 999
response = {'status': status_code} response = httplib2.Response({'status': status_code})
# This error only has an error_description_field and an unknown description. # This error only has an error_description_field and an unknown description.
content = {'error_description': 'something errored'} content = {'error_description': 'something errored'}
content_as_bytes = json.dumps(content).encode('UTF-8') content_as_bytes = json.dumps(content).encode('UTF-8')
@ -184,7 +186,7 @@ class ErrorsTest(unittest.TestCase):
def test_get_gapi_error_exits_on_invalid_error_description(self): def test_get_gapi_error_exits_on_invalid_error_description(self):
status_code = 400 status_code = 400
response = {'status': status_code} response = httplib2.Response({'status': status_code})
content = {'error_description': 'Invalid Value'} content = {'error_description': 'Invalid Value'}
content_as_bytes = json.dumps(content).encode('UTF-8') content_as_bytes = json.dumps(content).encode('UTF-8')
err = googleapiclient.errors.HttpError(response, content_as_bytes) err = googleapiclient.errors.HttpError(response, content_as_bytes)
@ -196,7 +198,7 @@ class ErrorsTest(unittest.TestCase):
def test_get_gapi_error_exits_code_4_on_unexpected_error_contents(self): def test_get_gapi_error_exits_code_4_on_unexpected_error_contents(self):
status_code = 900 status_code = 900
response = {'status': status_code} response = httplib2.Response({'status': status_code})
content = {'notErrorContentThatIsExpected': 'foo'} content = {'notErrorContentThatIsExpected': 'foo'}
content_as_bytes = json.dumps(content).encode('UTF-8') content_as_bytes = json.dumps(content).encode('UTF-8')
err = googleapiclient.errors.HttpError(response, content_as_bytes) err = googleapiclient.errors.HttpError(response, content_as_bytes)

View File

@ -1,7 +1,7 @@
cryptography cryptography
distro; sys_platform == 'linux' distro; sys_platform == 'linux'
filelock filelock
google-api-python-client==2.0.2 google-api-python-client>=2.1
google-auth-httplib2 google-auth-httplib2
google-auth-oauthlib>=0.4.1 google-auth-oauthlib>=0.4.1
google-auth>=1.11.2 google-auth>=1.11.2