Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gcloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""gcloud client base class for interacting with API."""

import six

from gcloud._helpers import _get_production_project
from gcloud.connection import Connection
Expand Down Expand Up @@ -147,6 +148,8 @@ def __init__(self, project=None, credentials=None, http=None):
if project is None:
raise ValueError('Project was not passed and could not be '
'determined from the environment.')
if not isinstance(project, six.string_types):
raise ValueError('Project must be a string.')
self.project = project

super(JSONClient, self).__init__(credentials=credentials, http=http)
25 changes: 13 additions & 12 deletions gcloud/storage/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def _makeOne(self, *args, **kw):
def test_ctor_connection_type(self):
from gcloud.storage.connection import Connection

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()

client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
self.assertEqual(client.project, PROJECT)
self.assertTrue(isinstance(client.connection, Connection))
self.assertTrue(client.connection.credentials is CREDENTIALS)
self.assertTrue(client.current_batch is None)
Expand All @@ -39,7 +40,7 @@ def test_ctor_connection_type(self):
def test__push_batch_and__pop_batch(self):
from gcloud.storage.batch import Batch

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()

client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
Expand All @@ -58,29 +59,29 @@ def test__push_batch_and__pop_batch(self):
self.assertEqual(list(client._batch_stack), [])

def test_connection_setter(self):
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
client._connection = None # Unset the value from the constructor
client.connection = connection = object()
self.assertTrue(client._connection is connection)

def test_connection_setter_when_set(self):
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
self.assertRaises(ValueError, setattr, client, 'connection', None)

def test_connection_getter_no_batch(self):
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
self.assertTrue(client.connection is client._connection)
self.assertTrue(client.current_batch is None)

def test_connection_getter_with_batch(self):
from gcloud.storage.batch import Batch
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
batch = Batch(client)
Expand All @@ -92,7 +93,7 @@ def test_connection_getter_with_batch(self):
def test_bucket(self):
from gcloud.storage.bucket import Bucket

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
BUCKET_NAME = 'BUCKET_NAME'

Expand All @@ -105,7 +106,7 @@ def test_bucket(self):
def test_batch(self):
from gcloud.storage.batch import Batch

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()

client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
Expand All @@ -116,7 +117,7 @@ def test_batch(self):
def test_get_bucket_miss(self):
from gcloud.exceptions import NotFound

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)

Expand All @@ -139,7 +140,7 @@ def test_get_bucket_miss(self):
def test_get_bucket_hit(self):
from gcloud.storage.bucket import Bucket

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)

Expand All @@ -163,7 +164,7 @@ def test_get_bucket_hit(self):
self.assertEqual(http._called_with['uri'], URI)

def test_lookup_bucket_miss(self):
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)

Expand All @@ -187,7 +188,7 @@ def test_lookup_bucket_miss(self):
def test_lookup_bucket_hit(self):
from gcloud.storage.bucket import Bucket

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = _Credentials()
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)

Expand Down
10 changes: 8 additions & 2 deletions gcloud/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_ctor_defaults(self):
from gcloud._testing import _Monkey
from gcloud import client

PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = object()
FUNC_CALLS = []

Expand Down Expand Up @@ -171,8 +171,14 @@ def mock_get_proj():

self.assertEqual(FUNC_CALLS, ['_get_production_project'])

def test_ctor_w_invalid_project(self):
CREDENTIALS = object()
HTTP = object()
with self.assertRaises(ValueError):
self._makeOne(project=object(), credentials=CREDENTIALS, http=HTTP)

def test_ctor_explicit(self):
PROJECT = object()
PROJECT = 'PROJECT'
CREDENTIALS = object()
HTTP = object()

Expand Down