-
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 #144 from tseaver/coverage-storage
Coverage for gcloud.storage
- Loading branch information
Showing
13 changed files
with
2,890 additions
and
22 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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import unittest2 | ||
|
||
|
||
class Test_get_connection(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kw): | ||
from gcloud.storage import get_connection | ||
return get_connection(*args, **kw) | ||
|
||
def test_it(self): | ||
from tempfile import NamedTemporaryFile | ||
from gcloud import credentials | ||
from gcloud.storage import SCOPE | ||
from gcloud.storage.connection import Connection | ||
from gcloud.test_credentials import _Client | ||
from gcloud.test_credentials import _Monkey | ||
PROJECT = 'project' | ||
CLIENT_EMAIL = '[email protected]' | ||
PRIVATE_KEY = 'SEEkR1t' | ||
client = _Client() | ||
with _Monkey(credentials, client=client): | ||
with NamedTemporaryFile() as f: | ||
f.write(PRIVATE_KEY) | ||
f.flush() | ||
found = self._callFUT(PROJECT, CLIENT_EMAIL, f.name) | ||
self.assertTrue(isinstance(found, Connection)) | ||
self.assertEqual(found.project, PROJECT) | ||
self.assertTrue(found._credentials is client._signed) | ||
self.assertEqual(client._called_with, | ||
{'service_account_name': CLIENT_EMAIL, | ||
'private_key': PRIVATE_KEY, | ||
'scope': SCOPE, | ||
}) | ||
|
||
|
||
class Test_get_bucket(unittest2.TestCase): | ||
|
||
def _callFUT(self, *args, **kw): | ||
from gcloud.storage import get_bucket | ||
return get_bucket(*args, **kw) | ||
|
||
def test_it(self): | ||
from tempfile import NamedTemporaryFile | ||
from gcloud import storage | ||
from gcloud.test_credentials import _Monkey | ||
bucket = object() | ||
class _Connection(object): | ||
def get_bucket(self, bucket_name): | ||
self._called_With = bucket_name | ||
return bucket | ||
connection = _Connection() | ||
_called_With = [] | ||
def get_connection(*args, **kw): | ||
_called_With.append((args, kw)) | ||
return connection | ||
BUCKET = 'bucket' | ||
PROJECT = 'project' | ||
CLIENT_EMAIL = '[email protected]' | ||
PRIVATE_KEY = 'SEEkR1t' | ||
with _Monkey(storage, get_connection=get_connection): | ||
with NamedTemporaryFile() as f: | ||
f.write(PRIVATE_KEY) | ||
f.flush() | ||
found = self._callFUT(BUCKET, PROJECT, CLIENT_EMAIL, f.name) | ||
self.assertTrue(found is bucket) | ||
self.assertEqual(_called_With, | ||
[((PROJECT, CLIENT_EMAIL, f.name), {})]) | ||
self.assertEqual(connection._called_With, BUCKET) | ||
|
Oops, something went wrong.