-
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 #1222 from dhermes/drop-namedtemp
Using custom named temporary file.
- Loading branch information
Showing
5 changed files
with
126 additions
and
60 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
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 |
---|---|---|
|
@@ -88,17 +88,19 @@ def _callFUT(self, client_email, private_key_path, scope=None): | |
scope=scope) | ||
|
||
def test_it(self): | ||
from tempfile import NamedTemporaryFile | ||
from gcloud import credentials as MUT | ||
from gcloud._testing import _Monkey | ||
from gcloud._testing import _NamedTemporaryFile | ||
|
||
CLIENT_EMAIL = '[email protected]' | ||
PRIVATE_KEY = b'SEEkR1t' | ||
client = _Client() | ||
with _Monkey(MUT, client=client): | ||
with NamedTemporaryFile() as file_obj: | ||
file_obj.write(PRIVATE_KEY) | ||
file_obj.flush() | ||
found = self._callFUT(CLIENT_EMAIL, file_obj.name) | ||
with _NamedTemporaryFile() as temp: | ||
with open(temp.name, 'wb') as file_obj: | ||
file_obj.write(PRIVATE_KEY) | ||
found = self._callFUT(CLIENT_EMAIL, temp.name) | ||
|
||
self.assertTrue(found is client._signed) | ||
expected_called_with = { | ||
'service_account_name': CLIENT_EMAIL, | ||
|
@@ -108,18 +110,20 @@ def test_it(self): | |
self.assertEqual(client._called_with, expected_called_with) | ||
|
||
def test_it_with_scope(self): | ||
from tempfile import NamedTemporaryFile | ||
from gcloud import credentials as MUT | ||
from gcloud._testing import _Monkey | ||
from gcloud._testing import _NamedTemporaryFile | ||
|
||
CLIENT_EMAIL = '[email protected]' | ||
PRIVATE_KEY = b'SEEkR1t' | ||
SCOPE = 'SCOPE' | ||
client = _Client() | ||
with _Monkey(MUT, client=client): | ||
with NamedTemporaryFile() as file_obj: | ||
file_obj.write(PRIVATE_KEY) | ||
file_obj.flush() | ||
found = self._callFUT(CLIENT_EMAIL, file_obj.name, SCOPE) | ||
with _NamedTemporaryFile() as temp: | ||
with open(temp.name, 'wb') as file_obj: | ||
file_obj.write(PRIVATE_KEY) | ||
found = self._callFUT(CLIENT_EMAIL, temp.name, SCOPE) | ||
|
||
self.assertTrue(found is client._signed) | ||
expected_called_with = { | ||
'service_account_name': CLIENT_EMAIL, | ||
|