-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1513 from dhermes/remove-svc-acct-wrappers
Removing get_for_service_account_* helpers.
- Loading branch information
Showing
4 changed files
with
39 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,19 +76,14 @@ def test_from_service_account_json(self): | |
from gcloud import client | ||
|
||
KLASS = self._getTargetClass() | ||
CREDENTIALS = object() | ||
_CALLED = [] | ||
|
||
def mock_creds(arg1): | ||
_CALLED.append((arg1,)) | ||
return CREDENTIALS | ||
|
||
BOGUS_ARG = object() | ||
with _Monkey(client, get_for_service_account_json=mock_creds): | ||
client_obj = KLASS.from_service_account_json(BOGUS_ARG) | ||
MOCK_FILENAME = 'foo.path' | ||
mock_creds = _MockServiceAccountCredentials() | ||
with _Monkey(client, ServiceAccountCredentials=mock_creds): | ||
client_obj = KLASS.from_service_account_json(MOCK_FILENAME) | ||
|
||
self.assertTrue(client_obj.connection.credentials is CREDENTIALS) | ||
self.assertEqual(_CALLED, [(BOGUS_ARG,)]) | ||
self.assertTrue(client_obj.connection.credentials is | ||
mock_creds._result) | ||
self.assertEqual(mock_creds.json_called, [MOCK_FILENAME]) | ||
|
||
def test_from_service_account_json_fail(self): | ||
KLASS = self._getTargetClass() | ||
|
@@ -101,20 +96,17 @@ def test_from_service_account_p12(self): | |
from gcloud import client | ||
|
||
KLASS = self._getTargetClass() | ||
CREDENTIALS = object() | ||
_CALLED = [] | ||
|
||
def mock_creds(arg1, arg2): | ||
_CALLED.append((arg1, arg2)) | ||
return CREDENTIALS | ||
|
||
BOGUS_ARG1 = object() | ||
BOGUS_ARG2 = object() | ||
with _Monkey(client, get_for_service_account_p12=mock_creds): | ||
client_obj = KLASS.from_service_account_p12(BOGUS_ARG1, BOGUS_ARG2) | ||
|
||
self.assertTrue(client_obj.connection.credentials is CREDENTIALS) | ||
self.assertEqual(_CALLED, [(BOGUS_ARG1, BOGUS_ARG2)]) | ||
CLIENT_EMAIL = '[email protected]' | ||
MOCK_FILENAME = 'foo.path' | ||
mock_creds = _MockServiceAccountCredentials() | ||
with _Monkey(client, ServiceAccountCredentials=mock_creds): | ||
client_obj = KLASS.from_service_account_p12(CLIENT_EMAIL, | ||
MOCK_FILENAME) | ||
|
||
self.assertTrue(client_obj.connection.credentials is | ||
mock_creds._result) | ||
self.assertEqual(mock_creds.p12_called, | ||
[(CLIENT_EMAIL, MOCK_FILENAME)]) | ||
|
||
def test_from_service_account_p12_fail(self): | ||
KLASS = self._getTargetClass() | ||
|
@@ -220,3 +212,19 @@ class _MockConnection(object): | |
def __init__(self, credentials=None, http=None): | ||
self.credentials = credentials | ||
self.http = http | ||
|
||
|
||
class _MockServiceAccountCredentials(object): | ||
|
||
def __init__(self): | ||
self.p12_called = [] | ||
self.json_called = [] | ||
self._result = object() | ||
|
||
def from_p12_keyfile(self, email, path): | ||
self.p12_called.append((email, path)) | ||
return self._result | ||
|
||
def from_json_keyfile_name(self, path): | ||
self.json_called.append(path) | ||
return self._result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,75 +80,6 @@ def test_it(self): | |
self.assertTrue(client._get_app_default_called) | ||
|
||
|
||
class Test_get_for_service_account_p12(unittest2.TestCase): | ||
|
||
def _callFUT(self, client_email, private_key_path, scope=None): | ||
from gcloud.credentials import get_for_service_account_p12 | ||
return get_for_service_account_p12(client_email, private_key_path, | ||
scope=scope) | ||
|
||
def test_it(self): | ||
from gcloud import credentials as MUT | ||
from gcloud._testing import _Monkey | ||
|
||
CLIENT_EMAIL = '[email protected]' | ||
MOCK_FILENAME = 'foo.path' | ||
MOCK_CRED_CLASS = _MockServiceAccountCredentials() | ||
with _Monkey(MUT, ServiceAccountCredentials=MOCK_CRED_CLASS): | ||
found = self._callFUT(CLIENT_EMAIL, MOCK_FILENAME) | ||
|
||
self.assertTrue(found is MOCK_CRED_CLASS._result) | ||
self.assertEqual(MOCK_CRED_CLASS.p12_called, | ||
[(CLIENT_EMAIL, MOCK_FILENAME, None)]) | ||
|
||
def test_it_with_scope(self): | ||
from gcloud import credentials as MUT | ||
from gcloud._testing import _Monkey | ||
|
||
CLIENT_EMAIL = '[email protected]' | ||
SCOPE = 'SCOPE' | ||
MOCK_FILENAME = 'foo.path' | ||
MOCK_CRED_CLASS = _MockServiceAccountCredentials() | ||
with _Monkey(MUT, ServiceAccountCredentials=MOCK_CRED_CLASS): | ||
found = self._callFUT(CLIENT_EMAIL, MOCK_FILENAME, SCOPE) | ||
|
||
self.assertTrue(found is MOCK_CRED_CLASS._result) | ||
self.assertEqual(MOCK_CRED_CLASS.p12_called, | ||
[(CLIENT_EMAIL, MOCK_FILENAME, SCOPE)]) | ||
|
||
|
||
class Test_get_for_service_account_json(unittest2.TestCase): | ||
|
||
def _callFUT(self, json_credentials_path, scope=None): | ||
from gcloud.credentials import get_for_service_account_json | ||
return get_for_service_account_json(json_credentials_path, scope=scope) | ||
|
||
def test_it(self): | ||
from gcloud._testing import _Monkey | ||
from gcloud import credentials as MUT | ||
|
||
FILENAME = object() | ||
MOCK_CRED_CLASS = _MockServiceAccountCredentials() | ||
with _Monkey(MUT, ServiceAccountCredentials=MOCK_CRED_CLASS): | ||
result = self._callFUT(FILENAME) | ||
|
||
self.assertEqual(result, MOCK_CRED_CLASS._result) | ||
self.assertEqual(MOCK_CRED_CLASS.json_called, [(FILENAME, None)]) | ||
|
||
def test_it_with_scope(self): | ||
from gcloud._testing import _Monkey | ||
from gcloud import credentials as MUT | ||
|
||
FILENAME = object() | ||
SCOPE = object() | ||
MOCK_CRED_CLASS = _MockServiceAccountCredentials() | ||
with _Monkey(MUT, ServiceAccountCredentials=MOCK_CRED_CLASS): | ||
result = self._callFUT(FILENAME, scope=SCOPE) | ||
|
||
self.assertEqual(result, MOCK_CRED_CLASS._result) | ||
self.assertEqual(MOCK_CRED_CLASS.json_called, [(FILENAME, SCOPE)]) | ||
|
||
|
||
class Test_generate_signed_url(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kwargs): | ||
|
@@ -665,19 +596,3 @@ def non_transactional(*args, **kwargs): | |
def do_nothing_wrapper(func): | ||
return func | ||
return do_nothing_wrapper | ||
|
||
|
||
class _MockServiceAccountCredentials(object): | ||
|
||
def __init__(self): | ||
self.p12_called = [] | ||
self.json_called = [] | ||
self._result = _Credentials() | ||
|
||
def from_p12_keyfile(self, email, path, scopes=None): | ||
self.p12_called.append((email, path, scopes)) | ||
return self._result | ||
|
||
def from_json_keyfile_name(self, path, scopes=None): | ||
self.json_called.append((path, scopes)) | ||
return self._result |